-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
name: On Pull Request | ||
|
||
on: | ||
pull_request: | ||
|
||
jobs: | ||
build: | ||
name: Build | ||
uses: ./.github/workflows/wf-docker-build.yaml | ||
with: | ||
push-ghcr: true | ||
save-cache: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
name: On Push Main | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
|
||
jobs: | ||
build: | ||
name: Build | ||
uses: ./.github/workflows/wf-docker-build.yaml | ||
with: | ||
push-ghcr: false | ||
save-cache: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
name: Build Docker Images | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
push-ghcr: | ||
type: boolean | ||
default: false | ||
save-cache: | ||
type: boolean | ||
default: false | ||
|
||
jobs: | ||
build_and_push: | ||
name: Build and Push | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: docker/setup-buildx-action@v3 | ||
- uses: docker/setup-qemu-action@v3 | ||
|
||
- if: inputs.push-ghcr | ||
name: Login to ghcr.io | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Docker Metadata | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: | | ||
${{ inputs.push-ghcr && format('ghcr.io/{0}', github.repository) || '' }} | ||
tags: | | ||
type=raw,value=latest,enable={{is_default_branch}} | ||
type=ref,event=pr | ||
type=sha | ||
- name: Build and Push Artifacts | ||
uses: docker/bake-action@v5 | ||
with: | ||
push: true | ||
# Metadata Action のタグ出力を加工したいのでここではラベルのみを渡す | ||
# タグの情報は環境変数 DOCKER_METADATA_OUTPUT_TAGS を使って受け取る | ||
files: | | ||
docker-bake.hcl | ||
${{ steps.meta.outputs.bake-file-labels }} | ||
# 基本的に main ブランチのキャッシュしか共有できないのでキャッシュの保存はオプトインにしておく | ||
set: | | ||
*.cache-from=type=gha | ||
${{ inputs.save-cache && '*.cache-to=type=gha,mode=max' || '' }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
group "default" { | ||
targets = ["backend"] | ||
} | ||
|
||
target "docker-metadata-action" {} | ||
|
||
target "backend" { | ||
inherits = ["docker-metadata-action"] | ||
context = "./backend" | ||
matrix = { | ||
image = ["scoreserver"] | ||
} | ||
name = "backend-${image}" | ||
tags = make_tags("${image}") | ||
target = "${image}" | ||
} | ||
|
||
variable "DOCKER_METADATA_OUTPUT_TAGS" { | ||
default = "" | ||
} | ||
function "make_tags" { | ||
params = [ns] | ||
result = split("\n", replace("${DOCKER_METADATA_OUTPUT_TAGS}", ":", "/${ns}:")) | ||
} |