From d30ef217b8db4d04e8e6859e33692c9772f7dda1 Mon Sep 17 00:00:00 2001 From: chinoGoblino Date: Sun, 17 Nov 2024 16:24:17 +1100 Subject: [PATCH] Added ci pipeline for staging branch --- .github/workflows/codeql.yml | 4 +- .github/workflows/docker-staging.yml | 81 ++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/docker-staging.yml diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 834be5c0c..96af92485 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -2,9 +2,9 @@ name: "CodeQL" on: push: - branches: [ "dev" ] + branches: [ "dev", "331-staging" ] pull_request: - branches: [ "dev" ] + branches: [ "dev", "331-staging" ] schedule: - cron: '18 14 * * 5' diff --git a/.github/workflows/docker-staging.yml b/.github/workflows/docker-staging.yml new file mode 100644 index 000000000..68fbd531f --- /dev/null +++ b/.github/workflows/docker-staging.yml @@ -0,0 +1,81 @@ +name: Docker (Staging) +on: + push: + branches: [ "331-staging" ] + +jobs: + build: + name: "Build (${{ matrix.component }})" + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + strategy: + fail-fast: false + matrix: + component: [frontend, backend] + include: + - component: frontend + dockerfile: production.dockerfile + args: | + "API_URL=https://circlesstagingapi.devsoc.app" + - component: backend + dockerfile: production.dockerfile + steps: + - name: Checkout repository + uses: actions/checkout@v3 + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + with: + platforms: arm64 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Log into registry ${{ env.REGISTRY }} + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GH_TOKEN }} + - name: Build and push Docker image + uses: docker/build-push-action@v3 + with: + context: ${{ matrix.component }} + push: ${{ github.event_name != 'pull_request' && github.ref == 'refs/heads/331-staging' }} + platforms: linux/amd64 + file: ${{ matrix.component }}/${{ matrix.dockerfile }} + build-args: ${{ matrix.args }} + tags: | + ghcr.io/csesoc/circles-staging-${{ matrix.component }}:${{ github.sha }} + ghcr.io/csesoc/circles-staging-${{ matrix.component }}:latest + labels: ${{ steps.meta.outputs.labels }} + deploy: + name: Deploy (CD) + runs-on: ubuntu-latest + needs: [build] + concurrency: production + environment: production + if: ${{ github.event_name != 'pull_request' && github.ref == 'refs/heads/331-staging' }} + + 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.35.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/circles-staging/${{ github.sha }} + yq -i '.items[0].spec.template.spec.containers[0].image = "ghcr.io/csesoc/circles-staging-frontend:${{ github.sha }}"' projects/circles-staging/deploy-frontend.yml + yq -i '.items[0].spec.template.spec.containers[0].image = "ghcr.io/csesoc/circles-staging-backend:${{ github.sha }}"' projects/circles-staging/deploy-backend.yml + git add . + git commit -m "feat(circles-staging): update images" + git push -u origin update/circles-staging/${{ github.sha }} + gh pr create -B migration --title "feat(circles-staging): update image" --body "Updates the image for the circles staging deployment to commit csesoc/circles-staging@${{ github.sha }}." > URL + gh pr merge $(cat URL) --squash -d