CR deployment #20
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
# This manually triggered workflow deploys front end application to a object store bucket | |
# try to use as much shell scripting a possible | |
# actions appear from default branch - https://github.community/t/workflow-files-only-picked-up-from-master/16129/2 | |
# | |
# Supported Container Registries: | |
# - [to test] Aliyun OSS | |
# - [backlog] AWS S3 | |
# - [backlog] Azure | |
# - [backlog] GCP Cloud Storage | |
# | |
# Setup the following secrets | |
# - CR_USERNAME | |
# - CR_PASSWORD | |
# Setup the following vars | |
# - CR_HOST | |
# - CR_NS | |
# - CR_IMAGENAME | |
# Specify the following during build | |
# - tag_gr | |
# - cr_env (dev, uat, prd) | |
# | |
name: CR deployment | |
on: | |
workflow_dispatch: | |
# Inputs the workflow accepts. | |
inputs: | |
tag_gr: | |
description: 'git repo branch or tag' | |
default: 'main' | |
required: true | |
tag_ci: | |
description: 'container image tag' | |
default: 'latest' | |
required: true | |
cr_imagename: | |
description: 'container image name - leave blank to use GITHUB variables (if specified) or repo name' | |
default: '' | |
required: false | |
dockerfile_path: | |
description: 'path to dockerfile' | |
default: '.' | |
required: false | |
cr_env: | |
description: 'environment: dev, uat, stg, prd' | |
default: 'dev' | |
required: true | |
env: | |
CR_IMAGENAME: ${{ github.event.inputs.cr_imagename || vars.CR_IMAGENAME || github.event.repository.name }} | |
CR_PASSWORD: ${{ secrets.CR_PASSWORD }} | |
CR_USERNAME: ${{ secrets.CR_USERNAME }} | |
CR_HOST: ${{ vars.CR_HOST }} | |
CR_NS: ${{ vars.CR_NS }} | |
DOCKERFILE_PATH: ${{ github.event.inputs.dockerfile_path || '.' }} | |
DOCKERFILE_TARGET: production # follow value in docker file | |
jobs: | |
deploy_to_cr: | |
runs-on: ubuntu-latest | |
name: Deploying CR | |
steps: | |
- name: Selected Branch/tag | |
run: echo ${{ github.event.inputs.tag_gr }} | |
- name: Add checkout plugin | |
uses: actions/checkout@v3 | |
with: | |
ref: ${{ github.event.inputs.tag_gr }} | |
- name: Build and push image to CR | |
env: | |
IMAGE_TARGET: production | |
IMAGE_TAG: ${{ github.sha }} | |
run: | | |
# cat password.txt | | |
echo $CR_PASSWORD | docker login --username $CR_USERNAME --password-stdin $CR_HOST | |
docker build -t $CR_HOST/$CR_NS/$CR_IMAGENAME:${{ github.event.inputs.tag_ci }} \ | |
--target $DOCKERFILE_TARGET \ | |
--build-arg ARG_NODE_ENV=${{ github.event.inputs.cr_env }} \ | |
--build-arg ARG_API_PORT=3000 \ | |
$DOCKERFILE_PATH || exit 1001 | |
docker push $CR_HOST/$CR_NS/$CR_IMAGENAME-${{ github.event.inputs.cr_env }}:${{ github.event.inputs.tag_ci }} | |
docker logout |