From 94a378253295e85d814d7922dbd9af2370e12713 Mon Sep 17 00:00:00 2001 From: Wolfdragon24 Date: Thu, 22 May 2025 21:33:35 +1000 Subject: [PATCH 1/3] Add updated csesoc website deployment CI/CD --- .github/workflows/backend-ci.yml | 32 ------------- .github/workflows/ci.yml | 39 ++++++++++++++++ .github/workflows/docker.yml | 74 +++++++++++++++++++++++++++++++ .github/workflows/frontend-ci.yml | 35 --------------- 4 files changed, 113 insertions(+), 67 deletions(-) delete mode 100644 .github/workflows/backend-ci.yml create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/docker.yml delete mode 100644 .github/workflows/frontend-ci.yml diff --git a/.github/workflows/backend-ci.yml b/.github/workflows/backend-ci.yml deleted file mode 100644 index 77bed59..0000000 --- a/.github/workflows/backend-ci.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: Backend CI - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - -jobs: - build: - runs-on: ubuntu-latest - - defaults: - run: - working-directory: ./backend - - steps: - - uses: actions/checkout@v3 - - - name: Use Node.js 22 - uses: actions/setup-node@v3 - with: - node-version: 22 - - - name: Install dependencies - run: npm install - - - name: Check types - run: npm run type-check - - - name: Build Express app - run: npm run build diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..ec916ca --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,39 @@ +name: ci + +on: + push: + branches: + - master + - renovate/* + pull_request: + branches: + - master + +jobs: + api-ci: + runs-on: ubuntu-latest + defaults: + run: + working-directory: ./backend + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v3 + with: + node-version: 22 + - run: npm ci + - run: npm run type-check + - run: npm run build + ui-ci: + runs-on: ubuntu-latest + defaults: + run: + working-directory: ./frontend + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v3 + with: + node-version: 16 + - run: npm install + - run: npm run lint + - run: npm run type-check + - run: npm run build \ No newline at end of file diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..005ad93 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,74 @@ +name: Docker +on: + push: + branches: + - "master" + +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' }} + 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-prod: + name: Deploy Production (CD) + runs-on: ubuntu-latest + needs: [build] + concurrency: prod + environment: + name: prod + if: ${{ github.event_name != 'pull_request' && github.ref == 'refs/heads/main' }} + 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: 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-prod/${{ github.sha }} + yq -i '.items[0].spec.template.spec.containers[0].image = "ghcr.io/csesoc/website-backend:${{ github.sha }}"' apps/projects/website/prod/deploy-backend.yml + yq -i '.items[0].spec.template.spec.containers[0].image = "ghcr.io/csesoc/website-frontend:${{ github.sha }}"' apps/projects/website/prod/deploy-frontend.yml + git add . + git commit -m "feat(website/prod): update image" + git push -u origin update/website-prod/${{ github.sha }} + gh pr create -B develop --title "feat(website/prod): 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 \ No newline at end of file diff --git a/.github/workflows/frontend-ci.yml b/.github/workflows/frontend-ci.yml deleted file mode 100644 index 1afed18..0000000 --- a/.github/workflows/frontend-ci.yml +++ /dev/null @@ -1,35 +0,0 @@ -name: Frontend CI - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - -jobs: - build: - runs-on: ubuntu-latest - - defaults: - run: - working-directory: ./frontend - - steps: - - uses: actions/checkout@v3 - - - name: Use Node.js 16 - uses: actions/setup-node@v3 - with: - node-version: 16 - - - name: Install dependencies - run: npm install - - - name: Lint code - run: npm run lint - - - name: Check types - run: npm run type-check - - - name: Build Next.js app - run: npm run build From e699966ba7e020dc9bc92dcd7077a5ec0b665a5d Mon Sep 17 00:00:00 2001 From: Wolfdragon24 Date: Tue, 1 Jul 2025 11:58:56 +1000 Subject: [PATCH 2/3] Deployment update for qa branch --- .github/workflows/ci.yml | 2 ++ .github/workflows/docker.yml | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ec916ca..46d5824 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,10 +4,12 @@ on: push: branches: - master + - qa - renovate/* pull_request: branches: - master + - qa jobs: api-ci: diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 005ad93..4634f3b 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -71,4 +71,35 @@ jobs: git commit -m "feat(website/prod): update image" git push -u origin update/website-prod/${{ github.sha }} gh pr create -B develop --title "feat(website/prod): 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 + deploy-qa: + name: Deploy QA (CD) + runs-on: ubuntu-latest + needs: [build] + concurrency: qa + environment: + name: qa + if: ${{ github.event_name != 'pull_request' && 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: 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-qa/${{ github.sha }} + yq -i '.items[0].spec.template.spec.containers[0].image = "ghcr.io/csesoc/website-qa-backend:${{ github.sha }}"' apps/projects/website/qa/deploy-backend.yml + yq -i '.items[0].spec.template.spec.containers[0].image = "ghcr.io/csesoc/website-qa-frontend:${{ github.sha }}"' apps/projects/website/qa/deploy-frontend.yml + git add . + git commit -m "feat(website/qa): update image" + git push -u origin update/website-qa/${{ github.sha }} + gh pr create -B develop --title "feat(website/qa): update image" --body "Updates the image for the website-qa deployment to commit csesoc/csesoc-website@${{ github.sha }}." > URL gh pr merge $(cat URL) --squash -d \ No newline at end of file From 2bb92f4b3001ad5ebedd9fa162873c926898be4f Mon Sep 17 00:00:00 2001 From: Wolfdragon24 Date: Tue, 1 Jul 2025 12:12:49 +1000 Subject: [PATCH 3/3] Adjustment to deployment layout and appending qa deployment --- .github/workflows/docker.yml | 60 +++++++++++++----------------------- 1 file changed, 21 insertions(+), 39 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 4634f3b..2575614 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -3,6 +3,7 @@ on: push: branches: - "master" + - "qa" jobs: build: @@ -34,21 +35,21 @@ jobs: uses: docker/build-push-action@v5 with: context: ${{ matrix.component }} - push: ${{ github.event_name != 'pull_request' }} + push: ${{ github.event_name != 'pull_request' && ( github.ref == 'refs/heads/main' || 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-prod: - name: Deploy Production (CD) + 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/main' }} + if: ${{ github.event_name != 'pull_request' && ( github.ref == 'refs/heads/main' || github.ref == 'refs/heads/qa' ) }} steps: - name: Checkout repository uses: actions/checkout@v4 @@ -58,48 +59,29 @@ jobs: ref: develop - name: Install yq - portable yaml processor uses: mikefarah/yq@v4.27.2 - - name: Update deployment + - name: "Determine deployment type" + id: get_manifest env: - GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} + BRANCH: ${{ github.ref }} run: | - git config user.name "CSESoc CD" - git config user.email "technical@csesoc.org.au" - git checkout -b update/website-prod/${{ github.sha }} - yq -i '.items[0].spec.template.spec.containers[0].image = "ghcr.io/csesoc/website-backend:${{ github.sha }}"' apps/projects/website/prod/deploy-backend.yml - yq -i '.items[0].spec.template.spec.containers[0].image = "ghcr.io/csesoc/website-frontend:${{ github.sha }}"' apps/projects/website/prod/deploy-frontend.yml - git add . - git commit -m "feat(website/prod): update image" - git push -u origin update/website-prod/${{ github.sha }} - gh pr create -B develop --title "feat(website/prod): 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 - deploy-qa: - name: Deploy QA (CD) - runs-on: ubuntu-latest - needs: [build] - concurrency: qa - environment: - name: qa - if: ${{ github.event_name != 'pull_request' && 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 + if [[ "${{ github.ref }}" == "refs/heads/main" ]]; 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-qa/${{ github.sha }} - yq -i '.items[0].spec.template.spec.containers[0].image = "ghcr.io/csesoc/website-qa-backend:${{ github.sha }}"' apps/projects/website/qa/deploy-backend.yml - yq -i '.items[0].spec.template.spec.containers[0].image = "ghcr.io/csesoc/website-qa-frontend:${{ github.sha }}"' apps/projects/website/qa/deploy-frontend.yml + 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/qa): update image" - git push -u origin update/website-qa/${{ github.sha }} - gh pr create -B develop --title "feat(website/qa): update image" --body "Updates the image for the website-qa deployment to commit csesoc/csesoc-website@${{ github.sha }}." > URL + 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 \ No newline at end of file