GitHub Actions · Lesson 8 of 10 · 3 min read
A complete pipeline: Java service to EKS via GitOps
name: orders
on:
pull_request: { branches: [main] }
push: { branches: [main] }
permissions: { contents: read }
concurrency:
group: orders-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with: { distribution: temurin, java-version: "21", cache: gradle }
- run: ./gradlew build --no-daemon
- uses: actions/upload-artifact@v4
if: always()
with: { name: reports, path: build/reports }
image:
needs: test
if: github.event_name == 'push'
runs-on: ubuntu-latest
permissions: { contents: read, id-token: write }
outputs: { tag: "${{ steps.meta.outputs.tag }}" }
steps:
- uses: actions/checkout@v4
- id: meta
run: echo "tag=${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::123456789012:role/gha-ecr-push-orders
aws-region: ap-south-1
- uses: aws-actions/amazon-ecr-login@v2
id: ecr
- uses: docker/setup-buildx-action@v3
- uses: docker/build-push-action@v6
with:
push: true
tags: ${{ steps.ecr.outputs.registry }}/orders:${{ steps.meta.outputs.tag }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Scan image
uses: aquasecurity/[email protected] # pin to a SHA in real use
with:
image-ref: ${{ steps.ecr.outputs.registry }}/orders:${{ steps.meta.outputs.tag }}
exit-code: "1"
severity: CRITICAL
promote-staging:
needs: image
runs-on: ubuntu-latest
environment: staging
steps:
- uses: actions/checkout@v4
with:
repository: acme/platform-gitops
token: ${{ secrets.GITOPS_TOKEN }} # or a GitHub App token
- run: |
cd apps/orders/overlays/staging
kustomize edit set image orders=*:${{ needs.image.outputs.tag }}
git config user.name "orders-ci" && git config user.email "[email protected]"
git commit -am "orders: staging -> ${{ needs.image.outputs.tag }}" && git push
Enlarge diagram
Swipe sideways to see all of it, or tap to open it full screen.
Production promotion is a separate job with environment: production (required reviewers) opening a PR against the prod overlay — Flux reconciles after merge. For writing to another repo, a GitHub App installation token (via actions/create-github-app-token) is better than a personal access token: scoped, short-lived, not tied to a person.