From d27c9a09105ebefead8ea5fa7f44b1267440929c Mon Sep 17 00:00:00 2001 From: Chitoku Date: Mon, 26 Aug 2024 03:20:06 +0900 Subject: [PATCH] Publish images to ghcr.io --- .github/workflows/cd.yml | 40 ++++++++++++++++++---------------------- docker-bake.hcl | 14 ++++++++++++-- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 892cc3a2..b65b6100 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -6,6 +6,7 @@ on: permissions: contents: read + packages: write id-token: write jobs: @@ -17,31 +18,22 @@ jobs: uses: actions/checkout@v4 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - name: Build + - name: Log into Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build and push uses: docker/bake-action@v5 + env: + TAG: ${{ github.ref_name }} with: files: docker-bake.hcl - load: true + push: true set: | *.cache-from=type=gha *.cache-to=type=gha,mode=max - - name: Set up ID token - uses: actions/github-script@v7 - id: id-token - with: - result-encoding: string - script: | - return await core.getIDToken('container.chitoku.jp'); - - name: Log into Container Registry - uses: docker/login-action@v3 - with: - registry: container.chitoku.jp - username: oidc-idtoken - password: ${{ steps.id-token.outputs.result }} - - name: Push to Container Registry - run: | - docker push container.chitoku.jp/chitoku-k/hoarder/api - docker push container.chitoku.jp/chitoku-k/hoarder/ui deploy: name: Deploy runs-on: ubuntu-latest @@ -63,7 +55,11 @@ jobs: kubectl config set-credentials github-actions --token=${{ steps.id-token.outputs.result }} kubectl config set-context k8s.chitoku.jp --cluster=k8s.chitoku.jp --user=github-actions kubectl config use-context k8s.chitoku.jp - - name: Rollout restart + - name: Update images run: | - kubectl rollout restart deployment/hoarder-api - kubectl rollout restart deployment/hoarder-ui + kubectl set image deployment/hoarder-api \ + migration=ghcr.io/chitoku-k/hoarder/api:${{ github.ref_name }} + api=ghcr.io/chitoku-k/hoarder/api:${{ github.ref_name }} + + kubectl set image deployment/hoarder-ui \ + ui=ghcr.io/chitoku-k/hoarder/ui:${{ github.ref_name }} diff --git a/docker-bake.hcl b/docker-bake.hcl index 41e9fc66..ff5bcca1 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -1,10 +1,17 @@ +variable "TAG" { + default = "latest" +} + group "default" { targets = ["api", "ui"] } target "api" { context = "./api" - tags = ["container.chitoku.jp/chitoku-k/hoarder/api"] + tags = [ + "ghcr.io/chitoku-k/hoarder/api:latest", + "ghcr.io/chitoku-k/hoarder/api:${TAG}", + ] } target "ui" { @@ -12,5 +19,8 @@ target "ui" { contexts = { schema = "./schema" } - tags = ["container.chitoku.jp/chitoku-k/hoarder/ui"] + tags = [ + "ghcr.io/chitoku-k/hoarder/ui:latest", + "ghcr.io/chitoku-k/hoarder/ui:${TAG}", + ] }