MET ANALYTICS API DEV CD #43
This file contains 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: MET ANALYTICS API DEV CD | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- "analytics-api/**" | |
workflow_dispatch: | |
inputs: | |
environment: | |
description: "Environment (dev/test/prod)" | |
required: true | |
default: "dev" | |
project_type: | |
description: "Project Type (EAO/GDX)" | |
required: false | |
default: "EAO" # Default value is EAO | |
defaults: | |
run: | |
shell: bash | |
working-directory: ./analytics-api | |
env: | |
APP_NAME: "analytics-api" | |
TAG_NAME: "${{github.event.inputs.environment || 'dev' }}" # If the environment type is manually selected, use the input value; otherwise, use 'dev' as default | |
PROJECT_TYPE: "${{ github.event.inputs.project_type || 'EAO' }}" # If the project type is manually selected, use the input value; otherwise, use 'EAO' as default | |
OPENSHIFT_LOGIN_REGISTRY: ${{ secrets.OPENSHIFT_LOGIN_REGISTRY }} | |
OPENSHIFT_SA_TOKEN: ${{ github.event.inputs.project_type == 'GDX' && secrets.OPENSHIFT_SA_TOKEN || secrets.OPENSHIFT_SA_TOKEN_EAO }} | |
OPENSHIFT_SA_NAME: ${{ github.event.inputs.project_type == 'GDX' && secrets.OPENSHIFT_SA_NAME || secrets.OPENSHIFT_SA_NAME_EAO }} | |
OPENSHIFT_IMAGE_REGISTRY: ${{ github.event.inputs.project_type == 'GDX' && secrets.OPENSHIFT_IMAGE_REGISTRY || secrets.OPENSHIFT_IMAGE_REGISTRY_EAO }} | |
OPENSHIFT_REPOSITORY: ${{ github.event.inputs.project_type == 'GDX' && secrets.OPENSHIFT_REPOSITORY || secrets.OPENSHIFT_REPOSITORY_EAO }} | |
jobs: | |
analytics-api-cd: | |
runs-on: ubuntu-20.04 | |
if: github.repository == 'bcgov/met-public' | |
environment: | |
name: "dev" | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Login Openshift | |
shell: bash | |
run: | | |
oc login --server=${{env.OPENSHIFT_LOGIN_REGISTRY}} --token=${{env.OPENSHIFT_SA_TOKEN}} | |
- name: Login Docker | |
run: | | |
echo "${{ env.OPENSHIFT_SA_TOKEN }}" | | |
docker login ${{ env.OPENSHIFT_IMAGE_REGISTRY }} -u ${{ env.OPENSHIFT_SA_NAME}} --password-stdin | |
- name: Build image | |
run: | | |
docker build . --file Dockerfile --tag image | |
- name: Push image | |
run: | | |
IMAGE_ID=${{ env.OPENSHIFT_IMAGE_REGISTRY }}/"${{ env.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 | |
shell: bash | |
run: | | |
oc rollout status dc/${{ env.APP_NAME }} -n ${{ env.OPENSHIFT_REPOSITORY }}-${{ env.TAG_NAME }} -w |