Skip to content

Final 2024 changes (#585) #423

Final 2024 changes (#585)

Final 2024 changes (#585) #423

Workflow file for this run

name: Docker
on:
push:
branches:
- "master"
- "dev"
env:
BRANCH_NAME: ${{ github.base_ref || github.ref_name }}
jobs:
build:
name: "Build (${{ matrix.name }})"
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
context: [backend, frontend]
include:
- context: backend
name: backend
- context: frontend
name: frontend
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: arm64
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GH_TOKEN }}
- name: Create staging .env file
if: ${{ env.BRANCH_NAME == 'dev' && matrix.context == 'frontend' }}
run: echo "NEXT_PUBLIC_STAGING=true" >> .env
working-directory: frontend
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
platforms: linux/amd64
file: ${{ matrix.context }}.dockerfile
tags: |
ghcr.io/csesoc/freerooms-${{ matrix.name }}:${{ github.sha }}
ghcr.io/csesoc/freerooms-${{ matrix.name }}:latest
labels: ${{ steps.meta.outputs.labels }}
deploy:
name: Deploy (CD)
runs-on: ubuntu-latest
needs: [build]
concurrency: staging
if: ${{ github.event_name != 'pull_request' && (github.ref_name == 'dev' || github.ref_name == 'master') }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
repository: csesoc/deployment
token: ${{ secrets.GH_TOKEN }}
ref: migration
- name: Install yq - portable yaml processor
uses: mikefarah/[email protected]
- name: Update deployment
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
git config user.name "CSESoc CD"
git config user.email "[email protected]"
case $BRANCH_NAME in
dev)
build_type="staging"
;;
master)
build_type="prod"
;;
*)
echo "Invalid branch '$branch'"
exit 1
;;
esac
git checkout -b update/freerooms-$build_type/${{ github.sha }}
yq -i '.items[0].spec.template.spec.containers[0].image = "ghcr.io/csesoc/freerooms-backend:${{ github.sha }}"' projects/freerooms/$build_type/deploy-backend.yml
yq -i '.items[0].spec.template.spec.containers[0].image = "ghcr.io/csesoc/freerooms-frontend:${{ github.sha }}"' projects/freerooms/$build_type/deploy-frontend.yml
git add .
git commit -m "feat(freerooms-$build_type): update images"
git push -u origin update/freerooms-$build_type/${{ github.sha }}
gh pr create -B migration --title "feat(freerooms-$build_type): update image" --body "Updates the image for the freerooms deployment to commit csesoc/freerooms@${{ github.sha }}." > URL
gh pr merge $(cat URL) --squash -d