diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 1230187f..9f7e8e79 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -6,7 +6,7 @@ # review when someone opens a pull request. -- @Fosol +- @Fosol @wkaspryk # Order is important; the last matching pattern takes the most diff --git a/.github/workflows/ci-cd-dev.yml b/.github/workflows/ci-cd-dev.yml index a9bf14a2..ea395e0b 100644 --- a/.github/workflows/ci-cd-dev.yml +++ b/.github/workflows/ci-cd-dev.yml @@ -31,11 +31,16 @@ on: # branches: # - dev # - main + # - test jobs: build-push: name: Build and Push to Registry runs-on: ubuntu-latest + outputs: + api: ${{ steps.filter.outputs.api }} + dashboard: ${{ steps.filter.outputs.dashboard }} + db-migration: ${{ steps.filter.outputs.db-migration }} timeout-minutes: 10 permissions: contents: read @@ -46,12 +51,26 @@ jobs: with: ref: ${{ github.event.pull_request.head.sha }} + - name: filter + uses: dorny/paths-filter@v2 + id: filter + with: + filters: | + api: + - 'src/api/**' + - 'src/libs/**' + dashboard: + - 'src/dashboard/**' + db-migration: + - 'src/libs/dal/**' + ## BUILD - name: Build API id: build-api uses: redhat-actions/buildah-build@v2 + if: steps.filter.outputs.api == 'true' with: - image: ${{ github.repository }}/${{ env.API_IMAGE_NAME }} + image: ${{ github.event.repository.name }}/${{ env.API_IMAGE_NAME }} tags: ${{ env.IMAGE_TAG }} ${{ env.VERSION }} ${{ env.DEPLOY_TO }} context: . dockerfiles: | @@ -60,8 +79,9 @@ jobs: - name: Build Dasbhoard id: build-app uses: redhat-actions/buildah-build@v2 + if: steps.filter.outputs.dashboard == 'true' with: - image: ${{ github.repository }}/${{ env.APP_IMAGE_NAME }} + image: ${{ github.event.repository.name }}/${{ env.APP_IMAGE_NAME }} tags: ${{ env.IMAGE_TAG }} ${{ env.VERSION }} ${{ env.DEPLOY_TO }} context: src/dashboard dockerfiles: | @@ -70,8 +90,9 @@ jobs: - name: Build DB Migration id: build-db-migration uses: redhat-actions/buildah-build@v2 + if: steps.filter.outputs.db-migration == 'true' with: - image: ${{ github.repository }}/${{ env.DB_MIGRATION_IMAGE_NAME }} + image: ${{ github.event.repository.name }}/${{ env.DB_MIGRATION_IMAGE_NAME }} tags: ${{ env.IMAGE_TAG }} ${{ env.VERSION }} ${{ env.DEPLOY_TO }} context: src/libs dockerfiles: | @@ -80,8 +101,9 @@ jobs: ## PUSH TO REGISTRY - name: Push API to registry uses: redhat-actions/push-to-registry@v2 + if: steps.filter.outputs.api == 'true' with: - image: ${{ github.repository }}/${{ env.DB_MIGRATION_IMAGE_NAME }} + image: ${{ steps.build-api.outputs.image }} tags: ${{ steps.build-api.outputs.tags }} registry: ${{ env.IMAGE_REGISTRY }} username: ${{ env.IMAGE_REGISTRY_USER }} @@ -89,6 +111,7 @@ jobs: - name: Push Dashboard to registry uses: redhat-actions/push-to-registry@v2 + if: steps.filter.outputs.dashboard == 'true' with: image: ${{ steps.build-app.outputs.image }} tags: ${{ steps.build-app.outputs.tags }} @@ -98,6 +121,7 @@ jobs: - name: Push DB Migration to registry uses: redhat-actions/push-to-registry@v2 + if: steps.filter.outputs.db-migration == 'true' with: image: ${{ steps.build-db-migration.outputs.image }} tags: ${{ steps.build-db-migration.outputs.tags }} diff --git a/devops/kustomize/base/tekton/imageStreams/api.yaml b/devops/kustomize/base/tekton/imageStreams/api.yaml index 61edb5d1..ab453c76 100644 --- a/devops/kustomize/base/tekton/imageStreams/api.yaml +++ b/devops/kustomize/base/tekton/imageStreams/api.yaml @@ -14,13 +14,34 @@ spec: lookupPolicy: local: false tags: + - name: dev + annotations: null + from: + kind: DockerImage + name: >- + artifacts.developer.gov.bc.ca/github-docker-remote/bcgov/hsb-dashboard/api:dev + importPolicy: + scheduled: true + importMode: Legacy + referencePolicy: + type: Source - name: latest annotations: null from: kind: DockerImage name: >- - artifacts.developer.gov.bc.ca/github-docker-remote/bcgov/bcgov/hsb-dashboard/api:latest - generation: 1 + artifacts.developer.gov.bc.ca/github-docker-remote/bcgov/hsb-dashboard/api:latest + importPolicy: + scheduled: true + importMode: Legacy + referencePolicy: + type: Source + - name: test + annotations: null + from: + kind: DockerImage + name: >- + artifacts.developer.gov.bc.ca/github-docker-remote/bcgov/hsb-dashboard/api:test importPolicy: scheduled: true importMode: Legacy diff --git a/devops/kustomize/base/tekton/imageStreams/app.yaml b/devops/kustomize/base/tekton/imageStreams/app.yaml index 6d4c64f6..509859d3 100644 --- a/devops/kustomize/base/tekton/imageStreams/app.yaml +++ b/devops/kustomize/base/tekton/imageStreams/app.yaml @@ -14,13 +14,34 @@ spec: lookupPolicy: local: false tags: + - name: dev + annotations: null + from: + kind: DockerImage + name: >- + artifacts.developer.gov.bc.ca/github-docker-remote/bcgov/hsb-dashboard/dashboard:dev + importPolicy: + scheduled: true + importMode: Legacy + referencePolicy: + type: Source - name: latest annotations: null from: kind: DockerImage name: >- - artifacts.developer.gov.bc.ca/github-docker-remote/bcgov/bcgov/hsb-dashboard/dashboard:latest - generation: 1 + artifacts.developer.gov.bc.ca/github-docker-remote/bcgov/hsb-dashboard/dashboard:latest + importPolicy: + scheduled: true + importMode: Legacy + referencePolicy: + type: Source + - name: test + annotations: null + from: + kind: DockerImage + name: >- + artifacts.developer.gov.bc.ca/github-docker-remote/bcgov/hsb-dashboard/dashboard:test importPolicy: scheduled: true importMode: Legacy diff --git a/devops/kustomize/base/tekton/imageStreams/db-migration.yaml b/devops/kustomize/base/tekton/imageStreams/db-migration.yaml index ccf363b7..b35835a4 100644 --- a/devops/kustomize/base/tekton/imageStreams/db-migration.yaml +++ b/devops/kustomize/base/tekton/imageStreams/db-migration.yaml @@ -14,13 +14,34 @@ spec: lookupPolicy: local: false tags: + - name: dev + annotations: null + from: + kind: DockerImage + name: >- + artifacts.developer.gov.bc.ca/github-docker-remote/bcgov/hsb-dashboard/db-migration:dev + importPolicy: + scheduled: true + importMode: Legacy + referencePolicy: + type: Source - name: latest annotations: null from: kind: DockerImage name: >- - artifacts.developer.gov.bc.ca/github-docker-remote/bcgov/bcgov/hsb-dashboard/db-migration:latest - generation: 1 + artifacts.developer.gov.bc.ca/github-docker-remote/bcgov/hsb-dashboard/db-migration:latest + importPolicy: + scheduled: true + importMode: Legacy + referencePolicy: + type: Source + - name: test + annotations: null + from: + kind: DockerImage + name: >- + artifacts.developer.gov.bc.ca/github-docker-remote/bcgov/hsb-dashboard/db-migration:test importPolicy: scheduled: true importMode: Legacy diff --git a/do b/do index f4307d7b..3719c02d 100644 --- a/do +++ b/do @@ -67,8 +67,12 @@ elif [ "$action" = "db-redo" ]; then # Openshift elif [ "$action" = "db-connect" ]; then db-connect ${2-prod} ${3-} ${4-} -elif [ "$action" = "deploy" ]; then - deploy ${2-} ${3-} ${4-} +elif [ "$action" = "oc-build" ]; then + oc-build ${2-} ${3-} +elif [ "$action" = "oc-push" ]; then + oc-push ${2-} ${3-} +elif [ "$action" = "oc-deploy" ]; then + oc-deploy ${2-} ${3-} ${4-} ${5-} # NPM elif [ "$action" = "npm-install" ]; then diff --git a/scripts/oc.sh b/scripts/oc.sh index aaca752c..44a2e10a 100644 --- a/scripts/oc.sh +++ b/scripts/oc.sh @@ -1,5 +1,7 @@ #!/bin/bash +IMAGE_REGISTRY='image-registry.apps.emerald.devops.gov.bc.ca' + db-connect () { die () { echo >&2 "$@" @@ -19,12 +21,30 @@ db-connect () { fi } -deploy () { +oc-build () { image=${1-} tag=${2-'latest'} - env=${3-} - IMAGE_REGISTRY=${4-'image-registry.apps.emerald.devops.gov.bc.ca'} + # Extract the random characters of the project namespace. + project=$(oc project --short); project=${project//-[a-z]*/}; echo $project + + if [ "$image" = "api" ]; then + # buid api + docker build -f src/api/Dockerfile -t $IMAGE_REGISTRY/$project-tools/$image:$tag . + elif [ "$image" = "app" ]; then + # buid app + image=dashboard + docker build -f src/dashboard/Dockerfile.prod -t $IMAGE_REGISTRY/$project-tools/$image:$tag ./src/dashboard + elif [ "$image" = "db" ]; then + # buid app + image=db-migration + docker build -f src/libs/Dockerfile -t $IMAGE_REGISTRY/$project-tools/$image:$tag ./src/libs + fi +} + +oc-push () { + image=${1-} + tag=${2-'latest'} # Extract the random characters of the project namespace. project=$(oc project --short); project=${project//-[a-z]*/}; echo $project @@ -35,102 +55,112 @@ deploy () { if [ "$image" = "api" ]; then # buid and deploy api - docker build -f src/api/Dockerfile -t $IMAGE_REGISTRY/$project-tools/$image:$tag . docker push $IMAGE_REGISTRY/$project-tools/$image:$tag - - if [ ! -z "$env" ]; then - oc tag $image:$tag $image:$env - fi elif [ "$image" = "app" ]; then # buid and deploy app image=dashboard - docker build -f src/dashboard/Dockerfile.prod -t $IMAGE_REGISTRY/$project-tools/$image:$tag ./src/dashboard docker push $IMAGE_REGISTRY/$project-tools/$image:$tag - - if [ ! -z "$env" ]; then - oc tag $image:$tag $image:$env - fi elif [ "$image" = "db" ]; then # buid and deploy app image=db-migration - docker build -f src/libs/Dockerfile -t $IMAGE_REGISTRY/$project-tools/$image:$tag ./src/libs docker push $IMAGE_REGISTRY/$project-tools/$image:$tag + fi +} + +oc-deploy () { + image=${1-} + tag=${2-'latest'} + env=${3-'dev'} + + # Extract the random characters of the project namespace. + project=$(oc project --short); project=${project//-[a-z]*/}; echo $project + # Change the current environment + oc project $project-tools + # login + docker login -u $(oc whoami) -p $(oc whoami -t) $IMAGE_REGISTRY/$project-tools + + if [ "$image" = "api" ]; then + oc tag $image:$tag $image:$env + elif [ "$image" = "app" ]; then + # buid and deploy app + image=dashboard + oc tag $image:$tag $image:$env + elif [ "$image" = "db" ]; then + # buid and deploy app + image=db-migration migration=${4-} - # --rm \ - if [ ! -z "$env" ]; then - oc tag $image:$tag $image:$env - echo "Running database migration in $project-$env" - overrides="{ - \"apiVersion\":\"v1\", - \"spec\":{ - \"containers\":[ - { - \"name\":\"$image\", - \"image\":\"$IMAGE_REGISTRY/$project-tools/$image:$env\", - \"env\":[ - { - \"name\":\"MIGRATION\", - \"value\":\"$migration\" - }, - { - \"name\":\"ConnectionStrings__Default\", - \"valueFrom\":{ - \"secretKeyRef\":{ - \"name\":\"database\", - \"key\":\"CONNECTION_STRING\" - } - } - }, - { - \"name\":\"POSTGRES_USER\", - \"valueFrom\":{ - \"secretKeyRef\":{ - \"name\":\"database\", - \"key\":\"DB_USER\" - } + oc tag $image:$tag $image:$env + echo "Running database migration '$migration' in $project-$env" + overrides="{ + \"apiVersion\":\"v1\", + \"spec\":{ + \"containers\":[ + { + \"name\":\"$image\", + \"image\":\"$IMAGE_REGISTRY/$project-tools/$image:$env\", + \"env\":[ + { + \"name\":\"MIGRATION\", + \"value\":\"$migration\" + }, + { + \"name\":\"ConnectionStrings__Default\", + \"valueFrom\":{ + \"secretKeyRef\":{ + \"name\":\"database\", + \"key\":\"CONNECTION_STRING\" } - }, - { - \"name\":\"POSTGRES_PASSWORD\", - \"valueFrom\":{ - \"secretKeyRef\":{ - \"name\":\"database\", - \"key\":\"DB_PASSWORD\" - } + } + }, + { + \"name\":\"POSTGRES_USER\", + \"valueFrom\":{ + \"secretKeyRef\":{ + \"name\":\"database\", + \"key\":\"DB_USER\" } } - ], - \"labels\":{ - \"name\":\"db-migration\",\"part-of\":\"hsb\",\"component\":\"database\",\"DataClass\":\"Low\" - }, - \"resources\":{ - \"requests\":{ - \"memory\":\"250Mi\", - \"cpu\":\"50m\" - }, - \"limits\":{ - \"memory\":\"500Mi\", - \"cpu\":\"250m\" + }, + { + \"name\":\"POSTGRES_PASSWORD\", + \"valueFrom\":{ + \"secretKeyRef\":{ + \"name\":\"database\", + \"key\":\"DB_PASSWORD\" + } } + } + ], + \"labels\":{ + \"name\":\"db-migration\",\"part-of\":\"hsb\",\"component\":\"database\",\"DataClass\":\"Low\" + }, + \"resources\":{ + \"requests\":{ + \"memory\":\"250Mi\", + \"cpu\":\"50m\" }, - \"imagePullPolicy\": \"Always\" - } - ] - } - }" - oc run $image \ - -n $project-$env \ - --image=$image \ - --image-pull-policy=Always \ - --attach \ - --rm \ - --labels='name=db-migration,part-of=hsb,component=database,DataClass=Low' \ - --restart=Never \ - --timeout=10m \ - --override-type='merge' \ - --overrides="$overrides" - fi + \"limits\":{ + \"memory\":\"500Mi\", + \"cpu\":\"250m\" + } + }, + \"imagePullPolicy\": \"Always\" + } + ] + } + }" + oc run $image \ + -n $project-$env \ + --image=$image \ + --image-pull-policy=Always \ + --attach \ + --rm \ + --labels='name=db-migration,part-of=hsb,component=database,DataClass=Low' \ + --restart=Never \ + --timeout=10m \ + --override-type='merge' \ + --overrides="$overrides" fi } diff --git a/src/dashboard/src/components/header/Header.tsx b/src/dashboard/src/components/header/Header.tsx index d0f74d4f..a4f92d35 100644 --- a/src/dashboard/src/components/header/Header.tsx +++ b/src/dashboard/src/components/header/Header.tsx @@ -1,8 +1,8 @@ 'use client'; +import Image from 'next/image'; import { usePathname } from 'next/navigation'; import { AuthState } from '../auth'; -import Image from 'next/image'; import './style.css'; export const Header: React.FC = () => {