Skip to content

Commit 0f2ddbf

Browse files
committed
adds github actions workflow to build frontend multiplatform image and push to ghcr
1 parent 279fb83 commit 0f2ddbf

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
name: Build and Push Frontend Image
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
types: [opened, synchronize, reopened]
9+
workflow_dispatch:
10+
11+
env:
12+
REGISTRY: ghcr.io
13+
14+
jobs:
15+
build_and_push_frontend:
16+
runs-on: ubuntu-22.04
17+
18+
permissions:
19+
contents: read
20+
packages: write
21+
id-token: write # Required for Cosign OIDC signing
22+
23+
steps:
24+
# Checkout the source code
25+
- uses: actions/checkout@v4
26+
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+
- uses: docker/setup-buildx-action@v3
34+
with:
35+
install: true
36+
37+
# Login to GHCR (GitHub Container Registry)
38+
- name: Docker login
39+
uses: docker/login-action@v2
40+
with:
41+
registry: ${{ env.REGISTRY }}
42+
username: ${{ github.actor }}
43+
password: ${{ secrets.GITHUB_TOKEN }}
44+
45+
# Dynamically generate image tag and name based on repo/org/branch
46+
- name: Determine Image Tags
47+
id: tags
48+
run: |
49+
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
58+
uses: docker/build-push-action@v5
59+
with:
60+
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
64+
push: true
65+
provenance: true # Enables provenance metadata
66+
sbom: true # Enables SBOM generation
67+
build-args: |
68+
NEXT_PUBLIC_BACKEND_SERVICE_PROTOCOL=${{ secrets.BACKEND_SERVICE_PROTOCOL }}
69+
NEXT_PUBLIC_BACKEND_SERVICE_HOST=${{ secrets.BACKEND_SERVICE_HOST }}
70+
NEXT_PUBLIC_BACKEND_SERVICE_PORT=${{ secrets.BACKEND_PORT }}
71+
NEXT_PUBLIC_BACKEND_API_VERSION=${{ secrets.BACKEND_API_VERSION }}
72+
FRONTEND_SERVICE_PORT=${{ secrets.FRONTEND_SERVICE_PORT }}
73+
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 }}
88+
89+
# Output usage instructions
90+
- name: Print Pull & Run Instructions
91+
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 }}"

0 commit comments

Comments
 (0)