Test deployment for QA site (#57) #8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Docker | |
on: | |
push: | |
branches: | |
- "master" | |
- "qa" | |
jobs: | |
build: | |
name: "Build (${{ matrix.component }})" | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
strategy: | |
fail-fast: true | |
matrix: | |
component: [backend, 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: Build and push Docker image | |
uses: docker/build-push-action@v5 | |
with: | |
context: ${{ matrix.component }} | |
push: ${{ github.event_name != 'pull_request' && ( github.ref == 'refs/heads/master' || github.ref == 'refs/heads/qa' ) }} | |
platforms: linux/amd64 | |
file: ${{ matrix.component }}/Dockerfile | |
tags: | | |
ghcr.io/csesoc/website-${{ matrix.component }}:${{ github.sha }} | |
ghcr.io/csesoc/website-${{ matrix.component }}:latest | |
labels: ${{ steps.meta.outputs.labels }} | |
deploy: | |
name: Deploy (CD) | |
runs-on: ubuntu-latest | |
needs: [build] | |
concurrency: prod | |
environment: | |
name: prod | |
if: ${{ github.event_name != 'pull_request' && ( github.ref == 'refs/heads/master' || github.ref == 'refs/heads/qa' ) }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
repository: csesoc/deployment | |
token: ${{ secrets.GH_TOKEN }} | |
ref: develop | |
- name: Install yq - portable yaml processor | |
uses: mikefarah/yq@v4.27.2 | |
- name: "Determine deployment type" | |
id: get_manifest | |
env: | |
BRANCH: ${{ github.ref }} | |
run: | | |
if [[ "${{ github.ref }}" == "refs/heads/master" ]]; then | |
echo "TYPE=prod" >> $GITHUB_OUTPUT | |
elif [[ "${{ github.ref }}" == "refs/heads/qa" ]]; then | |
echo "TYPE=qa" >> $GITHUB_OUTPUT | |
else | |
exit 1 | |
fi | |
- name: Update deployment | |
env: | |
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} | |
run: | | |
git config user.name "CSESoc CD" | |
git config user.email "technical@csesoc.org.au" | |
git checkout -b update/website-${{ steps.get_manifest.outputs.TYPE }}/${{ github.sha }} | |
yq -i '.items[0].spec.template.spec.containers[0].image = "ghcr.io/csesoc/website-backend:${{ github.sha }}"' apps/projects/website/${{ steps.get_manifest.outputs.TYPE }}/deploy-backend.yml | |
yq -i '.items[0].spec.template.spec.containers[0].image = "ghcr.io/csesoc/website-frontend:${{ github.sha }}"' apps/projects/website/${{ steps.get_manifest.outputs.TYPE }}/deploy-frontend.yml | |
git add . | |
git commit -m "feat(website/${{ steps.get_manifest.outputs.TYPE }}): update image" | |
git push -u origin update/website-${{ steps.get_manifest.outputs.TYPE }}/${{ github.sha }} | |
gh pr create -B develop --title "feat(website/${{ steps.get_manifest.outputs.TYPE }}): update image" --body "Updates the image for the website-prod deployment to commit csesoc/csesoc-website@${{ github.sha }}." > URL | |
gh pr merge $(cat URL) --squash -d |