|
10 | 10 |
|
11 | 11 | env: |
12 | 12 | REGISTRY: ghcr.io |
| 13 | + ORG_NAME: refactor-group |
| 14 | + REPO_NAME: refactor-platform-fe |
13 | 15 |
|
14 | 16 | jobs: |
15 | | - build_and_push_frontend: |
| 17 | + build_and_push_amd64: |
16 | 18 | runs-on: ubuntu-22.04 |
17 | 19 |
|
18 | 20 | permissions: |
19 | 21 | contents: read |
20 | 22 | packages: write |
21 | | - id-token: write # Required for Cosign OIDC signing |
| 23 | + id-token: write |
22 | 24 |
|
23 | 25 | steps: |
24 | | - # Checkout the source code |
25 | 26 | - uses: actions/checkout@v4 |
26 | 27 |
|
27 | | - # Setup QEMU for emulating multi-arch (e.g., ARM64 on x86) |
28 | | - - uses: docker/setup-qemu-action@v2 |
29 | | - with: |
30 | | - platforms: linux/amd64,linux/arm64 |
31 | | - |
32 | | - # Setup Buildx for advanced Docker builds (multiarch, caching, sbom) |
33 | 28 | - uses: docker/setup-buildx-action@v3 |
34 | 29 | with: |
35 | 30 | install: true |
36 | 31 |
|
37 | | - # Login to GHCR (GitHub Container Registry) |
38 | 32 | - name: Docker login |
39 | 33 | uses: docker/login-action@v2 |
40 | 34 | with: |
41 | 35 | registry: ${{ env.REGISTRY }} |
42 | 36 | username: ${{ github.actor }} |
43 | 37 | password: ${{ secrets.GITHUB_TOKEN }} |
44 | 38 |
|
45 | | - # Dynamically generate image tag and name based on repo/org/branch |
46 | | - - name: Determine Image Tags |
47 | | - id: tags |
| 39 | + - name: Set image tag |
| 40 | + id: vars |
48 | 41 | run: | |
49 | 42 | BRANCH_NAME=${GITHUB_HEAD_REF:-${GITHUB_REF##*/}} |
50 | | - ORG_NAME="refactor-group" |
51 | | - REPO_NAME="refactor-platform-fe" |
52 | | - IMAGE="${{ env.REGISTRY }}/${ORG_NAME}/${REPO_NAME}/${BRANCH_NAME}:latest" |
53 | | - echo "tag=$IMAGE" >> $GITHUB_OUTPUT |
54 | | - echo "image=$IMAGE" >> $GITHUB_OUTPUT |
55 | | -
|
56 | | - # Build, SBOM, and Push the multi-arch Docker image |
57 | | - - name: Build + Push Frontend |
| 43 | + IMAGE_BASE="${{ env.REGISTRY }}/${{ env.ORG_NAME }}/${{ env.REPO_NAME }}/${BRANCH_NAME}" |
| 44 | + echo "tag=${IMAGE_BASE}:amd64" >> $GITHUB_OUTPUT |
| 45 | +
|
| 46 | + - name: Build + Push AMD64 |
| 47 | + id: build |
58 | 48 | uses: docker/build-push-action@v5 |
59 | 49 | with: |
60 | 50 | context: . |
61 | | - file: ./Dockerfile # Dockerfile is at the root of the repo |
62 | | - target: runner # Your Dockerfile defines this stage |
63 | | - platforms: linux/amd64,linux/arm64 |
| 51 | + file: ./Dockerfile |
| 52 | + target: runner |
| 53 | + platforms: linux/amd64 |
64 | 54 | push: true |
65 | | - provenance: true # Enables provenance metadata |
66 | | - sbom: true # Enables SBOM generation |
| 55 | + provenance: true |
| 56 | + sbom: true |
67 | 57 | build-args: | |
68 | 58 | NEXT_PUBLIC_BACKEND_SERVICE_PROTOCOL=${{ secrets.BACKEND_SERVICE_PROTOCOL }} |
69 | 59 | NEXT_PUBLIC_BACKEND_SERVICE_HOST=${{ secrets.BACKEND_SERVICE_HOST }} |
70 | 60 | NEXT_PUBLIC_BACKEND_SERVICE_PORT=${{ secrets.BACKEND_PORT }} |
71 | 61 | NEXT_PUBLIC_BACKEND_API_VERSION=${{ secrets.BACKEND_API_VERSION }} |
72 | 62 | FRONTEND_SERVICE_PORT=${{ secrets.FRONTEND_SERVICE_PORT }} |
73 | 63 | FRONTEND_SERVICE_INTERFACE=${{ secrets.FRONTEND_SERVICE_INTERFACE }} |
74 | | - tags: ${{ steps.tags.outputs.tag }} |
75 | | - cache-from: type=gha # GitHub-hosted build cache |
76 | | - cache-to: type=gha,mode=max |
77 | | - |
78 | | - # Install Cosign CLI for image signing |
79 | | - - name: Install Cosign |
80 | | - uses: sigstore/cosign-installer@v3 |
81 | | - |
82 | | - # Sign image using GitHub OIDC token (no secrets needed) |
83 | | - - name: Sign image with Cosign |
84 | | - env: |
85 | | - COSIGN_EXPERIMENTAL: "true" |
86 | | - run: | |
87 | | - cosign sign --yes ${{ steps.tags.outputs.image }} |
| 64 | + tags: ${{ steps.vars.outputs.tag }} |
| 65 | + cache-from: type=gha,scope=amd64 |
| 66 | + cache-to: type=gha,mode=max,scope=amd64 |
| 67 | + |
| 68 | + build_and_push_arm64: |
| 69 | + runs-on: ubuntu-22.04 |
| 70 | + |
| 71 | + permissions: |
| 72 | + contents: read |
| 73 | + packages: write |
| 74 | + id-token: write |
88 | 75 |
|
89 | | - # Output usage instructions |
90 | | - - name: Print Pull & Run Instructions |
| 76 | + steps: |
| 77 | + - uses: actions/checkout@v4 |
| 78 | + |
| 79 | + - uses: docker/setup-buildx-action@v3 |
| 80 | + with: |
| 81 | + install: true |
| 82 | + |
| 83 | + - name: Docker login |
| 84 | + uses: docker/login-action@v2 |
| 85 | + with: |
| 86 | + registry: ${{ env.REGISTRY }} |
| 87 | + username: ${{ github.actor }} |
| 88 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 89 | + |
| 90 | + - name: Set image tag |
| 91 | + id: vars |
91 | 92 | run: | |
92 | | - echo -e "\033[1;32mFrontend Image Pushed & Signed:\033[0m" |
93 | | - echo " docker pull ${{ steps.tags.outputs.image }}" |
94 | | - echo "" |
95 | | - echo -e "\033[1;36mRun locally or with Compose:\033[0m" |
96 | | - echo " docker run --rm --env-file .env -p 3000:3000 ${{ steps.tags.outputs.image }}" |
97 | | - echo "" |
98 | | - echo -e "\033[1;33mSignature Verification:\033[0m" |
99 | | - echo " cosign verify ${{ steps.tags.outputs.image }}" |
| 93 | + BRANCH_NAME=${GITHUB_HEAD_REF:-${GITHUB_REF##*/}} |
| 94 | + IMAGE_BASE="${{ env.REGISTRY }}/${{ env.ORG_NAME }}/${{ env.REPO_NAME }}/${BRANCH_NAME}" |
| 95 | + echo "tag=${IMAGE_BASE}:arm64" >> $GITHUB_OUTPUT |
| 96 | +
|
| 97 | + - name: Build + Push ARM64 |
| 98 | + id: build |
| 99 | + uses: docker/build-push-action@v5 |
| 100 | + with: |
| 101 | + context: . |
| 102 | + file: ./Dockerfile |
| 103 | + target: runner |
| 104 | + platforms: linux/arm64 |
| 105 | + push: true |
| 106 | + provenance: true |
| 107 | + sbom: true |
| 108 | + build-args: | |
| 109 | + NEXT_PUBLIC_BACKEND_SERVICE_PROTOCOL=${{ secrets.BACKEND_SERVICE_PROTOCOL }} |
| 110 | + NEXT_PUBLIC_BACKEND_SERVICE_HOST=${{ secrets.BACKEND_SERVICE_HOST }} |
| 111 | + NEXT_PUBLIC_BACKEND_SERVICE_PORT=${{ secrets.BACKEND_PORT }} |
| 112 | + NEXT_PUBLIC_BACKEND_API_VERSION=${{ secrets.BACKEND_API_VERSION }} |
| 113 | + FRONTEND_SERVICE_PORT=${{ secrets.FRONTEND_SERVICE_PORT }} |
| 114 | + FRONTEND_SERVICE_INTERFACE=${{ secrets.FRONTEND_SERVICE_INTERFACE }} |
| 115 | + tags: ${{ steps.vars.outputs.tag }} |
| 116 | + cache-from: type=gha,scope=arm64 |
| 117 | + cache-to: type=gha,mode=max,scope=arm64 |
0 commit comments