mirror of https://github.com/astral-sh/uv
feat: use multi-runner on docker publish (#6556)
## Summary This PR parallelizes multi-platform builds using multiple workers (hence the new docker-build / docker-publish jobs), this seems to save about ~8 minutes. This is partial work extracted from https://github.com/astral-sh/uv/pull/6053 than is standalone
This commit is contained in:
parent
deea6025a1
commit
a959772074
|
|
@ -17,12 +17,21 @@ on:
|
||||||
paths:
|
paths:
|
||||||
- .github/workflows/build-docker.yml
|
- .github/workflows/build-docker.yml
|
||||||
|
|
||||||
|
env:
|
||||||
|
UV_BASE_IMG: ghcr.io/${{ github.repository_owner }}/uv
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
docker-publish:
|
docker-build:
|
||||||
name: Build Docker image (ghcr.io/astral-sh/uv)
|
name: Build Docker image (ghcr.io/astral-sh/uv) for ${{ matrix.platform }}
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
environment:
|
environment:
|
||||||
name: release
|
name: release
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
platform:
|
||||||
|
- linux/amd64
|
||||||
|
- linux/arm64
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
|
|
@ -40,7 +49,7 @@ jobs:
|
||||||
id: meta
|
id: meta
|
||||||
uses: docker/metadata-action@v5
|
uses: docker/metadata-action@v5
|
||||||
with:
|
with:
|
||||||
images: ghcr.io/astral-sh/uv
|
images: ${{ env.UV_BASE_IMG }}
|
||||||
|
|
||||||
- name: Check tag consistency
|
- name: Check tag consistency
|
||||||
if: ${{ inputs.plan != '' && !fromJson(inputs.plan).announcement_tag_is_implicit }}
|
if: ${{ inputs.plan != '' && !fromJson(inputs.plan).announcement_tag_is_implicit }}
|
||||||
|
|
@ -55,14 +64,72 @@ jobs:
|
||||||
echo "Releasing ${version}"
|
echo "Releasing ${version}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: "Build and push Docker image"
|
- name: Normalize Platform Pair (replace / with -)
|
||||||
|
run: |
|
||||||
|
platform=${{ matrix.platform }}
|
||||||
|
echo "PLATFORM_TUPLE=${platform//\//-}" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
# Adapted from https://docs.docker.com/build/ci/github-actions/multi-platform/
|
||||||
|
- name: Build and push by digest
|
||||||
|
id: build
|
||||||
uses: docker/build-push-action@v6
|
uses: docker/build-push-action@v6
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: ${{ matrix.platform }}
|
||||||
# Reuse the builder
|
cache-from: type=gha,scope=uv-${{ env.PLATFORM_TUPLE }}
|
||||||
cache-from: type=gha
|
cache-to: type=gha,mode=min,scope=uv-${{ env.PLATFORM_TUPLE }}
|
||||||
cache-to: type=gha,mode=max
|
|
||||||
push: ${{ inputs.plan != '' && !fromJson(inputs.plan).announcement_tag_is_implicit }}
|
|
||||||
tags: ghcr.io/astral-sh/uv:latest,ghcr.io/astral-sh/uv:${{ (inputs.plan != '' && fromJson(inputs.plan).announcement_tag) || 'dry-run' }}
|
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
outputs: type=image,name=${{ env.UV_BASE_IMG }},push-by-digest=true,name-canonical=true,push=${{ inputs.plan != '' && !fromJson(inputs.plan).announcement_tag_is_implicit }}
|
||||||
|
|
||||||
|
- name: Export digests
|
||||||
|
run: |
|
||||||
|
mkdir -p /tmp/digests
|
||||||
|
digest="${{ steps.build.outputs.digest }}"
|
||||||
|
touch "/tmp/digests/${digest#sha256:}"
|
||||||
|
|
||||||
|
- name: Upload digests
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: digests-${{ env.PLATFORM_TUPLE }}
|
||||||
|
path: /tmp/digests/*
|
||||||
|
if-no-files-found: error
|
||||||
|
retention-days: 1
|
||||||
|
|
||||||
|
docker-publish:
|
||||||
|
name: Publish Docker image (ghcr.io/astral-sh/uv)
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
environment:
|
||||||
|
name: release
|
||||||
|
needs:
|
||||||
|
- docker-build
|
||||||
|
if: ${{ inputs.plan != '' && !fromJson(inputs.plan).announcement_tag_is_implicit }}
|
||||||
|
steps:
|
||||||
|
- name: Download digests
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
path: /tmp/digests
|
||||||
|
pattern: digests-*
|
||||||
|
merge-multiple: true
|
||||||
|
|
||||||
|
- uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Extract metadata (tags, labels) for Docker
|
||||||
|
id: meta
|
||||||
|
uses: docker/metadata-action@v5
|
||||||
|
with:
|
||||||
|
images: ${{ env.UV_BASE_IMG }}
|
||||||
|
|
||||||
|
- uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: ghcr.io
|
||||||
|
username: ${{ github.repository_owner }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
# Adapted from https://docs.docker.com/build/ci/github-actions/multi-platform/
|
||||||
|
- name: Create manifest list and push
|
||||||
|
working-directory: /tmp/digests
|
||||||
|
run: |
|
||||||
|
docker buildx imagetools create \
|
||||||
|
-t ${{ env.UV_BASE_IMG }}:latest \
|
||||||
|
-t ${{ env.UV_BASE_IMG }}:${{ (inputs.plan != '' && fromJson(inputs.plan).announcement_tag) || 'dry-run' }} \
|
||||||
|
$(printf '${{ env.UV_BASE_IMG }}@sha256:%s ' *)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
FROM --platform=$BUILDPLATFORM ubuntu as build
|
FROM --platform=$BUILDPLATFORM ubuntu AS build
|
||||||
ENV HOME="/root"
|
ENV HOME="/root"
|
||||||
WORKDIR $HOME
|
WORKDIR $HOME
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue