Skip to content

Commit

Permalink
Enabled GHA Docker Cache in Pants (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
sureshjoshi authored Jun 12, 2024
1 parent fda35a1 commit 2338bf7
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 6 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/pants.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:

jobs:
build:
Expand All @@ -23,6 +24,29 @@ jobs:
steps:
- uses: actions/checkout@v4

# Need to use this action to specify containerd, otherwise it won't cache
- uses: crazy-max/ghaction-setup-docker@v3
with:
daemon-config: |
{
"features": {
"containerd-snapshotter": true
}
}
# This seems to be optional - if you're not doing cross-arch compilation of the container content
# - uses: docker/setup-buildx-action@v3
# with:
# install: true
# driver: docker

- name: Set up environment variables for Pants (Docker) to use GHA Cache
uses: actions/github-script@v7
with:
script: |
core.exportVariable("ACTIONS_CACHE_URL", process.env.ACTIONS_CACHE_URL || "");
core.exportVariable("ACTIONS_RUNTIME_TOKEN", process.env.ACTIONS_RUNTIME_TOKEN || "");
- uses: pantsbuild/actions/init-pants@v9
with:
# cache0 makes it easy to bust the cache if needed
Expand All @@ -37,6 +61,10 @@ jobs:
run: |
pants update-build-files --check lint ::
- name: Package
run: |
pants --docker-build-verbose package gcc-arm-none-eabi/:
# - name: Upload pants log
# uses: actions/upload-artifact@v2
# with:
Expand Down
2 changes: 2 additions & 0 deletions gcc-arm-none-eabi/BUILD.pants
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
docker_image(
name="gcc-arm-none-eabi",
cache_from=[{"type": "gha", "scope": "gcc-arm-none-eabi-gha"}],
cache_to={"type": "gha", "mode": "max", "scope": "gcc-arm-none-eabi-gha"},
)
13 changes: 7 additions & 6 deletions gcc-arm-none-eabi/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@ ARG DEBIAN_FRONTEND=non-interactive

RUN apt-get update \
&& apt-get install -y -qq --no-install-recommends \
bash=5.1-2+deb11u1 \
bzip2=1.0.8-4 \
ca-certificates=20210119 \
tar=1.34+dfsg-1 \
wget=1.21-1+b1 \
tar=1.34+dfsg-1+deb11u1 \
wget=1.21-1+deb11u1 \
&& rm -rf /var/lib/apt/lists/* \
&& wget -qO- https://developer.arm.com/-/media/Files/downloads/gnu-rm/10.3-2021.07/gcc-arm-none-eabi-10.3-2021.07-x86_64-linux.tar.bz2 | tar -xj


&& wget --progress=dot:giga -O- https://developer.arm.com/-/media/Files/downloads/gnu-rm/10.3-2021.07/gcc-arm-none-eabi-10.3-2021.07-x86_64-linux.tar.bz2 | tar -xj

FROM debian:bullseye-20210902-slim

RUN apt-get update \
&& apt-get install -y -qq --no-install-recommends \
bash=5.1-2+deb11u1 \
ccache=4.2-1 \
&& rm -rf /var/lib/apt/lists/* \
&& groupadd -r armoire \
Expand Down
6 changes: 6 additions & 0 deletions pants.ci.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@
colors = true
dynamic_ui = false
pantsd = false

[docker]
env_vars = [
"ACTIONS_CACHE_URL",
"ACTIONS_RUNTIME_TOKEN",
]
3 changes: 3 additions & 0 deletions pants.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ backend_packages = [
"pants.backend.docker.lint.hadolint",
]

[docker]
use_buildx = true

[python]
interpreter_constraints = [">=3.9,<4"]

Expand Down

0 comments on commit 2338bf7

Please sign in to comment.