From 892efc3564e388b3d2149fe06b83b29b41cc59cf Mon Sep 17 00:00:00 2001 From: ChinoGoblino <71302825+ChinoGoblino@users.noreply.github.com> Date: Sun, 22 Sep 2024 17:23:49 +1000 Subject: [PATCH] Container registry github action first draft --- .github/workflows/docker.yml | 73 ++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 .github/workflows/docker.yml diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..1fd427c --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,73 @@ +name: Docker +on: + push: + branches: + - main + +jobs: + build-client: + name: 'Build (Client)' + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + 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: client + push: ${{ github.event_name != 'pull_request' && github.ref == 'refs/heads/main' }} + platforms: linux/amd64 + file: client/Dockerfile + cache-from: type=gha + cache-to: type=gha,mode=max + build-args: | + HASURAGRES_API_KEY=${{ secrets.HASURAGRES_API_KEY }} + HASURAGRES_URL=${{ secrets.HASURAGRES_URL }} + tags: | + ghcr.io/csesoc/spooderman:${{ github.sha }} + ghcr.io/csesoc/spooderman:latest + labels: ${{ steps.meta.outputs.labels }} + deploy: + name: Deploy (CD) + runs-on: ubuntu-latest + needs: [build-client, build] + if: ${{ github.event_name != 'pull_request' && github.ref == 'refs/heads/main' }} + concurrency: production + + 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/yq@v4.44.2 + - 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/spooderman/${{ github.sha }} + yq -i '.items[0].spec.template.spec.containers[0].image = "ghcr.io/csesoc/spooderman:${{ github.sha }}"' projects/spooderman/cronjob.yml + git add . + git commit -m "feat(spooderman): update images" + git push -u origin update/spooderman/${{ github.sha }} + gh pr create -B migration --title "feat(spooderman): update images" --body "Updates the images for the spooderman timetable scraper deployment to commit csesoc/spooderman@${{ github.sha }}." > URL + gh pr merge $(cat URL) --squash -d