Skip to content

Commit

Permalink
Publish images to ghcr.io
Browse files Browse the repository at this point in the history
  • Loading branch information
chitoku-k committed Aug 25, 2024
1 parent 150a240 commit d27c9a0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 24 deletions.
40 changes: 18 additions & 22 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:

permissions:
contents: read
packages: write
id-token: write

jobs:
Expand All @@ -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
Expand All @@ -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 }}
14 changes: 12 additions & 2 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
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" {
context = "./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}",
]
}

0 comments on commit d27c9a0

Please sign in to comment.