Skip to content

feat: security hardening (#25) #71

feat: security hardening (#25)

feat: security hardening (#25) #71

name: CI/CD — Build and Publish Frontend Image
on:
push:
branches: [main, "feature/*"]
paths:
- 'frontend/**'
- 'shared/**'
- .github/workflows/frontend-docker-publish.yml
pull_request:
branches: [main]
paths:
- 'frontend/**'
- 'shared/**'
- .github/workflows/frontend-docker-publish.yml
workflow_dispatch: {}
permissions:
contents: read
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}/frontend
jobs:
ci:
name: Lint and test
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version: 24
cache: yarn
cache-dependency-path: frontend/yarn.lock
- name: Install and build shared library
working-directory: shared
run: yarn install --frozen-lockfile --non-interactive && yarn build
- name: Install frontend dependencies
working-directory: frontend
run: yarn install --frozen-lockfile --non-interactive
- name: Lint
continue-on-error: true # Existing issues, to be fixed in the future (non-blocking for now)
working-directory: frontend
run: yarn lint
- name: Test
working-directory: frontend
run: yarn vitest --run
build-and-push-frontend:
name: Build and push Frontend Docker image
needs: ci
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels)
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=sha
type=raw,value=dev
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
file: ./frontend/Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
deploy:
name: Deploy to ${{ matrix.environment }}
needs: build-and-push-frontend
if: github.event_name == 'push'
runs-on: ubuntu-latest
strategy:
matrix:
environment: >-
${{
github.ref == 'refs/heads/main'
&& fromJSON('["dev","prd"]')
|| fromJSON('["dev"]')
}}
steps:
- name: Trigger infra deployment
uses: peter-evans/repository-dispatch@v4
with:
token: ${{ secrets.INFRA_DEPLOY_PAT }}
repository: KrakenKey/infra-int
event-type: image-published
client-payload: >-
{"image": "${{ env.IMAGE_NAME }}", "sha": "${{ github.sha }}", "ref": "${{ github.ref_name }}", "environment": "${{ matrix.environment }}"}