Build bake change

This commit is contained in:
YuCat 2024-05-07 21:15:53 +08:00
parent cbee6ee7f3
commit 4c954be688
2 changed files with 25 additions and 29 deletions

View File

@ -52,12 +52,6 @@ jobs:
run: | run: |
mv "${{ steps.meta.outputs.bake-file }}" "/tmp/bake-meta.json" mv "${{ steps.meta.outputs.bake-file }}" "/tmp/bake-meta.json"
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Upload meta bake definition - name: Upload meta bake definition
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
with: with:
@ -114,11 +108,13 @@ jobs:
- name: Build - name: Build
id: bake id: bake
uses: docker/bake-action@v4 uses: docker/bake-action@v4
env:
PLATFORM: ${{ env.ARCH }}
with: with:
files: | files: |
./docker-bake.hcl ./docker-bake.hcl
/tmp/bake-meta.json /tmp/bake-meta.json
targets: ${{ env.PLATFORM_PAIR }} targets: image
set: | set: |
*.tags= *.tags=
*.platform=${{ matrix.platform }} *.platform=${{ matrix.platform }}
@ -126,18 +122,10 @@ jobs:
*.cache-to=type=gha,scope=build-${{ env.PLATFORM_PAIR }} *.cache-to=type=gha,scope=build-${{ env.PLATFORM_PAIR }}
*.output=type=image,"name=${{ env.DOCKERHUB_SLUG }},${{ env.GHCR_SLUG }}",push-by-digest=true,name-canonical=true,push=true *.output=type=image,"name=${{ env.DOCKERHUB_SLUG }},${{ env.GHCR_SLUG }}",push-by-digest=true,name-canonical=true,push=true
- name: Export digest (amd64) - name: Export digest
if: matrix.platform == 'linux/amd64'
run: | run: |
mkdir -p /tmp/digests mkdir -p /tmp/digests
digest="${{ fromJSON(steps.bake.outputs.metadata).image-amd64['containerimage.digest'] }}" digest="${{ fromJSON(steps.bake.outputs.metadata).image['containerimage.digest'] }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Export digest (arm64)
if: matrix.platform == 'linux/arm64'
run: |
mkdir -p /tmp/digests
digest="${{ fromJSON(steps.bake.outputs.metadata).image-arm64['containerimage.digest'] }}"
touch "/tmp/digests/${digest#sha256:}" touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest - name: Upload digest

View File

@ -2,24 +2,32 @@ variable "DEFAULT_TAG" {
default = "baidunetdisk-docker:latest" default = "baidunetdisk-docker:latest"
} }
group "linux-amd64" { variable "ARCH" {
targets = ["image-amd64"] default = "arm64"
}
group "linux-arm64" {
targets = ["image-arm64"]
} }
target "docker-metadata-action" { target "docker-metadata-action" {
tags = ["${DEFAULT_TAG}"] tags = ["${DEFAULT_TAG}"]
} }
// Default target if none specified
group "default" {
targets = ["image-local"]
}
target "image-amd64" { target "image" {
platforms = ["linux/amd64"]
inherits = ["docker-metadata-action"] inherits = ["docker-metadata-action"]
dockerfile = "Dockerfile" dockerfile = format("Dockerfile%s", equal("arm64", ARCH) ? "" : ".${ARCH}")
} }
target "image-arm64" {
platforms = ["linux/arm64"] target "image-local" {
inherits = ["docker-metadata-action"] inherits = ["image"]
dockerfile = "Dockerfile.arm64" output = ["type=docker"]
}
target "image-all" {
inherits = ["image"]
platforms = [
"linux/amd64",
"linux/arm64",
]
} }