3. Production deployment #3
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: 3. Production deployment | |
env: | |
IMAGE_REGISTRY: ghcr.io | |
IMAGE_NAME: opsta/opsta-linebot | |
on: | |
workflow_dispatch: | |
inputs: | |
use-latest: | |
type: boolean | |
required: true | |
default: false | |
description: Automatically pick the latest tag version | |
version: | |
type: string | |
required: false | |
description: 'Put version to deploy to production' | |
jobs: | |
# Commit to Git for ArgoCD | |
gitops-commit: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Get latest tag version | |
if: ${{ inputs.use-latest }} | |
id: semver | |
uses: anothrNick/github-tag-action@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
WITH_V: true | |
DRY_RUN: true | |
DEFAULT_BUMP: none | |
- name: Set tag version | |
run: echo "DEPLOY_VERSION=${{ inputs.use-latest && steps.semver.outputs.tag || inputs.version }}" >> "$GITHUB_ENV" | |
- name: Check if container image tag exists | |
uses: tyriis/[email protected] | |
id: check-tag | |
with: | |
registry: ${{ env.IMAGE_REGISTRY }} | |
repository: ${{ env.IMAGE_NAME }} | |
tag: ${{ env.DEPLOY_VERSION }} | |
- name: Fail if container image tag not exists | |
if: steps.check-tag.outputs.tag == 'not found' | |
run: | | |
echo "::error title=Container image tag not found::Container image tag ${{ env.DEPLOY_VERSION }} does not exist" | |
exit 1 | |
- name: Update Image Version in Helm Value file | |
uses: fjogeleit/yaml-update-action@main | |
with: | |
valueFile: "iac/helm-values/opsta-line-bot-prd.yaml" | |
propertyPath: image.tag | |
value: ${{ env.DEPLOY_VERSION }} | |
branch: main | |
message: "Update Image Version to ${{ env.DEPLOY_VERSION }}" | |
# ArgoCD Sync | |
gitops-sync: | |
runs-on: ubuntu-latest | |
container: | |
image: quay.io/argoproj/argocd:v2.12.4 | |
env: | |
ARGOCD_SERVER: ${{ secrets.ARGOCD_SERVER }} | |
ARGOCD_AUTH_TOKEN: ${{ secrets.ARGOCD_AUTH_TOKEN }} | |
# run after all of needs are complete (whether skipped or success) | |
if: ${{ !cancelled() && !failure() }} | |
needs: | |
- gitops-commit | |
steps: | |
- name: Sync ArgoCD | |
run: | | |
argocd app sync demo-opsta-line-bot-prd/opsta-line-bot-prd --project demo | |
argocd app wait demo-opsta-line-bot-prd/opsta-line-bot-prd --health |