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

Add example using GHA cache backend #12

Merged
merged 9 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
22 changes: 21 additions & 1 deletion .github/workflows/pants.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,26 @@ jobs:
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- uses: crazy-max/ghaction-setup-docker@v3
with:
daemon-config: |
{
"features": {
"containerd-snapshotter": true
}
}
- uses: docker/setup-buildx-action@v3
with:
install: true
driver: docker
# Required for multi-platform builds
- name: Setup QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: linux/amd64,linux/arm64
# Exposes Github env vars needed for docker caching - see https://github.com/orgs/community/discussions/42856
- name: Expose GitHub Runtime
uses: crazy-max/ghaction-github-runtime@v3
- uses: pantsbuild/actions/init-pants@v5-scie-pants
# This action bootstraps pants and manages 2-3 GHA caches.
# See: github.com/pantsbuild/actions/tree/main/init-pants/
Expand Down Expand Up @@ -58,7 +78,7 @@ jobs:
env:
DYNAMIC_TAG: workflow
run: |
pants package ::
pants --docker-build-verbose package ::
- name: Upload Pants log
uses: actions/upload-artifact@v3
with:
Expand Down
8 changes: 8 additions & 0 deletions pants.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,11 @@ interpreter_constraints = ["==3.8.*"]

[python-infer]
use_rust_parser = true

[docker]
env_vars = [
"ACTIONS_CACHE_URL",
"ACTIONS_RUNTIME_TOKEN",
"DYNAMIC_TAG",
]
use_buildx=true
8 changes: 8 additions & 0 deletions src/docker/caching/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright 2022 Pants project contributors.
# Licensed under the Apache License, Version 2.0 (see LICENSE).

docker_image(
name="with-gha-cache-backend",
cache_to={"type": "gha", "mode": "max"},
cache_from={"type": "gha"},
)
4 changes: 4 additions & 0 deletions src/docker/caching/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM alpine@sha256:21a3deaa0d32a8057914f36584b5288d2e5ecc984380bc0118285c70fa8c9300

RUN echo "hello" > msg.txt && \
sleep 60
15 changes: 15 additions & 0 deletions src/docker/multiplatform/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Note that multistage buildx builds requires using the containerd image store, due to
# limitations with the docker-container driver (https://github.com/moby/buildkit/issues/2343)

docker_image(
name="multiplatform-base",
source="Dockerfile.base",
skip_push=True,
build_platform=["linux/amd64", "linux/arm64"],
)

docker_image(
name="multiplatform-final",
source="Dockerfile.final",
build_platform=["linux/amd64", "linux/arm64"],
)
3 changes: 3 additions & 0 deletions src/docker/multiplatform/Dockerfile.base
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM python:3.8

RUN echo "base image" >> base.txt
6 changes: 6 additions & 0 deletions src/docker/multiplatform/Dockerfile.final
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ARG PARENT=:multiplatform-base
# hadolint ignore=DL3006
FROM ${PARENT}

RUN cat base.txt && \
echo "final image" >> final.txt
Loading