Build Web image and push to prod #3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: WEB CD | |
| run-name: Build Web image and push to ${{ github.event.inputs.environment || 'dev' }} | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - "web/**" | |
| workflow_dispatch: | |
| inputs: | |
| environment: | |
| description: "Environment" | |
| required: true | |
| default: "dev" | |
| type: choice | |
| options: | |
| - dev | |
| - test | |
| - prod | |
| defaults: | |
| run: | |
| shell: bash | |
| working-directory: ./web | |
| env: | |
| APP_NAME: "engagement-web" | |
| TAG_NAME: "${{ github.event.inputs.environment || 'dev' }}" # If the environment type is manually selected, use the input value; otherwise, use 'dev' as default | |
| OPENSHIFT_LOGIN_REGISTRY: ${{ secrets.OPENSHIFT_LOGIN_REGISTRY }} | |
| OPENSHIFT_SA_TOKEN: ${{ secrets.OPENSHIFT_SA_TOKEN }} | |
| OPENSHIFT_SA_NAME: ${{ secrets.OPENSHIFT_SA_NAME }} | |
| OPENSHIFT_IMAGE_REGISTRY: ${{ secrets.OPENSHIFT_IMAGE_REGISTRY }} | |
| OPENSHIFT_REPOSITORY: ${{ secrets.OPENSHIFT_REPOSITORY }} | |
| ARTIFACTORY_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }} | |
| ARTIFACTORY_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }} | |
| jobs: | |
| web-cd: | |
| runs-on: ubuntu-24.04 | |
| if: github.repository == 'bcgov/met-public' | |
| environment: ${{github.event.inputs.environment || 'dev' }} | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Install Openshift Tooling | |
| uses: redhat-actions/openshift-tools-installer@v1.13.1 | |
| with: | |
| oc: "4.16" | |
| - name: Login Openshift | |
| shell: bash | |
| run: | | |
| oc login --server=${OPENSHIFT_LOGIN_REGISTRY} --token=${OPENSHIFT_SA_TOKEN} | |
| - name: Login Docker | |
| run: | | |
| echo "${OPENSHIFT_SA_TOKEN}" | | |
| docker login ${OPENSHIFT_IMAGE_REGISTRY} -u ${OPENSHIFT_SA_NAME} --password-stdin | |
| - name: Create Artifactory secret files | |
| run: | | |
| echo -n "${ARTIFACTORY_USERNAME}" > /tmp/artifactory_username | |
| echo -n "${ARTIFACTORY_PASSWORD}" > /tmp/artifactory_password | |
| - name: Build image | |
| env: | |
| DOCKER_BUILDKIT: 1 | |
| run: | | |
| export TZ='America/Vancouver' && | |
| docker build . --file Dockerfile \ | |
| --secret id=artifactory_username,src=/tmp/artifactory_username \ | |
| --secret id=artifactory_password,src=/tmp/artifactory_password \ | |
| --build-arg REACT_APP_BUILD_COMMIT_HASH=${{ github.sha }} \ | |
| --build-arg REACT_APP_BUILD_DATE="$(date +'%b %d, %Y @ %H:%M')" \ | |
| --build-arg REACT_APP_BUILD_BRANCH=${{ github.ref_name }} \ | |
| --build-arg REACT_APP_GITHUB_REPO="https://github.com/${{ github.repository }}" \ | |
| --tag image | |
| - name: Push image | |
| run: | | |
| IMAGE_ID=${OPENSHIFT_IMAGE_REGISTRY}/"${OPENSHIFT_REPOSITORY}-tools"/$APP_NAME | |
| docker tag image $IMAGE_ID:latest | |
| docker push $IMAGE_ID:latest | |
| docker image tag $IMAGE_ID:latest $IMAGE_ID:$TAG_NAME | |
| docker push $IMAGE_ID:$TAG_NAME | |
| - name: Rollout | |
| continue-on-error: true | |
| shell: bash | |
| run: | | |
| # Restart the deployment to apply the new image and wait for it to complete | |
| oc rollout restart deployment/${APP_NAME} -n ${OPENSHIFT_REPOSITORY}-${TAG_NAME} | |
| oc rollout status deployment/${APP_NAME} -n ${OPENSHIFT_REPOSITORY}-${TAG_NAME} -w |