From 16f834e5c57af69e841e2ec25f22f35a1dbf7ca2 Mon Sep 17 00:00:00 2001 From: Harshal Sheth Date: Thu, 29 Aug 2024 15:27:02 -0700 Subject: [PATCH] make depot-based builds opt-in --- .../docker-custom-build-and-push/action.yml | 44 ++++++++++++++----- .github/workflows/docker-unified.yml | 4 ++ docker/datahub-ingestion/Dockerfile | 2 + docker/datahub-ingestion/Dockerfile-slim-only | 2 + 4 files changed, 42 insertions(+), 10 deletions(-) diff --git a/.github/actions/docker-custom-build-and-push/action.yml b/.github/actions/docker-custom-build-and-push/action.yml index 5d93a556d039f..a13046a3e6c11 100644 --- a/.github/actions/docker-custom-build-and-push/action.yml +++ b/.github/actions/docker-custom-build-and-push/action.yml @@ -36,6 +36,12 @@ inputs: target: description: "Sets the target stage to build" required: false + depot-project: + # Setting this will use native arm64 docker builds instead of QEMU emulation. + # This speeds up builds by 2-3x. + description: "Depot project id" + required: false + outputs: image_tag: description: "Docker image tags" @@ -97,27 +103,45 @@ runs: image: ${{ steps.single_tag.outputs.SINGLE_TAG }} # Code for building multi-platform images and pushing to Docker Hub. - # - name: Set up QEMU - # uses: docker/setup-qemu-action@v3 - # if: ${{ inputs.publish == 'true' }} - # - name: Set up Docker Buildx - # uses: docker/setup-buildx-action@v3 - # if: ${{ inputs.publish == 'true' }} + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + if: ${{ inputs.publish == 'true' && inputs.depot-project == '' }} + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + if: ${{ inputs.publish == 'true' && inputs.depot-project == '' }} - name: Setup Depot CLI uses: depot/setup-action@v1 - if: ${{ inputs.publish == 'true' }} + if: ${{ inputs.publish == 'true' && inputs.depot-project != '' }} - name: Login to DockerHub uses: docker/login-action@v3 if: ${{ inputs.publish == 'true' }} with: username: ${{ inputs.username }} password: ${{ inputs.password }} + + # Depot variant. - name: Build and Push Multi-Platform image - # uses: docker/build-push-action@v6 uses: depot/build-push-action@v1 - if: ${{ inputs.publish == 'true' }} + if: ${{ inputs.publish == 'true' && inputs.depot-project != '' }} + with: + project: ${{ inputs.depot-project }} + context: ${{ inputs.context }} + file: ${{ inputs.file }} + platforms: ${{ inputs.platforms }} + build-args: ${{ inputs.build-args }} + tags: ${{ steps.docker_meta.outputs.tags }} + target: ${{ inputs.target }} + push: true + cache-from: | + type=registry,ref=${{ steps.single_tag.outputs.SINGLE_TAG }}:head${{ inputs.flavor && format('-{0}', inputs.flavor) || '' }} + type=registry,ref=${{ steps.docker_meta.outputs.tags }} + cache-to: | + type=inline + + - name: Build and Push Multi-Platform image + uses: docker/build-push-action@v6 + if: ${{ inputs.publish == 'true' && inputs.depot-project == '' }} with: - project: s0gr1cr3jd context: ${{ inputs.context }} file: ${{ inputs.file }} platforms: ${{ inputs.platforms }} diff --git a/.github/workflows/docker-unified.yml b/.github/workflows/docker-unified.yml index 7284a5cc86a7e..c2adf628470e6 100644 --- a/.github/workflows/docker-unified.yml +++ b/.github/workflows/docker-unified.yml @@ -547,6 +547,7 @@ jobs: context: . file: ./docker/datahub-ingestion-base/Dockerfile platforms: linux/amd64,linux/arm64/v8 + depot-project: ${{ vars.DEPOT_PROJECT_ID }} - name: Compute DataHub Ingestion (Base) Tag id: tag run: echo "tag=${{ needs.setup.outputs.ingestion_base_change == 'true' && needs.setup.outputs.unique_tag || 'head' }}" >> "$GITHUB_OUTPUT" @@ -589,6 +590,7 @@ jobs: context: . file: ./docker/datahub-ingestion-base/Dockerfile platforms: linux/amd64,linux/arm64/v8 + depot-project: ${{ vars.DEPOT_PROJECT_ID }} - name: Compute DataHub Ingestion (Base-Slim) Tag id: tag run: echo "tag=${{ needs.setup.outputs.ingestion_base_change == 'true' && needs.setup.outputs.unique_slim_tag || 'head-slim' }}" >> "$GITHUB_OUTPUT" @@ -685,6 +687,7 @@ jobs: context: . file: ./docker/datahub-ingestion/Dockerfile platforms: linux/amd64,linux/arm64/v8 + depot-project: ${{ vars.DEPOT_PROJECT_ID }} - name: Compute Tag id: tag run: echo "tag=${{ needs.setup.outputs.ingestion_change == 'true' && needs.setup.outputs.unique_slim_tag || 'head-slim' }}" >> "$GITHUB_OUTPUT" @@ -772,6 +775,7 @@ jobs: context: . file: ./docker/datahub-ingestion/Dockerfile platforms: linux/amd64,linux/arm64/v8 + depot-project: ${{ vars.DEPOT_PROJECT_ID }} - name: Compute Tag (Full) id: tag run: echo "tag=${{ needs.setup.outputs.ingestion_change == 'true' && needs.setup.outputs.unique_tag || 'head' }}" >> "$GITHUB_OUTPUT" diff --git a/docker/datahub-ingestion/Dockerfile b/docker/datahub-ingestion/Dockerfile index caaf99a25d23f..ee0333e1cb1d1 100644 --- a/docker/datahub-ingestion/Dockerfile +++ b/docker/datahub-ingestion/Dockerfile @@ -59,4 +59,6 @@ FROM base AS dev-install FROM ${APP_ENV}-install AS final +WORKDIR /datahub-ingestion + USER datahub diff --git a/docker/datahub-ingestion/Dockerfile-slim-only b/docker/datahub-ingestion/Dockerfile-slim-only index 1ea15119f7b55..6ade262f2fede 100644 --- a/docker/datahub-ingestion/Dockerfile-slim-only +++ b/docker/datahub-ingestion/Dockerfile-slim-only @@ -26,4 +26,6 @@ RUN --mount=type=cache,target=/datahub-ingestion/.cache/uv,uid=1000,gid=1000 \ FROM slim-install as final +WORKDIR /datahub-ingestion + USER datahub