From b419231fcf27b18eef85d1dbc6e3a208375a4df6 Mon Sep 17 00:00:00 2001 From: David de Boer Date: Mon, 29 Jul 2024 12:11:37 +0200 Subject: [PATCH] ci: Build and deploy --- .github/workflows/deploy.yml | 60 ++++++++++++++++++++++++++++++++++++ .github/workflows/prod.yml | 14 +++++++++ 2 files changed, 74 insertions(+) create mode 100644 .github/workflows/deploy.yml create mode 100644 .github/workflows/prod.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..f5dfeed --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,60 @@ +on: + workflow_call: + inputs: + app: + required: true + type: string + +jobs: + build: + outputs: + image: ${{ steps.vars.outputs.image }} + tag: ${{ steps.vars.outputs.tag }} + runs-on: ubuntu-latest + permissions: + packages: write + contents: read + attestations: write + id-token: write + steps: + - uses: actions/checkout@v4 + - id: vars + run: | + echo "image=ghcr.io/${{ github.repository }}-${{ inputs.app }}" >> $GITHUB_OUTPUT + echo "tag=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + - uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - uses: docker/build-push-action@v6 + id: push + with: + context: ${{ inputs.app }} + push: true + tags: | + ${{ steps.vars.outputs.image }}:${{ steps.vars.outputs.tag }} + ${{ steps.vars.outputs.image }}:latest + - uses: actions/attest-build-provenance@v1 + with: + subject-name: ghcr.io/${{ github.repository }}-${{ inputs.app }} + subject-digest: ${{ steps.push.outputs.digest }} + push-to-registry: true + + deploy: + needs: build + runs-on: ubuntu-latest + steps: + - uses: digitalocean/action-doctl@v2 + with: + token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }} + + - name: Store credentials + run: doctl kubernetes cluster kubeconfig save nde + + - name: Update deployment + run: | + kubectl set image deployment/makemyflix-${{ inputs.app }} app=${{ needs.build.outputs.image }}:${{ needs.build.outputs.tag }} + + - name: Verify deployment + run: kubectl rollout status deployment/makemyflix-${{ inputs.app }} --timeout=120s diff --git a/.github/workflows/prod.yml b/.github/workflows/prod.yml new file mode 100644 index 0000000..14e39be --- /dev/null +++ b/.github/workflows/prod.yml @@ -0,0 +1,14 @@ +on: + push: + branches: + - main + +jobs: + build-deploy-app: + strategy: + matrix: + app: [nuxt, strapi] + uses: ./.github/workflows/deploy.yml + secrets: inherit + with: + app: ${{ matrix.app }}