Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build multi-arch images for commits on main #7900

Merged
merged 7 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions .github/workflows/docker-builds.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Build prefect docker images

# Note: Conda support for 3.11 is pending. See https://github.com/ContinuumIO/anaconda-issues/issues/13082

on:
# On each commit merged into main, push sha and branch patterns
push:
branches: main
# On workflow_dispatch, push sha and branch patterns
workflow_dispatch:

jobs:
publish-docker-images:
name: Build Docker images
runs-on: ubuntu-latest
Comment on lines +14 to +15
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you'll need "environment: dev" like we do for the prod environment https://github.com/PrefectHQ/prefect/blob/main/.github/workflows/release.yaml#L186

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch! d6defda

strategy:
matrix:
flavor:
- ""
- "-conda"
python-version:
- "3.7"
- "3.8"
- "3.9"
- "3.10"
- "3.11"
exclude:
# Not yet supported, see note at top
- flavor: "-conda"
python-version: "3.11"

steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

zanieb marked this conversation as resolved.
Show resolved Hide resolved
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
Comment on lines +46 to +49
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reminds me of the issue with retagging images build from main on release — the image will have the wrong version information. versioneer pulls information from git into a static file on Python package build.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we solved this problem with a mount directive: https://github.com/pypa/setuptools_scm#usage-from-docker

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

although that does void all subsequent layer caches, so we have to do it as late as possible 😅

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm we just copy the .git folder in during the build step which works fine. The issue is that we cannot retag these images on release, we'll need to rebuild them.

Copy link
Contributor Author

@ddelange ddelange Dec 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah gotcha. yes copying .git might be unwanted layer size if you have a lot of history. setuptools_scm also needs fetch-depth: 0 btw... ref pypa/setuptools-scm#480

they do however provide a 'pretend' environment variable mechanic you could combine with ${{ github.ref_name}} to 'solve' the problem


- name: Generate image metadata
id: metadata
uses: docker/metadata-action@v4
with:
images: prefecthq/prefect-dev
tags: |
type=raw,enable=${{ github.event_name != 'release' }},value=${{ github.ref_name }},suffix=-python${{ matrix.python-version }}
type=sha,suffix=-python${{ matrix.python-version }}
flavor: |
latest=false
suffix=${{ matrix.flavor }}

- name: Build image
uses: docker/build-push-action@v3
with:
context: .
platforms: linux/amd64,linux/arm64
build-args: |
PYTHON_VERSION=${{ matrix.python-version }}
${{ ( endsWith(matrix.flavor, 'conda') && 'BASE_IMAGE=prefect-conda' ) || '' }}
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}
push: true
zanieb marked this conversation as resolved.
Show resolved Hide resolved
# multi-stage cache manifests (mode=max) need a separate tag because they are not usable for runtime ref https://github.com/moby/buildkit#export-cache
cache-from: type=registry,ref=prefecthq/prefect-dev:buildcache-python${{ matrix.python-version }}${{ matrix.flavor }}
cache-to: ${{ ( github.event_name == 'push' && 'type=registry,ref=prefecthq/prefect-dev:buildcache-python${{ matrix.python-version }}${{ matrix.flavor }},mode=max' ) || '' }}
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ COPY --from=python-builder /opt/prefect/dist ./dist
ARG PREFECT_EXTRAS=${PREFECT_EXTRAS:-""}
RUN pip install --no-cache-dir "./dist/prefect.tar.gz${PREFECT_EXTRAS}"

# Smoke test
RUN prefect version

# Setup entrypoint
COPY scripts/entrypoint.sh ./entrypoint.sh
ENTRYPOINT ["/usr/bin/tini", "-g", "--", "/opt/prefect/entrypoint.sh"]