From 29cf8ab8dc45c7b4278d540f46975e88a593b479 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Wed, 21 Oct 2020 09:51:06 +0200 Subject: [PATCH] Enable iidfile for multi-platform Signed-off-by: CrazyMax --- .github/workflows/ci.yml | 72 ++++++++++++++++++++++++++---------- __tests__/context.test.ts | 29 +++++++++++++++ dist/index.js | 6 +-- src/context.ts | 4 +- test/Dockerfile-multi-golang | 30 --------------- 5 files changed, 85 insertions(+), 56 deletions(-) delete mode 100644 test/Dockerfile-multi-golang diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 015490c..7204adc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,8 +46,6 @@ jobs: - name: Set up QEMU uses: docker/setup-qemu-action@v1 - with: - platforms: all - name: Set up Docker Buildx id: buildx @@ -74,6 +72,13 @@ jobs: - name: Image 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 if: always() @@ -95,14 +100,11 @@ jobs: - name: Set up QEMU uses: docker/setup-qemu-action@v1 - with: - platforms: all - name: Set up Docker Buildx id: buildx uses: docker/setup-buildx-action@v1 with: - version: ${{ matrix.buildx-version }} driver-opts: network=host - name: Build and push @@ -125,6 +127,13 @@ jobs: - name: Image 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 if: always() @@ -150,8 +159,6 @@ jobs: - name: Set up QEMU uses: docker/setup-qemu-action@v1 - with: - platforms: all - name: Set up Docker Buildx id: buildx @@ -213,8 +220,6 @@ jobs: - name: Set up QEMU uses: docker/setup-qemu-action@v1 - with: - platforms: all - name: Set up Docker Buildx id: buildx @@ -242,6 +247,13 @@ jobs: - name: Image 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 if: always() @@ -261,8 +273,6 @@ jobs: - name: Set up QEMU uses: docker/setup-qemu-action@v1 - with: - platforms: all - name: Set up Docker Buildx id: buildx @@ -294,6 +304,13 @@ jobs: - name: Image digest (1) 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 run: | @@ -321,7 +338,14 @@ jobs: name: Image digest (2) 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: | 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 @@ -349,8 +373,6 @@ jobs: - name: Set up QEMU uses: docker/setup-qemu-action@v1 - with: - platforms: all - name: Set up Docker Buildx id: buildx @@ -378,7 +400,7 @@ jobs: uses: ./ with: context: ./test - file: ./test/Dockerfile-multi-golang + file: ./test/Dockerfile-multi builder: ${{ steps.buildx.outputs.name }} platforms: linux/amd64,linux/arm64 push: true @@ -394,6 +416,13 @@ jobs: - name: Image 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 if: always() @@ -414,8 +443,6 @@ jobs: - name: Set up QEMU uses: docker/setup-qemu-action@v1 - with: - platforms: all - name: Set up Docker Buildx id: buildx @@ -440,7 +467,7 @@ jobs: uses: ./ with: context: ./test - file: ./test/Dockerfile-multi-golang + file: ./test/Dockerfile-multi builder: ${{ steps.buildx.outputs.name }} platforms: linux/amd64,linux/arm64 push: true @@ -457,7 +484,14 @@ jobs: name: Image 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: | 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 diff --git a/__tests__/context.test.ts b/__tests__/context.test.ts index 24ca2c2..6cc1bd6 100644 --- a/__tests__/context.test.ts +++ b/__tests__/context.test.ts @@ -31,6 +31,19 @@ describe('getArgs', () => { // prettier-ignore test.each([ + [ + '0.4.1', + new Map([ + ['context', '.'], + ]), + [ + 'buildx', + 'build', + '--iidfile', '/tmp/.docker-build-push-jest/iidfile', + '--file', 'Dockerfile', + '.' + ] + ], [ '0.4.2', new Map([ @@ -63,6 +76,20 @@ describe('getArgs', () => { '.' ] ], + [ + '0.4.1', + new Map([ + ['context', '.'], + ['platforms', 'linux/amd64,linux/arm64'] + ]), + [ + 'buildx', + 'build', + '--platform', 'linux/amd64,linux/arm64', + '--file', 'Dockerfile', + '.' + ] + ], [ '0.4.1', new Map([ @@ -71,6 +98,7 @@ describe('getArgs', () => { [ 'buildx', 'build', + '--iidfile', '/tmp/.docker-build-push-jest/iidfile', '--file', 'Dockerfile', '.' ] @@ -120,6 +148,7 @@ describe('getArgs', () => { 'buildx', 'build', '--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', '--file', './test/Dockerfile', '--builder', 'builder-git-context-2', diff --git a/dist/index.js b/dist/index.js index 673d773..30b0c18 100644 --- a/dist/index.js +++ b/dist/index.js @@ -14928,10 +14928,8 @@ function getBuildArgs(inputs, defaultContext, buildxVersion) { yield exports.asyncForEach(inputs.outputs, (output) => __awaiter(this, void 0, void 0, function* () { args.push('--output', output); })); - // TODO: Remove platforms length cond when buildx >0.4.2 available on runner (docker/buildx#351) - if (inputs.platforms.length == 0 && - !buildx.isLocalOrTarExporter(inputs.outputs) && - semver.satisfies(buildxVersion, '>=0.4.2')) { + if (!buildx.isLocalOrTarExporter(inputs.outputs) && + (inputs.platforms.length == 0 || semver.satisfies(buildxVersion, '>=0.4.2'))) { args.push('--iidfile', yield buildx.getImageIDFile()); } yield exports.asyncForEach(inputs.cacheFrom, (cacheFrom) => __awaiter(this, void 0, void 0, function* () { diff --git a/src/context.ts b/src/context.ts index cfe3f63..94dcdae 100644 --- a/src/context.ts +++ b/src/context.ts @@ -104,11 +104,9 @@ async function getBuildArgs(inputs: Inputs, defaultContext: string, buildxVersio await asyncForEach(inputs.outputs, async output => { args.push('--output', output); }); - // TODO: Remove platforms length cond when buildx >0.4.2 available on runner (docker/buildx#351) if ( - inputs.platforms.length == 0 && !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()); } diff --git a/test/Dockerfile-multi-golang b/test/Dockerfile-multi-golang deleted file mode 100644 index c673b57..0000000 --- a/test/Dockerfile-multi-golang +++ /dev/null @@ -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