Skip to content

Build and Push Frontend Image #110

Build and Push Frontend Image

Build and Push Frontend Image #110

name: Build and Push Frontend Image
on:
push:
branches: [main]
paths:
- "frontend/**"
- ".github/workflows/build-frontend-image.yml"
pull_request:
branches: [main]
paths:
- "frontend/**"
- ".github/workflows/build-frontend-image.yml"
workflow_dispatch:
workflow_run:
workflows: ["Run Project Tests"]
types: [completed]
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}/frontend
jobs:
build-schema:
name: Generate GraphQL Schema
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: "9.0.x"
- name: Restore dependencies
run: dotnet restore PhantomDave.BankTracking.Api/PhantomDave.BankTracking.Api.csproj
- name: Start database
run: docker compose -f compose.dev.yaml up database -d --wait
- name: Start API in background
working-directory: ./PhantomDave.BankTracking.Api
run: |
dotnet run > api.log 2>&1 &
echo $! > api.pid
env:
ASPNETCORE_ENVIRONMENT: Development
- name: Wait for API to be ready
uses: jtalk/url-health-check-action@v4
with:
url: http://localhost:5095/graphql
max-attempts: 15
retry-delay: 2s
- name: Download GraphQL schema
run: curl -f http://localhost:5095/graphql?sdl -o frontend/schema.graphql
- name: Upload schema artifact
uses: actions/upload-artifact@v5
with:
name: graphql-schema
path: frontend/schema.graphql
retention-days: 1
build-and-push:
name: Build and Push Frontend Container
runs-on: ubuntu-latest
needs: build-schema
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Download schema artifact
uses: actions/download-artifact@v6
with:
name: graphql-schema
path: frontend
- name: Log in to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=sha,prefix={{branch}}-,enable=${{ github.event_name != 'pull_request' }}
type=ref,event=branch
type=ref,event=pr
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push frontend image
uses: docker/build-push-action@v6
with:
context: ./frontend
file: ./frontend/Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}