Skip to content

Trigger redeploy

Trigger redeploy #6

Workflow file for this run

name: deploy
on:
pull_request:
branches:
- master
types: [closed]
env:
ACR: arkivverket.azurecr.io/schemas
IMAGE: schemas
TARGET_ENV: karbonprod
jobs:
pre_job:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
outputs:
date: ${{ steps.date.outputs.date }}
steps:
- name: Get current date
id: date
run: echo "::set-output name=date::$(date +'%Y-%m-%d')"
build-and-publish-image:
runs-on: ubuntu-latest
needs: pre_job
env:
IMAGE_VERSION: ${{ format('{0}-{1}', needs.pre_job.outputs.date, github.sha) }}
steps:
- uses: actions/checkout@v3
- name: Login to Docker container registry
uses: docker/login-action@v2.1.0
with:
registry: arkivverket.azurecr.io
username: ${{ secrets.ARKIVVERKET_AZURE_REGISTRY_USERNAME }}
password: ${{ secrets.ARKIVVERKET_AZURE_REGISTRY_PASSWORD }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2.0.0
with:
install: true
- name: Publish
run: >
docker build
--tag ${{ env.ACR }}/${{ env.IMAGE }}:${{ env.IMAGE_VERSION }}
--tag ${{ env.ACR }}/${{ env.IMAGE }}:latest
--push .
working-directory: .
update-deployment-version:
needs:
- pre_job
- build-and-publish-image
runs-on: ubuntu-latest
env:
REPO: ${{ github.repository }}
IMAGE_VERSION: ${{ format('{0}-{1}', needs.pre_job.outputs.date, github.sha) }}
steps:
- uses: actions/checkout@v3
with:
repository: ${{ format('{0}-k8s-config', github.repository) }}
token: ${{ secrets.GITOPS_PAT }}
- run: |
kustomize edit set image ${IMAGE}Image=${ACR}/${IMAGE}:${{ format('{0}', env.IMAGE_VERSION) }}
working-directory: overlays/${{ env.TARGET_ENV }}
- run: |
git config --local user.email "${{ secrets.GITOPS_EMAIL }}"
git config --local user.name "${{ secrets.GITOPS_USER }}"
git add .
cat > /tmp/commit-message <<- EOM
Set ${IMAGE} image tag to ${TAG} in ${TARGET_ENV}
Repository: ${REPO}
Pull Request: [#${PR_NUMBER}][${PR_NUMBER}]
[${PR_NUMBER}]: ${PR_URL}
EOM
git commit -F /tmp/commit-message
git push