Skip to content

Commit ec47248

Browse files
riisiRhys MadiganRhys Madigan
authored
Add example using GHA cache backend (#12)
* Add caching example * edit workflow * Format * Set up buildx * Test gha cache * Tidy up * Enable containerd image store --------- Co-authored-by: Rhys Madigan <[email protected]> Co-authored-by: Rhys Madigan <[email protected]>
1 parent 40e2c12 commit ec47248

File tree

7 files changed

+65
-1
lines changed

7 files changed

+65
-1
lines changed

.github/workflows/pants.yaml

+21-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,26 @@ jobs:
2727
- uses: actions/setup-python@v4
2828
with:
2929
python-version: ${{ matrix.python-version }}
30+
- uses: crazy-max/ghaction-setup-docker@v3
31+
with:
32+
daemon-config: |
33+
{
34+
"features": {
35+
"containerd-snapshotter": true
36+
}
37+
}
38+
- uses: docker/setup-buildx-action@v3
39+
with:
40+
install: true
41+
driver: docker
42+
# Required for multi-platform builds
43+
- name: Setup QEMU
44+
uses: docker/setup-qemu-action@v3
45+
with:
46+
platforms: linux/amd64,linux/arm64
47+
# Exposes Github env vars needed for docker caching - see https://github.com/orgs/community/discussions/42856
48+
- name: Expose GitHub Runtime
49+
uses: crazy-max/ghaction-github-runtime@v3
3050
- uses: pantsbuild/actions/init-pants@v5-scie-pants
3151
# This action bootstraps pants and manages 2-3 GHA caches.
3252
# See: github.com/pantsbuild/actions/tree/main/init-pants/
@@ -58,7 +78,7 @@ jobs:
5878
env:
5979
DYNAMIC_TAG: workflow
6080
run: |
61-
pants package ::
81+
pants --docker-build-verbose package ::
6282
- name: Upload Pants log
6383
uses: actions/upload-artifact@v3
6484
with:

pants.toml

+8
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,11 @@ interpreter_constraints = ["==3.8.*"]
2828

2929
[python-infer]
3030
use_rust_parser = true
31+
32+
[docker]
33+
env_vars = [
34+
"ACTIONS_CACHE_URL",
35+
"ACTIONS_RUNTIME_TOKEN",
36+
"DYNAMIC_TAG",
37+
]
38+
use_buildx=true

src/docker/caching/BUILD

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright 2022 Pants project contributors.
2+
# Licensed under the Apache License, Version 2.0 (see LICENSE).
3+
4+
docker_image(
5+
name="with-gha-cache-backend",
6+
cache_to={"type": "gha", "mode": "max"},
7+
cache_from={"type": "gha"},
8+
)

src/docker/caching/Dockerfile

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM alpine@sha256:21a3deaa0d32a8057914f36584b5288d2e5ecc984380bc0118285c70fa8c9300
2+
3+
RUN echo "hello" > msg.txt && \
4+
sleep 60

src/docker/multiplatform/BUILD

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Note that multistage buildx builds requires using the containerd image store, due to
2+
# limitations with the docker-container driver (https://github.com/moby/buildkit/issues/2343)
3+
4+
docker_image(
5+
name="multiplatform-base",
6+
source="Dockerfile.base",
7+
skip_push=True,
8+
build_platform=["linux/amd64", "linux/arm64"],
9+
)
10+
11+
docker_image(
12+
name="multiplatform-final",
13+
source="Dockerfile.final",
14+
build_platform=["linux/amd64", "linux/arm64"],
15+
)
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM python:3.8
2+
3+
RUN echo "base image" >> base.txt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
ARG PARENT=:multiplatform-base
2+
# hadolint ignore=DL3006
3+
FROM ${PARENT}
4+
5+
RUN cat base.txt && \
6+
echo "final image" >> final.txt

0 commit comments

Comments
 (0)