aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Sebastiaan Zeeff <[email protected]>2020-11-16 16:48:33 +0100
committerGravatar Sebastiaan Zeeff <[email protected]>2020-11-16 16:48:33 +0100
commit7a5d61af3867eb79ed35f2748b2582f640897254 (patch)
treeff390a7917002ebc608c2e13333df03a94466eac
parentFix lint errors introduced by persistence removal (diff)
Split lint and build jobs into separate workflows
I've separated the lint and build jobs into two separate workflows: - Lint: .github/workflows/lint.yaml - Build: .github/workflows/build.yaml The main difference is that the Build workflow will be triggered if the Lint workflow completes while it's been run on the "master" branch. The build job will check if the Lint run was successful and if it were, it actually builds the container, pushes it the GHCR, and triggers the deployment to our kubernetes cluster.
-rw-r--r--.github/workflows/build.yaml64
-rw-r--r--.github/workflows/lint.yaml (renamed from .github/workflows/lint-build-deploy.yaml)59
2 files changed, 66 insertions, 57 deletions
diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml
new file mode 100644
index 00000000..404e66f7
--- /dev/null
+++ b/.github/workflows/build.yaml
@@ -0,0 +1,64 @@
+name: Build
+
+on:
+ workflow_run:
+ workflows: ["Lint"]
+ branches:
+ - master
+ types:
+ - completed
+
+jobs:
+ build:
+ if: github.event.workflow_run.conclusion == 'success'
+ name: Build, Push, & Deploy Container
+ runs-on: ubuntu-latest
+
+ steps:
+ # Create a commit SHA-based tag for the container repositories
+ - name: Create SHA Container Tag
+ id: sha_tag
+ run: |
+ tag=$(cut -c 1-7 <<< $GITHUB_SHA)
+ echo "::set-output name=tag::$tag"
+
+ - name: Checkout code
+ uses: actions/checkout@v2
+
+ - name: Set up Docker Buildx
+ uses: docker/setup-buildx-action@v1
+
+ - name: Login to Github Container Registry
+ uses: docker/login-action@v1
+ with:
+ registry: ghcr.io
+ username: ${{ github.repository_owner }}
+ password: ${{ secrets.GHCR_TOKEN }}
+
+ # Build and push the container to the GitHub Container
+ # Repository. The container will be tagged as "latest"
+ # and with the short SHA of the commit.
+ - name: Build and push
+ uses: docker/build-push-action@v2
+ with:
+ context: .
+ file: ./Dockerfile
+ push: true
+ cache-from: type=registry,ref=ghcr.io/python-discord/seasonalbot:latest
+ tags: |
+ ghcr.io/python-discord/seasonalbot:latest
+ ghcr.io/python-discord/seasonalbot:${{ 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/seasonalbot:${{ steps.sha_tag.outputs.tag }}'
+ kubectl-version: 'latest'
diff --git a/.github/workflows/lint-build-deploy.yaml b/.github/workflows/lint.yaml
index 7cfd532c..063f406c 100644
--- a/.github/workflows/lint-build-deploy.yaml
+++ b/.github/workflows/lint.yaml
@@ -1,4 +1,4 @@
-name: Lint, Build & Deploy
+name: Lint
on:
push:
@@ -9,7 +9,7 @@ on:
jobs:
lint:
- name: Lint using pre-commit & flake8
+ name: Run pre-commit & flake8
runs-on: ubuntu-latest
env:
# Configure pip to cache dependencies and do a user install
@@ -91,58 +91,3 @@ jobs:
- name: Run flake8
run: "flake8 \
--format='::error file=%(path)s,line=%(row)d,col=%(col)d::[flake8] %(code)s: %(text)s'"
-
- build-and-deploy:
- name: Build and Deploy to Kubernetes
- needs: lint
- if: github.event_name != 'pull_request_target' && github.ref == 'refs/heads/master'
- runs-on: ubuntu-latest
-
- steps:
- # Create a commit SHA-based tag for the container repositories
- - name: Create SHA Container Tag
- id: sha_tag
- run: |
- tag=$(cut -c 1-7 <<< $GITHUB_SHA)
- echo "::set-output name=tag::$tag"
-
- - name: Checkout code
- uses: actions/checkout@v2
-
- - name: Set up Docker Buildx
- uses: docker/setup-buildx-action@v1
-
- - name: Login to Github Container Registry
- uses: docker/login-action@v1
- with:
- registry: ghcr.io
- username: ${{ github.repository_owner }}
- password: ${{ secrets.GHCR_TOKEN }}
-
- # Build and push the container to the GitHub Container
- # Repository. The container will be tagged as "latest"
- # and with the short SHA of the commit.
- - name: Build and push
- uses: docker/build-push-action@v2
- with:
- context: .
- file: ./Dockerfile
- push: true
- cache-from: type=registry,ref=ghcr.io/python-discord/seasonalbot:latest
- tags: |
- ghcr.io/python-discord/seasonalbot:latest
- ghcr.io/python-discord/seasonalbot:${{ 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/seasonalbot:${{ steps.sha_tag.outputs.tag }}'
- kubectl-version: 'latest'