From 63c5febc532e93c20458a57432fab24d917a7309 Mon Sep 17 00:00:00 2001 From: shtlrs Date: Mon, 6 Mar 2023 12:59:39 +0100 Subject: merge buid & deploy CIs --- .github/workflows/build-deploy.yaml | 88 +++++++++++++++++++++++++++++++++++++ .github/workflows/build.yaml | 58 ------------------------ .github/workflows/deploy.yaml | 52 ---------------------- 3 files changed, 88 insertions(+), 110 deletions(-) create mode 100644 .github/workflows/build-deploy.yaml delete mode 100644 .github/workflows/build.yaml delete mode 100644 .github/workflows/deploy.yaml (limited to '.github') diff --git a/.github/workflows/build-deploy.yaml b/.github/workflows/build-deploy.yaml new file mode 100644 index 00000000..cdfc84f9 --- /dev/null +++ b/.github/workflows/build-deploy.yaml @@ -0,0 +1,88 @@ +name: Build & Deploy + +on: + workflow_call: + inputs: + sha-tag: + description: "A short-form SHA tag for the commit that triggered this workflow" + required: true + type: string + + +jobs: + build: + name: Build Docker Image + runs-on: ubuntu-latest + + steps: + + - name: Checkout code + uses: actions/checkout@v3 + + # The current version (v3) of Docker's build-push action uses + # buildx, which comes with BuildKit features that help us speed + # up our builds using additional cache features. Buildx also + # has a lot of other features that are not as relevant to us. + # + # See https://github.com/docker/build-push-action + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to Github Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + # Build the container, including an inline cache manifest to + # allow us to use the registry as a cache source. + - name: Build and push + uses: docker/build-push-action@v4 + with: + context: . + file: ./Dockerfile + push: true + cache-from: type=registry,ref=ghcr.io/python-discord/site:latest + cache-to: type=inline + tags: | + ghcr.io/python-discord/site:latest + ghcr.io/python-discord/site:${{ steps.sha_tag.outputs.tag }} + build-args: | + git_sha=${{ github.sha }} + + deploy: + name: Deploy + needs: build + runs-on: ubuntu-latest + environment: production + + steps: + # 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@v3 + with: + repository: python-discord/kubernetes + + - uses: azure/setup-kubectl@v3 + + - name: Authenticate with Kubernetes + uses: azure/k8s-set-context@v3 + with: + method: kubeconfig + kubeconfig: ${{ secrets.KUBECONFIG }} + + - name: Deploy to Kubernetes + uses: Azure/k8s-deploy@v4 + with: + manifests: | + namespaces/default/site/deployment.yaml + images: 'ghcr.io/python-discord/site:${{ steps.sha_tag.outputs.tag }}' + + - name: Purge Cloudflare Edge Cache + uses: jakejarvis/cloudflare-purge-action@master + env: + CLOUDFLARE_ZONE: 989c984a358bfcd1e9b9d188cc86c1df + CLOUDFLARE_TOKEN: ${{ secrets.CLOUDFLARE_CACHE_TOKEN }} diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml deleted file mode 100644 index bf9ec5b7..00000000 --- a/.github/workflows/build.yaml +++ /dev/null @@ -1,58 +0,0 @@ -name: Build - -on: - workflow_run: - workflows: ["Lint & Test"] - branches: - - main - types: - - completed - -jobs: - build: - name: Build Docker Image - if: github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'push' - 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 "tag=$tag" >> $GITHUB_OUTPUT - - - name: Checkout code - uses: actions/checkout@v3 - - # The current version (v3) of Docker's build-push action uses - # buildx, which comes with BuildKit features that help us speed - # up our builds using additional cache features. Buildx also - # has a lot of other features that are not as relevant to us. - # - # See https://github.com/docker/build-push-action - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Login to Github Container Registry - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GITHUB_TOKEN }} - - # Build the container, including an inline cache manifest to - # allow us to use the registry as a cache source. - - name: Build and push - uses: docker/build-push-action@v4 - with: - context: . - file: ./Dockerfile - push: true - cache-from: type=registry,ref=ghcr.io/python-discord/site:latest - cache-to: type=inline - tags: | - ghcr.io/python-discord/site:latest - ghcr.io/python-discord/site:${{ steps.sha_tag.outputs.tag }} - build-args: | - git_sha=${{ github.sha }} diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml deleted file mode 100644 index f27690f0..00000000 --- a/.github/workflows/deploy.yaml +++ /dev/null @@ -1,52 +0,0 @@ -name: Deploy - -on: - workflow_run: - workflows: ["Build"] - branches: - - main - types: - - completed - -jobs: - deploy: - if: github.event.workflow_run.conclusion == 'success' - name: Deploy to Kubernetes Cluster - runs-on: ubuntu-latest - environment: production - - steps: - - name: Create SHA Container Tag - id: sha_tag - run: | - tag=$(cut -c 1-7 <<< $GITHUB_SHA) - echo "tag=$tag" >> $GITHUB_OUTPUT - - # 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@v3 - with: - repository: python-discord/kubernetes - - - uses: azure/setup-kubectl@v3 - - - name: Authenticate with Kubernetes - uses: azure/k8s-set-context@v3 - with: - method: kubeconfig - kubeconfig: ${{ secrets.KUBECONFIG }} - - - name: Deploy to Kubernetes - uses: Azure/k8s-deploy@v4 - with: - manifests: | - namespaces/default/site/deployment.yaml - images: 'ghcr.io/python-discord/site:${{ steps.sha_tag.outputs.tag }}' - - - name: Purge Cloudflare Edge Cache - uses: jakejarvis/cloudflare-purge-action@master - env: - CLOUDFLARE_ZONE: 989c984a358bfcd1e9b9d188cc86c1df - CLOUDFLARE_TOKEN: ${{ secrets.CLOUDFLARE_CACHE_TOKEN }} -- cgit v1.2.3