Skip to content

Instantly share code, notes, and snippets.

@sjwaight
Created April 20, 2021 10:38
Show Gist options
  • Save sjwaight/41af791b7f27f0a4cf03ee7a363b0d9d to your computer and use it in GitHub Desktop.
Save sjwaight/41af791b7f27f0a4cf03ee7a363b0d9d to your computer and use it in GitHub Desktop.
Complete GitHub Action showing how to build and deploy a Windows Container app to Kubernetes using Helm
name: Build Windows Container Image
on:
push:
branches: [ deploy-to-k8s ]
pull_request:
branches: [ deploy-to-k8s ]
workflow_dispatch:
env:
dockerfilePath: 'MvcMusicStore-Completed\CIDockerfile'
USER: ${{ secrets.ACR_USER }}
TOKEN: ${{ secrets.ACR_SECRET }}
REPOSITORY: ${{ secrets.ACR_INSTANCE }}
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build-and-publish-docker-image:
name: Build and Publish Docker Image
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- name: Build and push an image to container registry
run: |
docker login $env:REPOSITORY -u $env:USER -p $env:TOKEN
docker build --file=$env:dockerfilePath -t ${{ secrets.ACR_INSTANCE }}/${{ secrets.IMAGE_NAME }}:${{ github.run_id }} -t ${{ secrets.ACR_INSTANCE }}/${{ secrets.IMAGE_NAME }}:latest .
docker image push --all-tags ${{ secrets.ACR_INSTANCE }}/${{ secrets.IMAGE_NAME }}
docker logout
build-and-push-helm-chart:
name: Build and Push Helm Chart
runs-on: windows-latest
needs: [build-and-publish-docker-image]
steps:
- uses: actions/checkout@master
- name: Helm Repo Add
run: |
helm repo add ${{ secrets.ACR_INSTANCE }} https://${{ secrets.ACR_INSTANCE }}/helm/v1/repo --username ${{ secrets.ACR_USER }} --password ${{ secrets.ACR_SECRET }}
env:
HELM_EXPERIMENTAL_OCI: 1
- name: Helm Chart Save
run: |
cd .\charts\mvcmusicstoreweb
helm chart save . ${{ secrets.IMAGE_NAME }}:v${{ github.run_id }}
helm chart save . ${{ secrets.ACR_INSTANCE }}/helm/${{ secrets.IMAGE_NAME }}:v${{ github.run_id }}
# list out saved charts
helm chart list
env:
HELM_EXPERIMENTAL_OCI: 1
- name: Helm Chart Push
run: |
helm registry login ${{ secrets.ACR_INSTANCE }} --username ${{ secrets.ACR_USER }} --password ${{ secrets.ACR_SECRET }}
helm chart push ${{ secrets.ACR_INSTANCE }}/helm/${{ secrets.IMAGE_NAME }}:v${{ github.run_id }}
env:
HELM_EXPERIMENTAL_OCI: 1
aks-deployment:
name: AKS Deployment
runs-on: windows-latest
needs: [build-and-publish-docker-image,build-and-push-helm-chart]
steps:
- uses: actions/checkout@master
- name: kubeconfig
run: echo "${{ secrets.KUBECONFIG }}" >> kubeconfig
- name: Helm Repo Add
run: |
helm repo add ${{ secrets.ACR_INSTANCE }} https://${{ secrets.ACR_INSTANCE }}/helm/v1/repo --username ${{ secrets.ACR_USER }} --password ${{ secrets.ACR_SECRET }}
helm repo update
env:
HELM_EXPERIMENTAL_OCI: 1
- name: Helm Upgrade
run: |
mkdir upgrade
helm registry login ${{ secrets.ACR_INSTANCE }} --username ${{ secrets.ACR_USER }} --password ${{ secrets.ACR_SECRET }}
helm chart pull ${{ secrets.ACR_INSTANCE }}/helm/${{ secrets.IMAGE_NAME }}:v${{ github.run_id }}
helm chart export ${{ secrets.ACR_INSTANCE }}/helm/${{ secrets.IMAGE_NAME }}:v${{ github.run_id }} --destination .\upgrade
helm upgrade ${{ secrets.IMAGE_NAME }} .\upgrade\${{ secrets.IMAGE_NAME }} -i
env:
KUBECONFIG: '.\kubeconfig'
HELM_EXPERIMENTAL_OCI: 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment