From 78d7df02cbaae2445a7bdbc591a12e5b88655067 Mon Sep 17 00:00:00 2001 From: Maxime Beauchemin Date: Mon, 6 Jan 2025 15:12:52 -0800 Subject: [PATCH] fix: docker builds in forks (#31732) --- .github/workflows/docker.yml | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index ea08c91eb..72238d0e2 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -37,6 +37,7 @@ jobs: env: DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }} DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} + IMAGE_TAG: apache/superset:GHA-${{ matrix.build_preset }}-${{ github.run_id }} steps: @@ -72,36 +73,40 @@ jobs: # Single platform builds in pull_request context to speed things up if [ "${{ github.event_name }}" = "push" ]; then PLATFORM_ARG="--platform linux/arm64 --platform linux/amd64" + # can only --load images in single-platform builds + PUSH_OR_LOAD="--push" elif [ "${{ github.event_name }}" = "pull_request" ]; then PLATFORM_ARG="--platform linux/amd64" + PUSH_OR_LOAD="--load" fi supersetbot docker \ - --push \ + $PUSH_OR_LOAD \ --preset ${{ matrix.build_preset }} \ --context "$EVENT" \ --context-ref "$RELEASE" $FORCE_LATEST \ - --extra-flags "--build-arg INCLUDE_CHROMIUM=false" \ + --extra-flags "--build-arg INCLUDE_CHROMIUM=false --tag $IMAGE_TAG" \ $PLATFORM_ARG + # in the context of push (using multi-platform build), we need to pull the image locally - name: Docker pull - if: steps.check.outputs.python || steps.check.outputs.frontend || steps.check.outputs.docker - run: docker pull apache/superset:GHA-${GITHUB_RUN_ID} + if: github.event_name == 'push' && (steps.check.outputs.python || steps.check.outputs.frontend || steps.check.outputs.docker) + run: docker pull $IMAGE_TAG - name: Print docker stats if: steps.check.outputs.python || steps.check.outputs.frontend || steps.check.outputs.docker run: | - IMAGE_ID=$(docker images --filter "label=sha=${{ github.sha }}" --format "{{.ID}}" | head -n 1) echo "SHA: ${{ github.sha }}" - echo "IMAGE: $IMAGE_ID" - docker images $IMAGE_ID - docker history $IMAGE_ID + echo "IMAGE: $IMAGE_TAG" + docker images $IMAGE_TAG + docker history $IMAGE_TAG - name: docker-compose sanity check if: (steps.check.outputs.python || steps.check.outputs.frontend || steps.check.outputs.docker) && (matrix.build_preset == 'dev' || matrix.build_preset == 'lean') shell: bash run: | export SUPERSET_BUILD_TARGET=${{ matrix.build_preset }} + # This should reuse the CACHED image built in the previous steps docker compose build superset-init --build-arg DEV_MODE=false --build-arg INCLUDE_CHROMIUM=false docker compose up superset-init --exit-code-from superset-init