Skip to content

Instantly share code, notes, and snippets.

@itsmunim
Last active December 3, 2021 08:19
Show Gist options
  • Save itsmunim/cf31d0829d8034f9f0f86bb9ad3a8b6d to your computer and use it in GitHub Desktop.
Save itsmunim/cf31d0829d8034f9f0f86bb9ad3a8b6d to your computer and use it in GitHub Desktop.
name: deploy-to-doks
on:
push:
branches:
- master
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build:
name: Build, push, and deploy
runs-on: ubuntu-latest
steps:
- name: Checkout master
uses: actions/checkout@master
- name: Set version
id: release
run: echo ::set-output name=version::$(git describe --always)
- name: Build container image
env:
VERSION: ${{ steps.release.outputs.version }}
run: docker build -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }} .
- name: Docker Login
run: echo ${{ secrets.CI_PAT }} | docker login ${{ env.REGISTRY }} -u ${{ github.actor }} --password-stdin
- name: Push image to Docker Registry
env:
VERSION: ${{ steps.release.outputs.version }}
run: docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }}
- name: Deploy to doks
env:
VERSION: ${{ steps.release.outputs.version }}
CLUSTER_CONFIG: "${{ secrets.CI_DOKS }}"
run: |
echo "${CLUSTER_CONFIG}" > .kubeconfig
export DOCKER_IMG="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }}"
# the following line adds the proper docker image path of our application service in kubernetes manifest
cat k8s/application.yaml | sed "s|IMAGE_PLACEHOLDER|$DOCKER_IMG|g" > application-with-image.yaml
kubectl --kubeconfig=.kubeconfig apply -f application-with-image.yaml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment