Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1734 registration2 ci cd #1758

Merged
merged 30 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c050061
chore: copy registration1 dockerfile to registration 2 project
marcellmueller Jun 6, 2024
521eeba
chore: add registration 2 docker build step
marcellmueller Jun 6, 2024
0721028
chore: add registration part 2 nx container config
marcellmueller Jun 6, 2024
4b55d66
refactor: separate test.yaml jobs
marcellmueller Jun 7, 2024
598134d
chore: remove required backend build step in workflow
marcellmueller Jun 7, 2024
d77f7e2
refactor: add main.yaml workflow
marcellmueller Jun 7, 2024
1716f0a
chore: add trivy scan to main workflow
marcellmueller Jun 7, 2024
56b3a73
chore: add codeql to main workflow
marcellmueller Jun 7, 2024
8c970f9
chore: fix registration1 workflow image location
marcellmueller Jun 7, 2024
45a7ff3
refactor: add docker build action
marcellmueller Jun 7, 2024
6b448b7
chore: rename docker-build action to nx-project-build
marcellmueller Jun 7, 2024
aec9f34
refactor: simplify workflow concurrency
marcellmueller Jun 7, 2024
005697b
chore: test workflow dev tools setup
marcellmueller Jun 7, 2024
bf0d82d
refactor: further split container workflows to optimize ci runtime
marcellmueller Jun 7, 2024
5a0b932
chore: remove duplicate ci job
marcellmueller Jun 7, 2024
4e752c2
refactor: ci build jobs
marcellmueller Jun 10, 2024
8bb5552
chore: add run-backend action
marcellmueller Jun 10, 2024
f821a36
chore: fix missing secrets
marcellmueller Jun 10, 2024
7bf5d60
chore: add registration2 helm templates
marcellmueller Jun 11, 2024
70f8cd5
chore: rename main workflow
marcellmueller Jun 11, 2024
dcf6547
chore: fix spelling error in nx-app-build
marcellmueller Jun 11, 2024
36d7d1a
chore: rebase
marcellmueller Jun 18, 2024
f939975
chore: add registration part2 build workflow
marcellmueller Jun 19, 2024
af52fd4
chore: update registration dockerfile
marcellmueller Jun 19, 2024
2318f74
chore: fix secrets
marcellmueller Jun 19, 2024
739cff8
chore: update e2e secrets
marcellmueller Jun 19, 2024
3999b27
chore: update comment based on pr review suggestion
marcellmueller Jun 28, 2024
30a92a7
chore: fix rebase regression
marcellmueller Jun 28, 2024
0de3442
chore: update comment
marcellmueller Jun 28, 2024
7c7bd15
chore: run pre-commit all files
marcellmueller Jun 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions .github/actions/nx-app-build/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: "Build and push Docker image for Nx frontend app in /bciers directory"
description: "Reusable action to build and push a Docker image for an Nx app in the /bciers directory"

inputs:
project:
description: "Nx project name"
required: true
image_url:
description: "Docker image URL"
required: true
github_token:
description: "GitHub token"
required: true

runs:
using: composite
steps:
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ inputs.image_url }}
tags: |
type=sha,format=long,prefix=
latest
type=ref,event=pr
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ inputs.github_token }}
- name: Install dependencies
shell: bash
run: |
corepack enable
yarn install --immutable
cd bciers && yarn install --immutable
- uses: actions/setup-node@v4
- name: Derive appropriate SHAs for base and head for `nx affected` commands
uses: nrwl/nx-set-shas@v4
with:
main-branch-name: "develop"
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-bciers-${{ inputs.project }}${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-bciers-${{ inputs.project }}
- name: Build images
shell: bash
env:
INPUT_GITHUB_TOKEN: ${{ inputs.github_token }}
INPUT_PUSH: true
INPUT_TAGS: ${{ steps.meta.outputs.tags }}
INPUT_LABELS: ${{ steps.meta.output.labels }}
INPUT_CACHE_FROM: type=local,src=/tmp/.buildx-cache
INPUT_CACHE_TO: type=local,dest=/tmp/.buildx-cache-new
run: |
npx nx container ${{ inputs.project }} --skip-nx-cache
working-directory: ./bciers
# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
shell: bash
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
14 changes: 14 additions & 0 deletions .github/actions/run-backend/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: "Run Django backend"
description: "Runs the Django backend locally"

inputs:
django_secret_key:
description: "Django secret key"
required: true

runs:
using: composite
steps:
- name: start backend
shell: bash
run: docker run -d --network=host -e "DB_USER=postgres" -e "DB_NAME=registration" -e "DB_PORT=5432" -e "DB_HOST=localhost" -e "DJANGO_SECRET_KEY=${{ inputs.django_secret_key }}" -e "ALLOWED_HOSTS=localhost,0.0.0.0,127.0.0.1" -e "ENVIRONMENT=develop" -e "CI=true" ghcr.io/bcgov/cas-reg-backend:${{ github.sha }}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ runs:
using: composite
steps:
- name: start backend
shell: bash
run: docker run -d --network=host -e "DB_USER=postgres" -e "DB_NAME=registration" -e "DB_PORT=5432" -e "DB_HOST=localhost" -e "DJANGO_SECRET_KEY=${{ inputs.django_secret_key }}" -e "ALLOWED_HOSTS=localhost,0.0.0.0,127.0.0.1" -e "ENVIRONMENT=develop" -e "CI=true" ghcr.io/bcgov/cas-reg-backend:${{ github.sha }}
uses: ./.github/actions/run-backend
with:
django_secret_key: ${{ inputs.django_secret_key }}
- name: start frontend
shell: bash
run: docker run -d --network=host -e "NEXTAUTH_URL_INTERNAL=http://localhost:3000/" -e "NEXTAUTH_URL=http://localhost:3000/" -e "NEXTAUTH_SECRET=${{ inputs.nextauth_secret }}" -e "API_URL=http://127.0.0.1:8000/api/" -e "KEYCLOAK_LOGIN_URL=https://dev.loginproxy.gov.bc.ca/auth/realms/standard" -e "KEYCLOAK_CLIENT_SECRET=${{ inputs.keycloak_client_secret }}" -e "KEYCLOAK_CLIENT_ID=${{ inputs.keycloak_client_id }}" ghcr.io/bcgov/cas-reg-frontend:${{ github.sha }}
run: docker run -d --network=host -e "NEXTAUTH_URL_INTERNAL=http://localhost:3000/" -e "NEXTAUTH_URL=http://localhost:3000/" -e "NEXTAUTH_SECRET=${{ inputs.nextauth_secret }}" -e "API_URL=http://127.0.0.1:8000/api/" -e "KEYCLOAK_LOGIN_URL=https://dev.loginproxy.gov.bc.ca/auth/realms/standard" -e "KEYCLOAK_CLIENT_SECRET=${{ inputs.keycloak_client_secret }}" -e "KEYCLOAK_CLIENT_ID=${{ inputs.keycloak_client_id }}" ghcr.io/bcgov/cas-reg1-frontend:${{ github.sha }}
55 changes: 55 additions & 0 deletions .github/workflows/build-backend.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Build BCIERS backend Docker container

on:
workflow_call:

jobs:
docker-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
with:
install: true
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/bcgov/cas-reg-backend
tags: |
type=sha,format=long,prefix=
latest
type=ref,event=pr
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-bc_obps-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-bc_obps
- name: Build image
uses: docker/build-push-action@v5
with:
context: bc_obps
builder: ${{ steps.buildx.outputs.name }}
push: true
file: bc_obps/Dockerfile
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
19 changes: 19 additions & 0 deletions .github/workflows/build-registration.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Build Registration Docker container

on:
workflow_call:

jobs:
docker-build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Build registration container
uses: ./.github/actions/nx-app-build
with:
project: registration
image_url: ghcr.io/bcgov/cas-reg-frontend
github_token: ${{ secrets.GITHUB_TOKEN }}
19 changes: 19 additions & 0 deletions .github/workflows/build-registration1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Build Registration1 Docker container

on:
workflow_call:

jobs:
docker-build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Build registration1 container
uses: ./.github/actions/nx-app-build
with:
project: registration1
image_url: ghcr.io/bcgov/cas-reg1-frontend
github_token: ${{ secrets.GITHUB_TOKEN }}
19 changes: 19 additions & 0 deletions .github/workflows/build-reporting.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Build Reporting Docker container

on:
workflow_call:

jobs:
docker-build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Build reporting container
uses: ./.github/actions/nx-app-build
with:
project: reporting
image_url: ghcr.io/bcgov/cas-rep-frontend
github_token: ${{ secrets.GITHUB_TOKEN }}
11 changes: 1 addition & 10 deletions .github/workflows/codeql.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,12 @@
name: "CodeQL"

on:
push:
branches: [main, develop]
tags:
- frontend
- backend
- configs
pull_request:
# The branches below must be a subset of the branches above
branches: [main, develop]
workflow_call:
schedule:
- cron: "19 23 * * 5"

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
Expand Down
54 changes: 54 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# This is the main workflow which will orchestrate the other workflows:

name: main

on:
push:
branches: [develop, main]
pull_request:
branches: [develop, main]
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
PGUSER: postgres

jobs:
install-dev-tools:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: dev env setup
uses: ./.github/actions/dev-env-setup
- run: yarn install --immutable
working-directory: ./bciers
build-backend:
uses: ./.github/workflows/build-backend.yaml
build-registration:
uses: ./.github/workflows/build-registration.yaml
build-registration1:
uses: ./.github/workflows/build-registration1.yaml
build-reporting:
uses: ./.github/workflows/build-reporting.yaml
test-code:
needs: [install-dev-tools]
uses: ./.github/workflows/test-code.yaml
test-backend:
needs: [build-backend, install-dev-tools]
uses: ./.github/workflows/test-backend.yaml
secrets: inherit
test-e2e:
needs: [build-registration1, install-dev-tools]
uses: ./.github/workflows/test-e2e.yaml
secrets: inherit
zap-owasp:
# We will need to set up registration part 2 and reporting to get zap scanned
needs: [build-backend, build-registration1, install-dev-tools]
uses: ./.github/workflows/zap-owasp.yaml
trivy:
uses: ./.github/workflows/trivy.yaml
codeql:
uses: ./.github/workflows/codeql.yaml
26 changes: 26 additions & 0 deletions .github/workflows/test-backend.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# This file is used for tests that use the backend container
# For tests that don't require containers to be built first, see test-code.yaml

name: Test BCIERS backend container

on:
workflow_call:

env:
PGUSER: postgres
DJANGO_SECRET_KEY: ${{ secrets.DJANGO_SECRET_KEY }}

jobs:
pythontests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: dev env setup
uses: ./.github/actions/dev-env-setup
- name: start backend
uses: ./.github/actions/run-backend
with:
django_secret_key: ${{ env.DJANGO_SECRET_KEY }}
- name: Run pytest
working-directory: ./bc_obps
run: make pythontests
76 changes: 76 additions & 0 deletions .github/workflows/test-code.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# This workflow is to run all tests that don't require containers to be built

name: Test BCIERS code

on:
workflow_call:

env:
PGUSER: postgres
DJANGO_SECRET_KEY: ${{ secrets.DJANGO_SECRET_KEY }}
KEYCLOAK_CLIENT_ID: ${{ secrets.KEYCLOAK_CLIENT_ID }}
KEYCLOAK_CLIENT_SECRET: ${{ secrets.KEYCLOAK_CLIENT_SECRET }}
NEXTAUTH_SECRET: ${{ secrets.NEXTAUTH_SECRET }}

jobs:
nx-tests:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./bciers
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: dev env setup
uses: ./.github/actions/dev-env-setup
- name: Run Nx Affected Tests with Remote Caching
id: nx-tests
run: |
yarn nx affected --base=origin/develop --target=test --parallel
shell: bash

yarn-audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: dev env setup
uses: ./.github/actions/dev-env-setup
- run: yarn npm audit
working-directory: ./bciers

pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: dev env setup
uses: ./.github/actions/dev-env-setup
- name: set pre-commit cache directory
run: |
echo "PRE_COMMIT_HOME=$GITHUB_WORKSPACE/.pre-commit-cache" >> $GITHUB_ENV
- name: set PY
run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV
- name: create commitlint COMMIT_EDITMSG if not exists
run: |
if test -f ".git/COMMIT_EDITMSG"; then
echo "COMMIT_EDITMSG EXISTS, skipping"
else
touch .git/COMMIT_EDITMSG
fi
- uses: actions/cache@v4
with:
path: |
./.pre-commit-cache
key: pre-commit-${{ env.PY }}-${{ hashFiles('.pre-commit-config.yaml') }}-v4
- run: pip install -r requirements.txt
- uses: pre-commit/[email protected]

check-migrations:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: dev env setup
uses: ./.github/actions/dev-env-setup
- run: poetry run python manage.py makemigrations --check --dry-run
working-directory: ./bc_obps
Loading
Loading