Merge pull request #196 from bcgov/dev #61
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: Create Image and publish App | |
on: | |
push: | |
branches: | |
- main | |
- dev | |
paths: | |
- "src/**" | |
- "helm/**" | |
- ".github/workflows/publish-image.yml" | |
- "Dockerfile" | |
- "poetry.lock" | |
- "pyproject.toml" | |
env: | |
GITHUB_REGISTRY: ghcr.io | |
IMAGE_NAME: bcgov/sso-switchover-agent | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
jobs: | |
build-and-push-image: | |
permissions: write-all | |
runs-on: ubuntu-20.04 | |
outputs: | |
release_tag: ${{ steps.get-tag.outputs.release_tag }} | |
steps: | |
- uses: hmarr/debug-action@v3 | |
- uses: actions/checkout@v4 | |
- name: Log in to the GitHub Container registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.GITHUB_REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract Tag for Sandbox | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.GITHUB_REGISTRY }}/${{ env.IMAGE_NAME }} | |
- name: Create Release and Extract Tag for Production | |
if: endsWith(github.ref, '/main') | |
id: release | |
uses: rymndhng/[email protected] | |
with: | |
bump_version_scheme: "patch" | |
tag_prefix: "v" | |
use_github_release_notes: "true" | |
release_name: "Release <RELEASE_VERSION>" | |
max_commits: 100 # default is 50 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Cache Docker layers | |
uses: actions/cache@v4 | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-buildx-${{ github.sha }} | |
restore-keys: ${{ runner.os }}-buildx- | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
push: true | |
tags: ${{ endsWith(github.ref, '/main') && format('{0}/{1}:{2}', env.GITHUB_REGISTRY, env.IMAGE_NAME, steps.release.outputs.tag_name) || steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
cache-from: type=local,src=/tmp/.buildx-cache | |
cache-to: type=local,dest=/tmp/.buildx-cache-new | |
# Temp fix | |
# https://github.com/docker/build-push-action/issues/252 | |
# https://github.com/moby/buildkit/issues/1896 | |
- name: Move Docker layers cache | |
run: | | |
rm -rf /tmp/.buildx-cache | |
mv /tmp/.buildx-cache-new /tmp/.buildx-cache | |
- id: get-tag | |
name: Get Tag | |
run: | | |
echo "release_tag=${{ endsWith(github.ref, '/main') && steps.release.outputs.tag_name || steps.meta.outputs.version }}" >> $GITHUB_OUTPUT | |
deploy-to-openshift: | |
needs: [build-and-push-image] | |
strategy: | |
matrix: | |
license: [e4ca1d, eb75ad] | |
env: [dev, test, prod] | |
runs-on: ubuntu-20.04 | |
permissions: | |
contents: read | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Authenticate and set context | |
if: (endsWith(github.ref, '/dev') && matrix.license == 'e4ca1d' || endsWith(github.ref, '/main') && matrix.license == 'eb75ad') | |
uses: redhat-actions/oc-login@v1 | |
with: | |
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER_GOLDDR }} | |
openshift_token: ${{ secrets.OPENSHIFT_TOKEN_GOLDDR }} | |
namespace: ${{ matrix.license }}-${{ matrix.env }} | |
insecure_skip_tls_verify: true | |
- name: Deploy app with Helm chart | |
if: (endsWith(github.ref, '/dev') && matrix.license == 'e4ca1d' || endsWith(github.ref, '/main') && matrix.license == 'eb75ad') | |
run: | | |
namespace=${{ matrix.license }}-${{ matrix.env }} | |
helm dep up | |
helm upgrade --install --atomic switch-agent . -n ${namespace} \ | |
-f values.yaml -f "values-${{ matrix.license }}.yaml" --set image.tag="${{ needs.build-and-push-image.outputs.release_tag }}" | |
working-directory: ./helm |