-
Notifications
You must be signed in to change notification settings - Fork 913
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5e2b715
commit 20b91b1
Showing
7 changed files
with
129 additions
and
5 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Build and publish a Docker image. | ||
# | ||
# Assumed to run as a subworkflow of .github/workflows/release.yml; specifically, as a local | ||
# artifacts job within `cargo-dist`. | ||
# | ||
# TODO(charlie): Ideally, the publish step would happen as a publish job within `cargo-dist`, but | ||
# sharing the built image as an artifact between jobs is challenging. | ||
name: "[puffin] Build Docker image" | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
plan: | ||
required: true | ||
type: string | ||
pull_request: | ||
paths: | ||
# When we change pyproject.toml, we want to ensure that the maturin builds still work. | ||
- pyproject.toml | ||
# And when we change this workflow itself... | ||
- .github/workflows/build-docker.yml | ||
|
||
jobs: | ||
docker-publish: | ||
name: Build Docker image (ghcr.io/astral-sh/puffin) | ||
runs-on: ubuntu-latest | ||
environment: | ||
name: release | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
submodules: recursive | ||
|
||
- uses: docker/setup-buildx-action@v3 | ||
|
||
- uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Extract metadata (tags, labels) for Docker | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ghcr.io/astral-sh/puffin | ||
|
||
- name: Check tag consistency | ||
if: ${{ inputs.plan && !fromJson(inputs.plan).announcement_tag_is_implicit }} | ||
run: | | ||
version=$(grep "version = " pyproject.toml | sed -e 's/version = "\(.*\)"/\1/g') | ||
if [ "${{ fromJson(inputs.plan).announcement_tag }}" != "${version}" ]; then | ||
echo "The input tag does not match the version from pyproject.toml:" >&2 | ||
echo "${{ fromJson(inputs.plan).announcement_tag }}" >&2 | ||
echo "${version}" >&2 | ||
exit 1 | ||
else | ||
echo "Releasing ${version}" | ||
fi | ||
- name: "Build and push Docker image" | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
platforms: linux/amd64,linux/arm64 | ||
# Reuse the builder | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max | ||
push: ${{ inputs.plan && !fromJson(inputs.plan).announcement_tag_is_implicit }} | ||
tags: ghcr.io/astral-sh/puffin:latest,ghcr.io/astral-sh/puffin:${{ inputs.plan && fromJson(inputs.plan).announcement_tag || 'dry-run' }} | ||
labels: ${{ steps.meta.outputs.labels }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
FROM --platform=$BUILDPLATFORM ubuntu as build | ||
ENV HOME="/root" | ||
WORKDIR $HOME | ||
|
||
RUN apt update \ | ||
&& apt install -y --no-install-recommends \ | ||
build-essential \ | ||
curl \ | ||
python3-venv \ | ||
cmake \ | ||
&& apt clean \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# Setup zig as cross compiling linker | ||
RUN python3 -m venv $HOME/.venv | ||
RUN .venv/bin/pip install cargo-zigbuild | ||
ENV PATH="$HOME/.venv/bin:$PATH" | ||
|
||
# Install rust | ||
ARG TARGETPLATFORM | ||
RUN case "$TARGETPLATFORM" in \ | ||
"linux/arm64") echo "aarch64-unknown-linux-musl" > rust_target.txt ;; \ | ||
"linux/amd64") echo "x86_64-unknown-linux-musl" > rust_target.txt ;; \ | ||
*) exit 1 ;; \ | ||
esac | ||
# Update rustup whenever we bump the rust version | ||
COPY rust-toolchain.toml rust-toolchain.toml | ||
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --target $(cat rust_target.txt) --profile minimal --default-toolchain none | ||
ENV PATH="$HOME/.cargo/bin:$PATH" | ||
# Installs the correct toolchain version from rust-toolchain.toml and then the musl target | ||
RUN rustup target add $(cat rust_target.txt) | ||
|
||
# Build | ||
COPY crates crates | ||
COPY ./Cargo.toml Cargo.toml | ||
COPY ./Cargo.lock Cargo.lock | ||
RUN cargo zigbuild --bin puffin --target $(cat rust_target.txt) --release | ||
RUN cp target/$(cat rust_target.txt)/release/puffin /puffin | ||
# TODO(konsti): Optimize binary size, with a version that also works when cross compiling | ||
# RUN strip --strip-all /puffin | ||
|
||
FROM scratch | ||
COPY --from=build /puffin /puffin | ||
WORKDIR /io | ||
ENTRYPOINT ["/puffin"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters