3
0
Fork 0
mirror of https://gitea.com/docker/build-push-action.git synced 2024-11-22 09:29:38 +01:00

Enable iidfile for multi-platform

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2020-10-21 09:51:06 +02:00
parent 999f006917
commit 29cf8ab8dc
No known key found for this signature in database
GPG key ID: 3248E46B6BB8C7F7
5 changed files with 85 additions and 56 deletions

View file

@ -46,8 +46,6 @@ jobs:
- -
name: Set up QEMU name: Set up QEMU
uses: docker/setup-qemu-action@v1 uses: docker/setup-qemu-action@v1
with:
platforms: all
- -
name: Set up Docker Buildx name: Set up Docker Buildx
id: buildx id: buildx
@ -74,6 +72,13 @@ jobs:
- -
name: Image digest name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }} run: echo ${{ steps.docker_build.outputs.digest }}
-
name: Check digest
run: |
if [ -z "${{ steps.docker_build.outputs.digest }}" ]; then
echo "::error::Digest should not be empty"
exit 1
fi
- -
name: Dump context name: Dump context
if: always() if: always()
@ -95,14 +100,11 @@ jobs:
- -
name: Set up QEMU name: Set up QEMU
uses: docker/setup-qemu-action@v1 uses: docker/setup-qemu-action@v1
with:
platforms: all
- -
name: Set up Docker Buildx name: Set up Docker Buildx
id: buildx id: buildx
uses: docker/setup-buildx-action@v1 uses: docker/setup-buildx-action@v1
with: with:
version: ${{ matrix.buildx-version }}
driver-opts: network=host driver-opts: network=host
- -
name: Build and push name: Build and push
@ -125,6 +127,13 @@ jobs:
- -
name: Image digest name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }} run: echo ${{ steps.docker_build.outputs.digest }}
-
name: Check digest
run: |
if [ -z "${{ steps.docker_build.outputs.digest }}" ]; then
echo "::error::Digest should not be empty"
exit 1
fi
- -
name: Dump context name: Dump context
if: always() if: always()
@ -150,8 +159,6 @@ jobs:
- -
name: Set up QEMU name: Set up QEMU
uses: docker/setup-qemu-action@v1 uses: docker/setup-qemu-action@v1
with:
platforms: all
- -
name: Set up Docker Buildx name: Set up Docker Buildx
id: buildx id: buildx
@ -213,8 +220,6 @@ jobs:
- -
name: Set up QEMU name: Set up QEMU
uses: docker/setup-qemu-action@v1 uses: docker/setup-qemu-action@v1
with:
platforms: all
- -
name: Set up Docker Buildx name: Set up Docker Buildx
id: buildx id: buildx
@ -242,6 +247,13 @@ jobs:
- -
name: Image digest name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }} run: echo ${{ steps.docker_build.outputs.digest }}
-
name: Check digest
run: |
if [ -z "${{ steps.docker_build.outputs.digest }}" ]; then
echo "::error::Digest should not be empty"
exit 1
fi
- -
name: Dump context name: Dump context
if: always() if: always()
@ -261,8 +273,6 @@ jobs:
- -
name: Set up QEMU name: Set up QEMU
uses: docker/setup-qemu-action@v1 uses: docker/setup-qemu-action@v1
with:
platforms: all
- -
name: Set up Docker Buildx name: Set up Docker Buildx
id: buildx id: buildx
@ -294,6 +304,13 @@ jobs:
- -
name: Image digest (1) name: Image digest (1)
run: echo ${{ steps.docker_build.outputs.digest }} run: echo ${{ steps.docker_build.outputs.digest }}
-
name: Check digest (1)
run: |
if [ -z "${{ steps.docker_build.outputs.digest }}" ]; then
echo "::error::Digest should not be empty"
exit 1
fi
- -
name: Prune name: Prune
run: | run: |
@ -321,7 +338,14 @@ jobs:
name: Image digest (2) name: Image digest (2)
run: echo ${{ steps.docker_build2.outputs.digest }} run: echo ${{ steps.docker_build2.outputs.digest }}
- -
name: Check digests name: Check digest (2)
run: |
if [ -z "${{ steps.docker_build2.outputs.digest }}" ]; then
echo "::error::Digest should not be empty"
exit 1
fi
-
name: Compare digests
run: | run: |
echo Compare "${{ steps.docker_build.outputs.digest }}" with "${{ steps.docker_build2.outputs.digest }}" echo Compare "${{ steps.docker_build.outputs.digest }}" with "${{ steps.docker_build2.outputs.digest }}"
if [ "${{ steps.docker_build.outputs.digest }}" != "${{ steps.docker_build2.outputs.digest }}" ]; then if [ "${{ steps.docker_build.outputs.digest }}" != "${{ steps.docker_build2.outputs.digest }}" ]; then
@ -349,8 +373,6 @@ jobs:
- -
name: Set up QEMU name: Set up QEMU
uses: docker/setup-qemu-action@v1 uses: docker/setup-qemu-action@v1
with:
platforms: all
- -
name: Set up Docker Buildx name: Set up Docker Buildx
id: buildx id: buildx
@ -378,7 +400,7 @@ jobs:
uses: ./ uses: ./
with: with:
context: ./test context: ./test
file: ./test/Dockerfile-multi-golang file: ./test/Dockerfile-multi
builder: ${{ steps.buildx.outputs.name }} builder: ${{ steps.buildx.outputs.name }}
platforms: linux/amd64,linux/arm64 platforms: linux/amd64,linux/arm64
push: true push: true
@ -394,6 +416,13 @@ jobs:
- -
name: Image digest name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }} run: echo ${{ steps.docker_build.outputs.digest }}
-
name: Check digest
run: |
if [ -z "${{ steps.docker_build.outputs.digest }}" ]; then
echo "::error::Digest should not be empty"
exit 1
fi
- -
name: Dump context name: Dump context
if: always() if: always()
@ -414,8 +443,6 @@ jobs:
- -
name: Set up QEMU name: Set up QEMU
uses: docker/setup-qemu-action@v1 uses: docker/setup-qemu-action@v1
with:
platforms: all
- -
name: Set up Docker Buildx name: Set up Docker Buildx
id: buildx id: buildx
@ -440,7 +467,7 @@ jobs:
uses: ./ uses: ./
with: with:
context: ./test context: ./test
file: ./test/Dockerfile-multi-golang file: ./test/Dockerfile-multi
builder: ${{ steps.buildx.outputs.name }} builder: ${{ steps.buildx.outputs.name }}
platforms: linux/amd64,linux/arm64 platforms: linux/amd64,linux/arm64
push: true push: true
@ -457,7 +484,14 @@ jobs:
name: Image digest name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }} run: echo ${{ steps.docker_build.outputs.digest }}
- -
name: Check digests name: Check digest
run: |
if [ -z "${{ steps.docker_build.outputs.digest }}" ]; then
echo "::error::Digest should not be empty"
exit 1
fi
-
name: Compare digests
run: | run: |
echo Compare "${{ needs.github-cache-first.outputs.digest }}" with "${{ steps.docker_build.outputs.digest }}" echo Compare "${{ needs.github-cache-first.outputs.digest }}" with "${{ steps.docker_build.outputs.digest }}"
if [ "${{ needs.github-cache-first.outputs.digest }}" != "${{ steps.docker_build.outputs.digest }}" ]; then if [ "${{ needs.github-cache-first.outputs.digest }}" != "${{ steps.docker_build.outputs.digest }}" ]; then

View file

@ -31,6 +31,19 @@ describe('getArgs', () => {
// prettier-ignore // prettier-ignore
test.each([ test.each([
[
'0.4.1',
new Map<string, string>([
['context', '.'],
]),
[
'buildx',
'build',
'--iidfile', '/tmp/.docker-build-push-jest/iidfile',
'--file', 'Dockerfile',
'.'
]
],
[ [
'0.4.2', '0.4.2',
new Map<string, string>([ new Map<string, string>([
@ -63,6 +76,20 @@ describe('getArgs', () => {
'.' '.'
] ]
], ],
[
'0.4.1',
new Map<string, string>([
['context', '.'],
['platforms', 'linux/amd64,linux/arm64']
]),
[
'buildx',
'build',
'--platform', 'linux/amd64,linux/arm64',
'--file', 'Dockerfile',
'.'
]
],
[ [
'0.4.1', '0.4.1',
new Map<string, string>([ new Map<string, string>([
@ -71,6 +98,7 @@ describe('getArgs', () => {
[ [
'buildx', 'buildx',
'build', 'build',
'--iidfile', '/tmp/.docker-build-push-jest/iidfile',
'--file', 'Dockerfile', '--file', 'Dockerfile',
'.' '.'
] ]
@ -120,6 +148,7 @@ describe('getArgs', () => {
'buildx', 'buildx',
'build', 'build',
'--platform', 'linux/amd64,linux/arm64', '--platform', 'linux/amd64,linux/arm64',
'--iidfile', '/tmp/.docker-build-push-jest/iidfile',
'--secret', 'id=GIT_AUTH_TOKEN,src=/tmp/.docker-build-push-jest/.tmpname-jest', '--secret', 'id=GIT_AUTH_TOKEN,src=/tmp/.docker-build-push-jest/.tmpname-jest',
'--file', './test/Dockerfile', '--file', './test/Dockerfile',
'--builder', 'builder-git-context-2', '--builder', 'builder-git-context-2',

6
dist/index.js generated vendored
View file

@ -14928,10 +14928,8 @@ function getBuildArgs(inputs, defaultContext, buildxVersion) {
yield exports.asyncForEach(inputs.outputs, (output) => __awaiter(this, void 0, void 0, function* () { yield exports.asyncForEach(inputs.outputs, (output) => __awaiter(this, void 0, void 0, function* () {
args.push('--output', output); args.push('--output', output);
})); }));
// TODO: Remove platforms length cond when buildx >0.4.2 available on runner (docker/buildx#351) if (!buildx.isLocalOrTarExporter(inputs.outputs) &&
if (inputs.platforms.length == 0 && (inputs.platforms.length == 0 || semver.satisfies(buildxVersion, '>=0.4.2'))) {
!buildx.isLocalOrTarExporter(inputs.outputs) &&
semver.satisfies(buildxVersion, '>=0.4.2')) {
args.push('--iidfile', yield buildx.getImageIDFile()); args.push('--iidfile', yield buildx.getImageIDFile());
} }
yield exports.asyncForEach(inputs.cacheFrom, (cacheFrom) => __awaiter(this, void 0, void 0, function* () { yield exports.asyncForEach(inputs.cacheFrom, (cacheFrom) => __awaiter(this, void 0, void 0, function* () {

View file

@ -104,11 +104,9 @@ async function getBuildArgs(inputs: Inputs, defaultContext: string, buildxVersio
await asyncForEach(inputs.outputs, async output => { await asyncForEach(inputs.outputs, async output => {
args.push('--output', output); args.push('--output', output);
}); });
// TODO: Remove platforms length cond when buildx >0.4.2 available on runner (docker/buildx#351)
if ( if (
inputs.platforms.length == 0 &&
!buildx.isLocalOrTarExporter(inputs.outputs) && !buildx.isLocalOrTarExporter(inputs.outputs) &&
semver.satisfies(buildxVersion, '>=0.4.2') (inputs.platforms.length == 0 || semver.satisfies(buildxVersion, '>=0.4.2'))
) { ) {
args.push('--iidfile', await buildx.getImageIDFile()); args.push('--iidfile', await buildx.getImageIDFile());
} }

View file

@ -1,30 +0,0 @@
FROM --platform=${BUILDPLATFORM:-linux/amd64} tonistiigi/xx:golang AS xgo
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.13-alpine AS builder
ENV CGO_ENABLED 0
ENV GO111MODULE on
ENV GOPROXY https://goproxy.io
COPY --from=xgo / /
ARG TARGETPLATFORM
RUN go env
RUN apk --update --no-cache add \
build-base \
gcc \
git \
&& rm -rf /tmp/* /var/cache/apk/*
WORKDIR /app
ENV DIUN_VERSION="v4.4.0"
RUN git clone --branch ${DIUN_VERSION} https://github.com/crazy-max/diun .
RUN go mod download
RUN go build -ldflags "-w -s -X 'main.version=test'" -v -o diun cmd/main.go
FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:latest
COPY --from=builder /app/diun /usr/local/bin/diun
COPY --from=builder /usr/local/go/lib/time/zoneinfo.zip /usr/local/go/lib/time/zoneinfo.zip
RUN diun --version