From dccafe553a72df274cdd4726d344b3fce6647102 Mon Sep 17 00:00:00 2001 From: Jesse Suen Date: Thu, 4 Apr 2024 16:40:00 -0700 Subject: [PATCH] feat: multi-arch release action Signed-off-by: Jesse Suen --- .github/workflows/ci-cd.yml | 80 ---------------------------------- .github/workflows/release.yaml | 48 ++++++++++++++++++++ 2 files changed, 48 insertions(+), 80 deletions(-) delete mode 100644 .github/workflows/ci-cd.yml create mode 100644 .github/workflows/release.yaml diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml deleted file mode 100644 index 20c13e2..0000000 --- a/.github/workflows/ci-cd.yml +++ /dev/null @@ -1,80 +0,0 @@ -name: CI/CD -on: - push: - branches: - - main - -jobs: - build-image: - name: Build and Push Docker images - runs-on: ubuntu-latest - outputs: - image: ${{ steps.push-image.outputs.image }} - steps: - - - name: Checkout - uses: actions/checkout@v3 - with: - # fetch-depth: 0 needed for `git rev-list --count` to work properly - fetch-depth: 0 - - - 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.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Set up Golang - uses: actions/setup-go@v2 - with: - go-version: '1.18.0' - - - name: Push Image - id: push-image - run: make push-latest - - deploy-stage: - needs: build-image - runs-on: ubuntu-latest - steps: - - - uses: webfactory/ssh-agent@v0.5.4 - with: - ssh-private-key: ${{ secrets.GUESTBOOK_DEPLOY_KEY }} - - - uses: imranismail/setup-kustomize@v1 - - - name: Kustomize - run: | - git config --global user.name "Deploy Bot" - git config --global user.email "no-reply@akuity.io" - git clone git@github.com:akuity/guestbook-deploy.git - cd guestbook-deploy/env/stage - kustomize edit set image ${{ needs.build-image.outputs.image }} - git commit -a -m "Deploy stage: ${{ needs.build-image.outputs.image }}" - git push - - deploy-prod: - needs: [build-image, deploy-stage] - runs-on: ubuntu-latest - steps: - - - uses: webfactory/ssh-agent@v0.5.4 - with: - ssh-private-key: ${{ secrets.GUESTBOOK_DEPLOY_KEY }} - - - uses: imranismail/setup-kustomize@v1 - - - name: Kustomize - run: | - git config --global user.name "Deploy Bot" - git config --global user.email "no-reply@akuity.io" - git clone git@github.com:akuity/guestbook-deploy.git - cd guestbook-deploy/env/prod - kustomize edit set image ${{ needs.build-image.outputs.image }} - git commit -a -m "Deploy prod: ${{ needs.build-image.outputs.image }}" - git push diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..16c68d5 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,48 @@ +name: Release + +on: + release: + types: + - published + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: true + platforms: linux/amd64,linux/arm64 + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }}