Skip to content

Commit

Permalink
Restructure Build & Deploy sequence in CI
Browse files Browse the repository at this point in the history
I've restructured the build & deploy sequence in our GitHub Actions CI
workflow:

- There's now a separate workflow to deploy to our cluster

- The Build workflow has an additional `if` check to ensure we're only
  starting the build & deploy sequences for pushes to master

- We now checkout the python-discord/kubernetes repo to fetch the
  deployment.yaml file located in there
  • Loading branch information
SebastiaanZ committed Nov 23, 2020
1 parent 08ab6fe commit ad84a56
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build & Deploy
name: Build

on:
workflow_run:
Expand All @@ -9,9 +9,9 @@ on:
- completed

jobs:
build-and-deploy:
name: Build and Deploy to Kubernetes
if: github.event.workflow_run.conclusion == 'success'
build:
name: Build Docker Image
if: github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'push'
runs-on: ubuntu-latest

steps:
Expand Down Expand Up @@ -54,17 +54,3 @@ jobs:
tags: |
ghcr.io/python-discord/site:latest
ghcr.io/python-discord/site:${{ steps.sha_tag.outputs.tag }}
- name: Authenticate with Kubernetes
uses: azure/k8s-set-context@v1
with:
method: kubeconfig
kubeconfig: ${{ secrets.KUBECONFIG }}

- name: Deploy to Kubernetes
uses: Azure/k8s-deploy@v1
with:
manifests: |
deployment.yaml
images: 'ghcr.io/python-discord/site:${{ steps.sha_tag.outputs.tag }}'
kubectl-version: 'latest'
45 changes: 45 additions & 0 deletions .github/workflows/kubernetes-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Deploy

on:
workflow_run:
workflows: ["Build"]
branches:
- master
types:
- completed

jobs:
deploy:
if: github.event.workflow_run.conclusion == 'success'
name: Deploy to Kubernetes Cluster
runs-on: ubuntu-latest

steps:
- name: Create SHA Container Tag
id: sha_tag
run: |
tag=$(cut -c 1-7 <<< $GITHUB_SHA)
echo "::set-output name=tag::$tag"
# Check out the private Kubernetes repository for the
# deployment.yaml file using a GitHub Personal Access
# Token to get access.
- name: Checkout code
uses: actions/checkout@v2
with:
repository: python-discord/kubernetes
token: ${{ secrets.REPO_TOKEN }}

- name: Authenticate with Kubernetes
uses: azure/k8s-set-context@v1
with:
method: kubeconfig
kubeconfig: ${{ secrets.KUBECONFIG }}

- name: Deploy to Kubernetes
uses: Azure/k8s-deploy@v1
with:
manifests: |
site/deployment.yaml
images: 'ghcr.io/python-discord/site:${{ steps.sha_tag.outputs.tag }}'
kubectl-version: 'latest'
23 changes: 0 additions & 23 deletions deployment.yaml

This file was deleted.

0 comments on commit ad84a56

Please sign in to comment.