diff --git a/.github/workflows/DevEnv-backend-BuildImageAndPush.yml b/.github/workflows/DevEnv-backend-BuildImageAndPush.yml index f428aa14..7396287f 100644 --- a/.github/workflows/DevEnv-backend-BuildImageAndPush.yml +++ b/.github/workflows/DevEnv-backend-BuildImageAndPush.yml @@ -2,7 +2,8 @@ name: DevEnv-backend-BuildImageAndPush # Build the image and deploy in OpenShift environment env: # Registries such as GHCR, Quay.io, and Docker Hub are supported. - IMAGE_REGISTRY: image-registry.apps.silver.devops.gov.bc.ca/c5839f-tools + TOOLSNS_IMAGE_REGISTRY: image-registry.apps.silver.devops.gov.bc.ca/c5839f-tools + DEVNS_IMAGE_REGISTRY: image-registry.apps.silver.devops.gov.bc.ca/c5839f-dev IMAGE_REGISTRY_USER: ${{ secrets.C5839F_OPENSHIFT_GITHUB_ACTIONS_SA_USER }} IMAGE_REGISTRY_PASSWORD: ${{ secrets.C5839F_OPENSHIFT_GITHUB_ACTIONS_SA_TOKEN }} IMAGE_NAME: mspdirect-backend @@ -37,7 +38,7 @@ jobs: - name: Determine image tags if: env.IMAGE_TAGS == '' run: | - echo "IMAGE_TAGS=latest ${GITHUB_SHA::12} mspdirect-dev" | tee -a $GITHUB_ENV + echo "IMAGE_TAGS=${GITHUB_SHA::12}" | tee -a $GITHUB_ENV # Build from docker file @@ -51,13 +52,24 @@ jobs: dockerfiles: | ./backend/Dockerfile - - name: Push to registry - id: push-image + - name: Push to tools registry + id: push-image-tools uses: redhat-actions/push-to-registry@v2 with: image: ${{ steps.build-docker.outputs.image }} tags: ${{ steps.build-docker.outputs.tags }} - registry: ${{ env.IMAGE_REGISTRY }} + registry: ${{ env.TOOLSNS_IMAGE_REGISTRY }} + username: ${{ env.IMAGE_REGISTRY_USER }} + password: ${{ env.IMAGE_REGISTRY_PASSWORD }} + + + - name: Push to dev registry + id: push-image-dev + uses: redhat-actions/push-to-registry@v2 + with: + image: ${{ steps.build-docker.outputs.image }} + tags: ${{ steps.build-docker.outputs.tags }} + registry: ${{ env.DEVNS_IMAGE_REGISTRY }} username: ${{ env.IMAGE_REGISTRY_USER }} password: ${{ env.IMAGE_REGISTRY_PASSWORD }} @@ -85,7 +97,7 @@ jobs: if: ${{ success() }} run: | cd mspdirect-devops/overlays/dev - kustomize edit set image "backend-image=image-registry.openshift-image-registry.svc:5000/c5839f-tools/${{ env.IMAGE_NAME }}@${{ steps.push-image.outputs.digest }}" + kustomize edit set image "backend-image=image-registry.openshift-image-registry.svc:5000/c5839f-dev/${{ env.IMAGE_NAME }}@${{ steps.push-image-dev.outputs.digest }}" git config --local user.email "action@github.com" git config --local user.name "GitHub Action" git commit -am "Update Backend API image ID for Dev" diff --git a/.github/workflows/DevEnv-frontend-BuildImageAndPush.yml b/.github/workflows/DevEnv-frontend-BuildImageAndPush.yml index 7202131a..ce6defcf 100644 --- a/.github/workflows/DevEnv-frontend-BuildImageAndPush.yml +++ b/.github/workflows/DevEnv-frontend-BuildImageAndPush.yml @@ -2,11 +2,12 @@ name: DevEnv-frontend-BuildImageAndPush # Build the image and deploy in OpenShift environment env: # Registries such as GHCR, Quay.io, and Docker Hub are supported. - IMAGE_REGISTRY: image-registry.apps.silver.devops.gov.bc.ca/c5839f-tools + DEVNS_IMAGE_REGISTRY: image-registry.apps.silver.devops.gov.bc.ca/c5839f-dev + TOOLSNS_IMAGE_REGISTRY: image-registry.apps.silver.devops.gov.bc.ca/c5839f-tools IMAGE_REGISTRY_USER: ${{ secrets.C5839F_OPENSHIFT_GITHUB_ACTIONS_SA_USER }} IMAGE_REGISTRY_PASSWORD: ${{ secrets.C5839F_OPENSHIFT_GITHUB_ACTIONS_SA_TOKEN }} IMAGE_NAME: mspdirect-frontend - IMAGE_TAGS: + IMAGE_TAGS: on: # Run the workflow manually, instead of on a push. @@ -39,8 +40,7 @@ jobs: - name: Determine image tags if: env.IMAGE_TAGS == '' run: | - echo "IMAGE_TAGS=latest ${GITHUB_SHA::12} mspdirect-dev" | tee -a $GITHUB_ENV - + echo "IMAGE_TAGS=${GITHUB_SHA::12}" | tee -a $GITHUB_ENV # Build from docker file - name: Build from Dockerfile @@ -54,16 +54,27 @@ jobs: dockerfiles: | ./frontend/Dockerfile - - name: Push to registry - id: push-image + - name: Push to tools registry + id: push-image-tools uses: redhat-actions/push-to-registry@v2 with: image: ${{ steps.build-docker.outputs.image }} tags: ${{ steps.build-docker.outputs.tags }} - registry: ${{ env.IMAGE_REGISTRY }} + registry: ${{ env.TOOLSNS_IMAGE_REGISTRY }} username: ${{ env.IMAGE_REGISTRY_USER }} password: ${{ env.IMAGE_REGISTRY_PASSWORD }} + + - name: Push to Dev registry + id: push-image-dev + uses: redhat-actions/push-to-registry@v2 + with: + image: ${{ steps.build-docker.outputs.image }} + tags: ${{ steps.build-docker.outputs.tags }} + registry: ${{ env.DEVNS_IMAGE_REGISTRY }} + username: ${{ env.IMAGE_REGISTRY_USER }} + password: ${{ env.IMAGE_REGISTRY_PASSWORD }} + # Update the image ID in the manifest repository used by Argo CD. # We need to use the SSH deploy key to check out the manifest repo, set up # Kustomize in the runner, update the image ID, commit the change, and @@ -88,7 +99,7 @@ jobs: if: ${{ success() }} run: | cd mspdirect-devops/overlays/dev - kustomize edit set image "frontend-image=image-registry.openshift-image-registry.svc:5000/c5839f-tools/${{ env.IMAGE_NAME }}@${{ steps.push-image.outputs.digest }}" + kustomize edit set image "frontend-image=image-registry.openshift-image-registry.svc:5000/c5839f-dev/${{ env.IMAGE_NAME }}@${{ steps.push-image-dev.outputs.digest }}" git config --local user.email "action@github.com" git config --local user.name "GitHub Action" git commit -am "Update frontend API image ID for Dev" diff --git a/.github/workflows/TestEnv-backend-BuildImageAndPush.yml b/.github/workflows/TestEnv-backend-BuildImageAndPush.yml index 14f43df4..10a93916 100644 --- a/.github/workflows/TestEnv-backend-BuildImageAndPush.yml +++ b/.github/workflows/TestEnv-backend-BuildImageAndPush.yml @@ -2,7 +2,8 @@ name: TestEnv-backend-BuildImageAndPush # Build the image and deploy in OpenShift environment env: # Registries such as GHCR, Quay.io, and Docker Hub are supported. - IMAGE_REGISTRY: image-registry.apps.silver.devops.gov.bc.ca/c5839f-tools + TOOLSNS_IMAGE_REGISTRY: image-registry.apps.silver.devops.gov.bc.ca/c5839f-tools + TESTNS_IMAGE_REGISTRY: image-registry.apps.silver.devops.gov.bc.ca/c5839f-test IMAGE_REGISTRY_USER: ${{ secrets.C5839F_OPENSHIFT_GITHUB_ACTIONS_SA_USER }} IMAGE_REGISTRY_PASSWORD: ${{ secrets.C5839F_OPENSHIFT_GITHUB_ACTIONS_SA_TOKEN }} IMAGE_NAME: mspdirect-backend @@ -14,18 +15,18 @@ on: # API build config. # -------------------------------------------------------------------------- - # workflow_dispatch: - # inputs: - # branch: - # description: 'Enter branch name:' - # required: true - # default: main - push: branches: [ main ] paths: - "backend/**" + workflow_dispatch: + # inputs: + # branch: + # description: 'Enter branch name:' + # required: true + # default: main + jobs: buildAndPush: @@ -57,13 +58,23 @@ jobs: dockerfiles: | ./backend/Dockerfile - - name: Push to registry - id: push-image + - name: Push to tools registry + id: push-image-tools + uses: redhat-actions/push-to-registry@v2 + with: + image: ${{ steps.build-docker.outputs.image }} + tags: ${{ steps.build-docker.outputs.tags }} + registry: ${{ env.TOOLSNS_IMAGE_REGISTRY }} + username: ${{ env.IMAGE_REGISTRY_USER }} + password: ${{ env.IMAGE_REGISTRY_PASSWORD }} + + - name: Push to test registry + id: push-image-test uses: redhat-actions/push-to-registry@v2 with: image: ${{ steps.build-docker.outputs.image }} tags: ${{ steps.build-docker.outputs.tags }} - registry: ${{ env.IMAGE_REGISTRY }} + registry: ${{ env.TESTNS_IMAGE_REGISTRY }} username: ${{ env.IMAGE_REGISTRY_USER }} password: ${{ env.IMAGE_REGISTRY_PASSWORD }} @@ -91,7 +102,7 @@ jobs: if: ${{ success() }} run: | cd mspdirect-devops/overlays/test - kustomize edit set image "backend-image=image-registry.openshift-image-registry.svc:5000/c5839f-tools/${{ env.IMAGE_NAME }}@${{ steps.push-image.outputs.digest }}" + kustomize edit set image "backend-image=image-registry.openshift-image-registry.svc:5000/c5839f-test/${{ env.IMAGE_NAME }}@${{ steps.push-image-test.outputs.digest }}" git config --local user.email "action@github.com" git config --local user.name "GitHub Action" git commit -am "Update Backend API image ID for test" diff --git a/.github/workflows/TestEnv-frontend-BuildImageAndPush.yml b/.github/workflows/TestEnv-frontend-BuildImageAndPush.yml index 08b2ebc4..53b901ef 100644 --- a/.github/workflows/TestEnv-frontend-BuildImageAndPush.yml +++ b/.github/workflows/TestEnv-frontend-BuildImageAndPush.yml @@ -2,7 +2,8 @@ name: TestEnv-frontend-BuildImageAndPush # Build the image and deploy in OpenShift environment env: # Registries such as GHCR, Quay.io, and Docker Hub are supported. - IMAGE_REGISTRY: image-registry.apps.silver.devops.gov.bc.ca/c5839f-tools + TOOLSNS_IMAGE_REGISTRY: image-registry.apps.silver.devops.gov.bc.ca/c5839f-tools + TESTNS_IMAGE_REGISTRY: image-registry.apps.silver.devops.gov.bc.ca/c5839f-test IMAGE_REGISTRY_USER: ${{ secrets.C5839F_OPENSHIFT_GITHUB_ACTIONS_SA_USER }} IMAGE_REGISTRY_PASSWORD: ${{ secrets.C5839F_OPENSHIFT_GITHUB_ACTIONS_SA_TOKEN }} IMAGE_NAME: mspdirect-frontend @@ -13,6 +14,8 @@ on: branches: [ main ] paths: - "frontend/**" + + workflow_dispatch: jobs: @@ -46,13 +49,23 @@ jobs: dockerfiles: | ./frontend/Dockerfile - - name: Push to registry - id: push-image + - name: Push to tools registry + id: push-image-tools + uses: redhat-actions/push-to-registry@v2 + with: + image: ${{ steps.build-docker.outputs.image }} + tags: ${{ steps.build-docker.outputs.tags }} + registry: ${{ env.TOOLSNS_IMAGE_REGISTRY }} + username: ${{ env.IMAGE_REGISTRY_USER }} + password: ${{ env.IMAGE_REGISTRY_PASSWORD }} + + - name: Push to test registry + id: push-image-test uses: redhat-actions/push-to-registry@v2 with: image: ${{ steps.build-docker.outputs.image }} tags: ${{ steps.build-docker.outputs.tags }} - registry: ${{ env.IMAGE_REGISTRY }} + registry: ${{ env.TESTNS_IMAGE_REGISTRY }} username: ${{ env.IMAGE_REGISTRY_USER }} password: ${{ env.IMAGE_REGISTRY_PASSWORD }} @@ -80,7 +93,7 @@ jobs: if: ${{ success() }} run: | cd mspdirect-devops/overlays/test - kustomize edit set image "frontend-image=image-registry.openshift-image-registry.svc:5000/c5839f-tools/${{ env.IMAGE_NAME }}@${{ steps.push-image.outputs.digest }}" + kustomize edit set image "frontend-image=image-registry.openshift-image-registry.svc:5000/c5839f-test/${{ env.IMAGE_NAME }}@${{ steps.push-image-test.outputs.digest }}" git config --local user.email "action@github.com" git config --local user.name "GitHub Action" git commit -am "Update frontend API image ID for Test" diff --git a/.github/workflows/backend-openshift.yml b/.github/workflows/backend-openshift.yml deleted file mode 100644 index 9d8092db..00000000 --- a/.github/workflows/backend-openshift.yml +++ /dev/null @@ -1,203 +0,0 @@ -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. - -# ๐Ÿ’ The OpenShift Starter workflow will: -# - Checkout your repository -# - Perform a container image build -# - Push the built image to the GitHub Container Registry (GHCR) -# - Log in to your OpenShift cluster -# - Create an OpenShift app from the image and expose it to the internet - -# โ„น๏ธ Configure your repository and the workflow with the following steps: -# 1. Have access to an OpenShift cluster. Refer to https://www.openshift.com/try -# 2. Create the OPENSHIFT_SERVER and OPENSHIFT_TOKEN repository secrets. Refer to: -# - https://github.com/redhat-actions/oc-login#readme -# - https://docs.github.com/en/actions/reference/encrypted-secrets -# - https://cli.github.com/manual/gh_secret_set -# 3. (Optional) Edit the top-level 'env' section as marked with '๐Ÿ–Š๏ธ' if the defaults are not suitable for your project. -# 4. (Optional) Edit the build-image step to build your project. -# The default build type is by using a Dockerfile at the root of the repository, -# but can be replaced with a different file, a source-to-image build, or a step-by-step buildah build. -# 5. Commit and push the workflow file to your default branch to trigger a workflow run. - -# ๐Ÿ‘‹ Visit our GitHub organization at https://github.com/redhat-actions/ to see our actions and provide feedback. - -name: backend-openshift - -env: - # ๐Ÿ–Š๏ธ EDIT your repository secrets to log into your OpenShift cluster and set up the context. - # See https://github.com/redhat-actions/oc-login#readme for how to retrieve these values. - # To get a permanent token, refer to https://github.com/redhat-actions/oc-login/wiki/Using-a-Service-Account-for-GitHub-Actions - OPENSHIFT_SERVER: ${{ secrets.C5839F_OPENSHIFT_SERVER }} - OPENSHIFT_TOKEN: ${{ secrets.C5839F_OPENSHIFT_GITHUB_ACTIONS_SA_TOKEN }} - # ๐Ÿ–Š๏ธ EDIT to set the kube context's namespace after login. Leave blank to use your user's default namespace. - OPENSHIFT_NAMESPACE: "c5839f-dev" - - # ๐Ÿ–Š๏ธ EDIT to set a name for your OpenShift app, or a default one will be generated below. - APP_NAME: "hnweb-backend-manual" - - # ๐Ÿ–Š๏ธ EDIT with the port your application should be accessible on. - # If the container image exposes *exactly one* port, this can be left blank. - # Refer to the 'port' input of https://github.com/redhat-actions/oc-new-app - APP_PORT: "9090" - - # ๐Ÿ–Š๏ธ EDIT to change the image registry settings. - # Registries such as GHCR, Quay.io, and Docker Hub are supported. - IMAGE_REGISTRY: image-registry.apps.silver.devops.gov.bc.ca/c5839f-tools - IMAGE_REGISTRY_USER: ${{ secrets.C5839F_OPENSHIFT_GITHUB_ACTIONS_SA_USER }} - IMAGE_REGISTRY_PASSWORD: ${{ secrets.C5839F_OPENSHIFT_GITHUB_ACTIONS_SA_TOKEN }} - - # ๐Ÿ–Š๏ธ EDIT to specify custom tags for the container image, or default tags will be generated below. - IMAGE_TAGS: "openshift-workflow" - -on: - # Run the workflow manually, instead of on a push. - # The user specifies the name of the build config to use, which should be an - # API build config. - # -------------------------------------------------------------------------- - workflow_dispatch: - inputs: - branch: - description: 'Enter branch name:' - required: true - default: main - # https://docs.github.com/en/actions/reference/events-that-trigger-workflows - - # push: - # # Edit to the branch(es) you want to build and deploy on each push. - # branches: [ main, 4969-setup-hnweb ] - # paths: - # - "backend/**" - -jobs: - openshift-ci-cd: - name: Build and deploy to OpenShift - # ubuntu-20.04 can also be used. - runs-on: ubuntu-18.04 - #environment: production - - outputs: - ROUTE: ${{ steps.deploy-and-expose.outputs.route }} - SELECTOR: ${{ steps.deploy-and-expose.outputs.selector }} - - steps: - - name: Check for required secrets - uses: actions/github-script@v4 - with: - script: | - const secrets = { - OPENSHIFT_SERVER: `${{ env.OPENSHIFT_SERVER }}`, - OPENSHIFT_TOKEN: `${{ env.OPENSHIFT_TOKEN }}`, - }; - - const GHCR = "ghcr.io"; - if (`${{ env.IMAGE_REGISTRY }}`.startsWith(GHCR)) { - core.info(`Image registry is ${GHCR} - no registry password required`); - } - else { - core.info("A registry password is required"); - secrets["IMAGE_REGISTRY_PASSWORD"] = `${{ secrets.C5839F_OPENSHIFT_GITHUB_ACTIONS_SA_TOKEN }}`; - } - - const missingSecrets = Object.entries(secrets).filter(([ name, value ]) => { - if (value.length === 0) { - core.error(`Secret "${name}" is not set`); - return true; - } - core.info(`โœ”๏ธ Secret "${name}" is set`); - return false; - }); - - if (missingSecrets.length > 0) { - core.setFailed(`โŒ At least one required secret is not set in the repository. \n` + - "You can add it using:\n" + - "GitHub UI: https://docs.github.com/en/actions/reference/encrypted-secrets#creating-encrypted-secrets-for-a-repository \n" + - "GitHub CLI: https://cli.github.com/manual/gh_secret_set \n" + - "Also, refer to https://github.com/redhat-actions/oc-login#getting-started-with-the-action-or-see-example"); - } - else { - core.info(`โœ… All the required secrets are set`); - } - - - name: Check out repository - uses: actions/checkout@v2 - with: - ref: ${{ github.event.inputs.branch }} - - - name: Determine app name - if: env.APP_NAME == '' - run: | - echo "APP_NAME=$(basename $PWD)" | tee -a $GITHUB_ENV - - - name: Determine image tags - if: env.IMAGE_TAGS == '' - run: | - echo "IMAGE_TAGS=latest ${GITHUB_SHA::12}" | tee -a $GITHUB_ENV - - # https://github.com/redhat-actions/buildah-build#readme - - name: Build from Dockerfile - id: build-image - uses: redhat-actions/buildah-build@v2 - with: - image: ${{ env.APP_NAME }} - tags: ${{ env.IMAGE_TAGS }} - context: ./backend - #build-args: env=test - # If you don't have a Dockerfile/Containerfile, refer to https://github.com/redhat-actions/buildah-build#scratch-build-inputs - # Or, perform a source-to-image build using https://github.com/redhat-actions/s2i-build - # Otherwise, point this to your Dockerfile/Containerfile relative to the repository root. - dockerfiles: | - ./backend/Dockerfile - - # https://github.com/redhat-actions/push-to-registry#readme - - name: Push to registry - id: push-image - uses: redhat-actions/push-to-registry@v2 - with: - image: ${{ steps.build-image.outputs.image }} - tags: ${{ steps.build-image.outputs.tags }} - registry: ${{ env.IMAGE_REGISTRY }} - username: ${{ env.IMAGE_REGISTRY_USER }} - password: ${{ env.IMAGE_REGISTRY_PASSWORD }} - - # The path the image was pushed to is now stored in ${{ steps.push-image.outputs.registry-path }} - - - name: Install oc - uses: redhat-actions/openshift-tools-installer@v1 - with: - oc: 4 - - # https://github.com/redhat-actions/oc-login#readme - - name: Log in to OpenShift - uses: redhat-actions/oc-login@v1 - with: - openshift_server_url: ${{ env.OPENSHIFT_SERVER }} - openshift_token: ${{ env.OPENSHIFT_TOKEN }} - insecure_skip_tls_verify: true - namespace: ${{ env.OPENSHIFT_NAMESPACE }} - - # This step should create a deployment, service, and route to run your app and expose it to the internet. - # https://github.com/redhat-actions/oc-new-app#readme - - name: Create and expose app - id: deploy-and-expose - uses: redhat-actions/oc-new-app@v1 - with: - app_name: ${{ env.APP_NAME }} - image: ${{ steps.push-image.outputs.registry-path }} - namespace: ${{ env.OPENSHIFT_NAMESPACE }} - port: ${{ env.APP_PORT }} - - - name: Print application URL - env: - ROUTE: ${{ steps.deploy-and-expose.outputs.route }} - SELECTOR: ${{ steps.deploy-and-expose.outputs.selector }} - run: | - [[ -n ${{ env.ROUTE }} ]] || (echo "Determining application route failed in previous step"; exit 1) - echo - echo "======================== Your application is available at: ========================" - echo ${{ env.ROUTE }} - echo "===================================================================================" - echo - echo "Your app can be taken down with: \"oc delete all --selector='${{ env.SELECTOR }}'\"" \ No newline at end of file diff --git a/.github/workflows/deploy-mspdirect.yml b/.github/workflows/deploy-mspdirect.yml index 542d80c7..5141eaa2 100644 --- a/.github/workflows/deploy-mspdirect.yml +++ b/.github/workflows/deploy-mspdirect.yml @@ -1,36 +1,139 @@ -# This is a basic workflow to help you get started with Actions +# This is a deployment workflow to deploy a selected release in selected environment +# Steps are: +# 1. Login to OpenShift +# 2. Find the image digest from input parameters +# 3. Validate if that is correct. If not, exit the job +# 4. Push the image to selected repository +# 5. Edit the selcted Argo CD manifest file + + name: deploy-mspdirect +env: + OPENSHIFT_SERVER: ${{ secrets.C5839F_OPENSHIFT_SERVER }} + OPENSHIFT_TOKEN: ${{ secrets.C5839F_OPENSHIFT_GITHUB_ACTIONS_SA_TOKEN }} + FRONTEND_IMAGE_NAME: mspdirect-frontend + BACKEND_IMAGE_NAME: mspdirect-backend + DEFAULT_NAMESPACE: "c5839f-tools" + VERSION_PREFIX: "Release_1.0_" + OPENSHIFT_NAMESPACE: + FRONTEND_IMAGE_ID: + BACKEND_IMAGE_ID: + + + + # Controls when the workflow will run on: - # Triggers the workflow on push or pull request events but only for the main branch - push: - branches: [ main ] - pull_request: - branches: [ main ] - # Allows you to run this workflow manually from the Actions tab workflow_dispatch: + inputs: + Environment: + type: choice + description: Select an environment to deploy + options: + - dev + - test + Branch: + description: 'Enter branch name (Currently deployable releases are created only from main )' + required: true + default: main + Release: + description: 'Enter build number: ' + required: true + default: 1 + # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: - # This workflow contains a single job called "build" - build: + deploy: # The type of runner that the job will run on runs-on: ubuntu-latest + # Steps represent a sequence of tasks that will be executed as part of the job steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v2 - # Runs a single command using the runners shell - - name: Run a one-line script - run: echo Hello, world! + # 1. Login to OpenShift + - name: Log in to OpenShift + uses: redhat-actions/oc-login@v1 + with: + openshift_server_url: ${{ env.OPENSHIFT_SERVER }} + openshift_token: ${{ env.OPENSHIFT_TOKEN }} + insecure_skip_tls_verify: true + namespace: ${{ env.DEFAULT_NAMESPACE }} + # 2. Find the namespace and image digest from input parameters + - name: Compute namespace + id: set-namespace + uses: actions/github-script@v5 + with: + script: | + if (`${{ github.event.inputs.Environment }}` == 'dev') { + return "c5839f-dev" + } + if (`${{ github.event.inputs.Environment }}` == 'test' || `${{ github.event.inputs.Environment }}` == 'uat') { + return "c5839f-test" + } + + - name: Compute Version image + run: | + echo "OPENSHIFT_NAMESPACE=${{steps.set-namespace.outputs.result}}" | tee -a $GITHUB_ENV + echo "VERSION=${{ env.VERSION_PREFIX }}${{ github.event.inputs.Branch }}_${{ github.event.inputs.Release }}" | tee -a $GITHUB_ENV + + - name: Find image + run: | + oc project + echo "FRONTEND_IMAGE_ID=$(oc get istag/${{ env.FRONTEND_IMAGE_NAME }}:${{ env.VERSION }} -o jsonpath={.image.metadata.name})" | tee -a $GITHUB_ENV + echo "BACKEND_IMAGE_ID=$(oc get istag/${{ env.BACKEND_IMAGE_NAME }}:${{ env.VERSION }} -o jsonpath={.image.metadata.name})" | tee -a $GITHUB_ENV + + # 3. Validate if that is correct. If not, exit the job + - name: Validate image + uses: actions/github-script@v4 + with: + script: | + if (`${{ env.FRONTEND_IMAGE_ID }}`.length == 0 || `${{ env.BACKEND_IMAGE_ID }}`.length == 0) { + core.setFailed(`โŒ Image version: ${{ env.VERSION }}. \n` + + "Please provide a valid image build number." ); + } + else { + core.info(`โœ… Valid image found.`); + } + # 4. Push the image to selected repository + - name: Push Image + run: | + oc tag ${{ env.FRONTEND_IMAGE_NAME }}:${{ env.VERSION }} ${{ env.OPENSHIFT_NAMESPACE }}/${{ env.FRONTEND_IMAGE_NAME }}:${{ env.VERSION }} + oc tag ${{ env.BACKEND_IMAGE_NAME }}:${{ env.VERSION }} ${{ env.OPENSHIFT_NAMESPACE }}/${{ env.BACKEND_IMAGE_NAME }}:${{ env.VERSION }} + + # 5. Edit the selcted Argo CD manifest file + # Update the image ID in the manifest repository used by Argo CD. + # We need to use the SSH deploy key to check out the manifest repo, set up + # Kustomize in the runner, update the image ID, commit the change, and + # push the changes back to the manifest repository. + # ------------------------------------------------------------------------ + - name: Prepare deploy key + uses: webfactory/ssh-agent@v0.5.3 + with: + ssh-private-key: ${{ secrets.GITOPS_C5839F_PRIVATE_KEY }} + + - name: Check out manifest repo + uses: actions/checkout@v2 + with: + ssh-key: ${{ secrets.GITOPS_C5839F_PRIVATE_KEY }} + repository: ${{ secrets.GITOPS_C5839F_REPO }} + ref: main + + - name: Set up Kustomize + uses: imranismail/setup-kustomize@v1 - # Runs a set of commands using the runners shell - - name: Run a multi-line script + - name: Update image ID and commit change + if: ${{ success() }} run: | - echo Add other actions to build, - echo test, and deploy your project. + cd mspdirect-devops/overlays/${{ github.event.inputs.Environment }} + kustomize edit set image "backend-image=image-registry.openshift-image-registry.svc:5000/${{ env.OPENSHIFT_NAMESPACE }}/${{ env.BACKEND_IMAGE_NAME }}@${{ env.BACKEND_IMAGE_ID }}" + kustomize edit set image "frontend-image=image-registry.openshift-image-registry.svc:5000/${{ env.OPENSHIFT_NAMESPACE }}/${{ env.FRONTEND_IMAGE_NAME }}@${{ env.FRONTEND_IMAGE_ID }}" + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + git commit -am "Update frontend and backend image ids using deploy workflow." + git push origin + \ No newline at end of file diff --git a/.github/workflows/mspdirect-release-draft.yml b/.github/workflows/mspdirect-release-draft.yml deleted file mode 100644 index 20420570..00000000 --- a/.github/workflows/mspdirect-release-draft.yml +++ /dev/null @@ -1,123 +0,0 @@ -# This is a manual workflow that performs following activities: -# 1. Determine the version number tag i.e. Release_1.0__ -# 2. Edit .env in frontend with the value -# 3. Creates images for frontend and backend code -# 4. Tags the images with release number -# 5. Tags the images with additional tags if any -# 6. Upload the images in image repository in tools namespace - -name: mspdirect-release-draft -# Build the image and deploy in OpenShift environment -env: - # Registries such as GHCR, Quay.io, and Docker Hub are supported. - IMAGE_REGISTRY: image-registry.apps.silver.devops.gov.bc.ca/c5839f-tools - IMAGE_REGISTRY_USER: ${{ secrets.C5839F_OPENSHIFT_GITHUB_ACTIONS_SA_USER }} - IMAGE_REGISTRY_PASSWORD: ${{ secrets.C5839F_OPENSHIFT_GITHUB_ACTIONS_SA_TOKEN }} - IMAGE_NAME_BACKEND: mspdirect-backend - IMAGE_NAME_FRONTEND: mspdirect-frontend - IMAGE_TAGS: - - -on: - # Run the workflow manually, instead of on a push. - # The user specifies the optional tag - # -------------------------------------------------------------------------- - - workflow_dispatch: - inputs: - OPTIONAL_TAG: - description: 'Enter any optional tag name, For example Sprint-20' - required: false - default: - - #push: - # branches: [ main ] - # paths: - # - "backend/**" - -jobs: - - createMSPDirectRelease: - runs-on: ubuntu-latest - - steps: - # Check out the code - - name: Check out code - id: checkout - uses: actions/checkout@v2 - with: - ref: main - - # 1. Determine the version number tag i.e. Release_1.0__ - - name: Determine image tags - if: env.IMAGE_TAGS == '' - # Branch name is fixed to 'main' in version identifier - run: | - echo "RELEASE_VERSION= Release_1.0_main_${{github.run_number}} " | tee -a $GITHUB_ENV - echo "IMAGE_TAGS= ${GITHUB_SHA::12} ${{env.RELEASE_VERSION}} ${{ github.event.inputs.OPTIONAL_TAG }} " | tee -a $GITHUB_ENV - echo "Final tags are ${{env.IMAGE_TAGS}}" - echo "Final Release version is ${{env.RELEASE_VERSION}}" - - # 2. Edit .env in frontend with the value - - name: Edit env file to add version - # - run: | - echo "Current path is" - pwd - cd ./moh-hnweb/frontend/env_config - sed -i 's/[VER]]/${{env.RELEASE_VERSION}}/' .env.dev - echo "RELEASE_VERSION= Release_1.0_main_${{github.run_number}} " | tee -a $GITHUB_ENV - echo "IMAGE_TAGS= ${GITHUB_SHA::12} ${{env.RELEASE_VERSION}} ${{ github.event.inputs.OPTIONAL_TAG }} " | tee -a $GITHUB_ENV - echo "Final tags are ${{env.IMAGE_TAGS}}" - - - # # Build from docker file - # - name: Build from Dockerfile - # id: build-docker - # uses: redhat-actions/buildah-build@v2 - # with: - # image: ${{ env.IMAGE_NAME }} - # tags: ${{ env.IMAGE_TAGS }} - # context: ./backend - # dockerfiles: | - # ./backend/Dockerfile - - # - name: Push to registry - # id: push-image - # uses: redhat-actions/push-to-registry@v2 - # with: - # image: ${{ steps.build-docker.outputs.image }} - # tags: ${{ steps.build-docker.outputs.tags }} - # registry: ${{ env.IMAGE_REGISTRY }} - # username: ${{ env.IMAGE_REGISTRY_USER }} - # password: ${{ env.IMAGE_REGISTRY_PASSWORD }} - - # # Update the image ID in the manifest repository used by Argo CD. - # # We need to use the SSH deploy key to check out the manifest repo, set up - # # Kustomize in the runner, update the image ID, commit the change, and - # # push the changes back to the manifest repository. - # # ------------------------------------------------------------------------ - # - name: Prepare deploy key - # uses: webfactory/ssh-agent@v0.5.3 - # with: - # ssh-private-key: ${{ secrets.GITOPS_C5839F_PRIVATE_KEY }} - - # - name: Check out manifest repo - # uses: actions/checkout@v2 - # with: - # ssh-key: ${{ secrets.GITOPS_C5839F_PRIVATE_KEY }} - # repository: ${{ secrets.GITOPS_C5839F_REPO }} - # ref: main - - # - name: Set up Kustomize - # uses: imranismail/setup-kustomize@v1 - - # - name: Update image ID and commit change - # if: ${{ success() }} - # run: | - # cd mspdirect-devops/overlays/test - # kustomize edit set image "backend-image=image-registry.openshift-image-registry.svc:5000/c5839f-tools/${{ env.IMAGE_NAME }}@${{ steps.push-image.outputs.digest }}" - # git config --local user.email "action@github.com" - # git config --local user.name "GitHub Action" - # git commit -am "Update Backend API image ID for test" - # git push origin \ No newline at end of file diff --git a/.github/workflows/release-mspdirect.yml b/.github/workflows/release-mspdirect.yml index d8cccb36..15c56df6 100644 --- a/.github/workflows/release-mspdirect.yml +++ b/.github/workflows/release-mspdirect.yml @@ -1,31 +1,182 @@ -# This is a basic workflow to help you get started with Actions +# This is a manual workflow that performs following activities: +# 1. Determine the version number tag i.e. Release_1.0__ +# 2. Determine tags for OpenShift image +# 3. Edit .env in frontend with the value +# 3. Creates images for frontend and backend code +# 4. Tags the images with release number +# 5. Tags the images with additional tags if any +# 6. Upload the images in image repository in tools namespace +# 7. Tag the commit in Git with release number +# 8. Deploy the release in test environment -name: CI -# Controls when the workflow will run -on: +name: release-mspdirect +# Build the image and deploy in OpenShift environment +env: + # Registries such as GHCR, Quay.io, and Docker Hub are supported. + TESTNS_IMAGE_REGISTRY: image-registry.apps.silver.devops.gov.bc.ca/c5839f-test + IMAGE_REGISTRY: image-registry.apps.silver.devops.gov.bc.ca/c5839f-tools + IMAGE_REGISTRY_USER: ${{ secrets.C5839F_OPENSHIFT_GITHUB_ACTIONS_SA_USER }} + IMAGE_REGISTRY_PASSWORD: ${{ secrets.C5839F_OPENSHIFT_GITHUB_ACTIONS_SA_TOKEN }} + IMAGE_NAME_BACKEND: mspdirect-backend + IMAGE_NAME_FRONTEND: mspdirect-frontend + IMAGE_TAGS: + RELEASE_VERSION: + - # Allows you to run this workflow manually from the Actions tab +on: + # Run the workflow manually, instead of on a push. + # The user specifies the optional tag + # -------------------------------------------------------------------------- + workflow_dispatch: + inputs: + OPENSHIFT_IMAGE_TAG: + description: 'Optional parameter for additional tags on released images. ' + required: false + default: + -# A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: - # This workflow contains a single job called "build" - build: - # The type of runner that the job will run on - runs-on: ubuntu-latest - # Steps represent a sequence of tasks that will be executed as part of the job + createMSPDirectRelease: + runs-on: ubuntu-latest + steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v2 - - # Runs a single command using the runners shell - - name: Run a one-line script - run: echo Hello, world! - - # Runs a set of commands using the runners shell - - name: Run a multi-line script - run: | - echo Add other actions to build, - echo test, and deploy your project. + # Check out the code + - name: Check out code + id: checkout + uses: actions/checkout@v2 + with: + ref: main + + # 1. Determine the version number tag i.e. Release_1.0__ + - name: Determine Version number + # Branch name is fixed to 'main' in version identifier + run: | + echo "RELEASE_VERSION=Release_1.0_main_${{github.run_number}}" | tee -a $GITHUB_ENV + + # 2. Determine tags for OpenShift image + - name: Determine image tags + run: | + echo "IMAGE_TAGS= ${GITHUB_SHA::12} ${{ env.RELEASE_VERSION }} ${{ github.event.inputs.OPENSHIFT_IMAGE_TAG }} " | tee -a $GITHUB_ENV + + + # 3. Edit .env in frontend with the value + - name: Edit env file to add version + run: | + cd ./frontend/env_config + sed -i 's//${{ env.RELEASE_VERSION }}/' .env + +# 3. Creates images for frontend and backend code +# 4. Tags the images with release number +# 5. Tags the images with additional tags if any + # Build frontend from docker file + - name: Build frontend from Dockerfile + id: build-docker-frontend + uses: redhat-actions/buildah-build@v2 + with: + image: ${{ env.IMAGE_NAME_FRONTEND }} + tags: ${{ env.IMAGE_TAGS }} + context: ./frontend + dockerfiles: | + ./frontend/Dockerfile + + # Build backend from docker file + - name: Build backend from Dockerfile + id: build-docker-backend + uses: redhat-actions/buildah-build@v2 + with: + image: ${{ env.IMAGE_NAME_BACKEND }} + tags: ${{ env.IMAGE_TAGS }} + context: ./backend + dockerfiles: | + ./backend/Dockerfile + +# 6. Upload the images in image repository in tools namespace + - name: Push frontend image to registry + id: push-image-frontend + uses: redhat-actions/push-to-registry@v2 + with: + image: ${{ steps.build-docker-frontend.outputs.image }} + tags: ${{ steps.build-docker-frontend.outputs.tags }} + registry: ${{ env.IMAGE_REGISTRY }} + username: ${{ env.IMAGE_REGISTRY_USER }} + password: ${{ env.IMAGE_REGISTRY_PASSWORD }} + + - name: Push backend image to registry + id: push-image-backend + uses: redhat-actions/push-to-registry@v2 + with: + image: ${{ steps.build-docker-backend.outputs.image }} + tags: ${{ steps.build-docker-backend.outputs.tags }} + registry: ${{ env.IMAGE_REGISTRY }} + username: ${{ env.IMAGE_REGISTRY_USER }} + password: ${{ env.IMAGE_REGISTRY_PASSWORD }} + +# 7. Tag the commit in Git with release number and Optional tags + - name: Tag the commit with Release number + id: tag + uses: actions-ecosystem/action-push-tag@v1 + with: + tag: v${{ env.RELEASE_VERSION }} + message: 'Tag generated by GitHub Actions process.' + +#************************************************************************************** +#************************************************************************************** +# Getting an error when doing 2 checkout actions in same job +# Commented the code for next story, to include deploy to test as default in release job +#************************************************************************************** +#************************************************************************************** + +# 8. Deploy the release in test environment + # - name: Push frontend image to test registry + # id: push-image-frontend-test + # uses: redhat-actions/push-to-registry@v2 + # with: + # image: ${{ steps.build-docker-frontend.outputs.image }} + # tags: ${{ steps.build-docker-frontend.outputs.tags }} + # registry: ${{ env.TESTNS_IMAGE_REGISTRY }} + # username: ${{ env.IMAGE_REGISTRY_USER }} + # password: ${{ env.IMAGE_REGISTRY_PASSWORD }} + + # - name: Push backend image to registry + # id: push-image-backend-test + # uses: redhat-actions/push-to-registry@v2 + # with: + # image: ${{ steps.build-docker-backend.outputs.image }} + # tags: ${{ steps.build-docker-backend.outputs.tags }} + # registry: ${{ env.TESTNS_IMAGE_REGISTRY }} + # username: ${{ env.IMAGE_REGISTRY_USER }} + # password: ${{ env.IMAGE_REGISTRY_PASSWORD }} + + # # Update the image ID in the manifest repository used by Argo CD. + # # We need to use the SSH deploy key to check out the manifest repo, set up + # # Kustomize in the runner, update the image ID, commit the change, and + # # push the changes back to the manifest repository. + # # ------------------------------------------------------------------------ + # - name: Prepare deploy key + # uses: webfactory/ssh-agent@v0.5.3 + # with: + # ssh-private-key: ${{ secrets.GITOPS_C5839F_PRIVATE_KEY }} + + # - name: Check out manifest repo + # uses: actions/checkout@v2 + # with: + # ssh-key: ${{ secrets.GITOPS_C5839F_PRIVATE_KEY }} + # repository: ${{ secrets.GITOPS_C5839F_REPO }} + # ref: main + + # - name: Set up Kustomize + # uses: imranismail/setup-kustomize@v1 + + # - name: Update image ID and commit change + # if: ${{ success() }} + # run: | + # cd mspdirect-devops/overlays/test + # kustomize edit set image "backend-image=image-registry.openshift-image-registry.svc:5000/c5839f-test/${{ env.IMAGE_NAME }}@${{ steps.push-image-backend-test.outputs.digest }}" + # kustomize edit set image "frontend-image=image-registry.openshift-image-registry.svc:5000/c5839f-test/${{ env.IMAGE_NAME }}@${{ steps.push-image-frontend-test.outputs.digest }}" + # git config --local user.email "action@github.com" + # git config --local user.name "GitHub Action" + # git commit -am "release-mpsdirect workflow deploying release build in test environment." + # git push origin \ No newline at end of file diff --git a/.github/workflows/frontend-openshift.yml b/.github/workflows/sample-workflow.yml similarity index 99% rename from .github/workflows/frontend-openshift.yml rename to .github/workflows/sample-workflow.yml index 4cd51c5f..1ad17f1d 100644 --- a/.github/workflows/frontend-openshift.yml +++ b/.github/workflows/sample-workflow.yml @@ -24,7 +24,7 @@ # ๐Ÿ‘‹ Visit our GitHub organization at https://github.com/redhat-actions/ to see our actions and provide feedback. -name: frontend-openshift +name: sample-workflow env: # ๐Ÿ–Š๏ธ EDIT your repository secrets to log into your OpenShift cluster and set up the context. diff --git a/frontend/env_config/.env b/frontend/env_config/.env index 8f742d98..cd1ddc84 100644 --- a/frontend/env_config/.env +++ b/frontend/env_config/.env @@ -1,3 +1,4 @@ VITE_APP_TITLE=HN Web VITE_KEYCLOAK_CLIENT_ID=MSPDIRECT-WEB -VITE_KEYCLOAK_REALM=moh_applications \ No newline at end of file +VITE_KEYCLOAK_REALM=moh_applications +VITE_APP_VERSION= \ No newline at end of file diff --git a/frontend/env_config/.env.dev b/frontend/env_config/.env.dev index 179eb5dd..2683da81 100644 --- a/frontend/env_config/.env.dev +++ b/frontend/env_config/.env.dev @@ -1,5 +1,5 @@ # Environment configurations for OpenShift dev environment -VITE_APP_TITLE=HN Web (Dev) - [VER] +VITE_APP_TITLE=HN Web (Dev) VITE_KEYCLOAK_URL=https://common-logon-dev.hlth.gov.bc.ca/auth/ VITE_SITEMINDER_LOGOUT=https://logontest7.gov.bc.ca/clp-cgi/logoff.cgi?retnow=1&returl=https://mspdirect-dev.apps.silver.devops.gov.bc.ca VITE_SERVICE_URL=https://mspdirect-dev-api.apps.silver.devops.gov.bc.ca/ \ No newline at end of file diff --git a/frontend/src/components/template/TheFooter.vue b/frontend/src/components/template/TheFooter.vue index a5058fdb..c6d8e04c 100644 --- a/frontend/src/components/template/TheFooter.vue +++ b/frontend/src/components/template/TheFooter.vue @@ -1,34 +1,42 @@ \ No newline at end of file +