From 913cbf123316e7cc5b8eebb8f7d837482932b578 Mon Sep 17 00:00:00 2001 From: jasonchung1871 <101672465+jasonchung1871@users.noreply.github.com> Date: Wed, 14 Feb 2024 09:25:08 -0800 Subject: [PATCH] manually setting build tags (#1283) * manually setting build tags trying to manually set the version tags.. to fix the openshift issue where it's trying pull the wrong image based on the sha * Update action.yaml replaced github.sha with git rev-parse HEAD to keep things consistent * Delete on-push.yaml removing on-push in case of conflicts --- .../actions/build-push-container/action.yaml | 28 ++++- .github/workflows/.deploy.yaml | 1 + .github/workflows/on-push.yaml | 115 ------------------ 3 files changed, 23 insertions(+), 121 deletions(-) delete mode 100644 .github/workflows/on-push.yaml diff --git a/.github/actions/build-push-container/action.yaml b/.github/actions/build-push-container/action.yaml index 8691a8ee9..3306d76e3 100644 --- a/.github/actions/build-push-container/action.yaml +++ b/.github/actions/build-push-container/action.yaml @@ -60,6 +60,10 @@ inputs: description: The checkout ref id required: false default: '' + pr_number: + description: Pull request number + required: false + type: string runs: using: composite @@ -73,6 +77,18 @@ runs: uses: actions/checkout@v3 if: ${{ inputs.ref == '' }} + - name: Set variables + run: | + echo "SHA=sha-$(git rev-parse --short HEAD)" >> $GITHUB_ENV + echo "IMAGE_REVISION=$(git rev-parse HEAD)" >> $GITHUB_ENV + echo "IMAGE_VERSION=main" >> $GITHUB_ENV + if [[ "${{ inputs.ref }}" != '' ]]; then + git fetch origin ${{ inputs.ref }} + echo "SHA=sha-$(git rev-parse --short HEAD)" >> $GITHUB_ENV + echo "IMAGE_REVISION=$(git rev-parse HEAD)" >> $GITHUB_ENV + echo "IMAGE_VERSION=pr-${{ inputs.pr_number }}" >> $GITHUB_ENV + fi + - name: Creates env variables env: VITE_TITLE: ${{ inputs.app_title }} @@ -132,12 +148,12 @@ runs: latest=true # Creates tags based off of branch names and semver tags tags: | - type=ref,event=branch - type=ref,event=pr - type=semver,pattern={{version}} - type=semver,pattern={{major}}.{{minor}} - type=semver,pattern={{major}} - type=sha + type=raw,value=ghcr.io/${{ env.GH_USERNAME }}/${{ inputs.image_name }}:${{ env.IMAGE_VERSION }} + type=raw,value=ghcr.io/${{ env.GH_USERNAME }}/${{ inputs.image_name }}:${{ env.SHA }} + type=raw,value=ghcr.io/${{ env.GH_USERNAME }}/${{ inputs.image_name }}:latest + labels: | + org.opencontainers.image.revision=${{ env.IMAGE_REVISION }} + org.opencontainers.image.version=${{ env.IMAGE_VERSION }} - name: Build and Push to Container Registry id: builder diff --git a/.github/workflows/.deploy.yaml b/.github/workflows/.deploy.yaml index 30004582c..1fed1c4e1 100644 --- a/.github/workflows/.deploy.yaml +++ b/.github/workflows/.deploy.yaml @@ -95,6 +95,7 @@ jobs: route_path: ${{ needs.set-vars.outputs.ROUTE_PATH }} app_contact: ${{ vars.CHEFS_CONTACT }} ref: ${{ needs.set-vars.outputs.ref }} + pr_number: ${{ github.event.inputs.pr-number }} deploy: name: Deploys to selected environment diff --git a/.github/workflows/on-push.yaml b/.github/workflows/on-push.yaml deleted file mode 100644 index 9c3004b4e..000000000 --- a/.github/workflows/on-push.yaml +++ /dev/null @@ -1,115 +0,0 @@ -name: Push - -env: - ACRONYM: chefs - -on: - push: - branches: - - main - tags: - - v*.*.* - -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true - -jobs: - build: - name: Build & Push - runs-on: ubuntu-latest - timeout-minutes: 10 - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Build & Push - uses: ./.github/actions/build-push-container - with: - context: . - image_name: ${{ vars.APP_NAME }} - github_username: ${{ github.repository_owner }} - github_token: ${{ secrets.GITHUB_TOKEN }} - app_contact: ${{ secrets.VITE_CONTACT }} - - deploy-dev: - name: Deploy to Dev - environment: - name: dev - url: https://${{ env.ACRONYM }}-dev.apps.silver.devops.gov.bc.ca/app - runs-on: ubuntu-latest - needs: build - timeout-minutes: 12 - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Deploy to Dev - uses: ./.github/actions/deploy-to-environment - with: - app_name: ${{ vars.APP_NAME }} - acronym: ${{ env.ACRONYM }} - environment: dev - job_name: master - namespace_prefix: ${{ vars.NAMESPACE_PREFIX }} - namespace_environment: dev - openshift_server: ${{ secrets.OPENSHIFT_SERVER }} - openshift_token: ${{ secrets.OPENSHIFT_TOKEN }} - server_host: ${{ vars.SERVER_HOST }} - route_path: /app - route_prefix: ${{ vars.ROUTE_PREFIX }} - - deploy-test: - name: Deploy to Test - environment: - name: test - url: https://${{ env.ACRONYM }}-test.apps.silver.devops.gov.bc.ca/app - runs-on: ubuntu-latest - needs: - - build - - deploy-dev - timeout-minutes: 12 - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Deploy to Test - uses: ./.github/actions/deploy-to-environment - with: - app_name: ${{ vars.APP_NAME }} - acronym: ${{ env.ACRONYM }} - environment: test - job_name: master - namespace_prefix: ${{ vars.NAMESPACE_PREFIX }} - namespace_environment: test - openshift_server: ${{ secrets.OPENSHIFT_SERVER }} - openshift_token: ${{ secrets.OPENSHIFT_TOKEN }} - server_host: ${{ vars.SERVER_HOST }} - route_path: /app - route_prefix: ${{ vars.ROUTE_PREFIX }} - - deploy-prod: - name: Deploy to Prod - environment: - name: prod - url: https://${{ env.ACRONYM }}.apps.silver.devops.gov.bc.ca/app - runs-on: ubuntu-latest - needs: - - build - - deploy-dev - - deploy-test - timeout-minutes: 12 - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Deploy to Prod - uses: ./.github/actions/deploy-to-environment - with: - app_name: ${{ vars.APP_NAME }} - acronym: ${{ env.ACRONYM }} - environment: prod - job_name: master - namespace_prefix: ${{ vars.NAMESPACE_PREFIX }} - namespace_environment: prod - openshift_server: ${{ secrets.OPENSHIFT_SERVER }} - openshift_token: ${{ secrets.OPENSHIFT_TOKEN }} - server_host: ${{ vars.SERVER_HOST }} - route_path: /app - route_prefix: ${{ vars.ROUTE_PREFIX }}