Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit f22252d

Browse files
authored
Enable docker image caching for the deb build (#10431)
1 parent ab82fd6 commit f22252d

File tree

3 files changed

+65
-13
lines changed

3 files changed

+65
-13
lines changed

.github/workflows/release-artifacts.yml

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,43 @@ jobs:
4848
distro: ${{ fromJson(needs.get-distros.outputs.distros) }}
4949

5050
steps:
51-
- uses: actions/checkout@v2
51+
- name: Checkout
52+
uses: actions/checkout@v2
5253
with:
5354
path: src
54-
- uses: actions/setup-python@v2
55-
- run: ./src/scripts-dev/build_debian_packages "${{ matrix.distro }}"
56-
- uses: actions/upload-artifact@v2
55+
56+
- name: Set up Docker Buildx
57+
id: buildx
58+
uses: docker/setup-buildx-action@v1
59+
with:
60+
install: true
61+
62+
- name: Set up docker layer caching
63+
uses: actions/cache@v2
64+
with:
65+
path: /tmp/.buildx-cache
66+
key: ${{ runner.os }}-buildx-${{ github.sha }}
67+
restore-keys: |
68+
${{ runner.os }}-buildx-
69+
70+
- name: Set up python
71+
uses: actions/setup-python@v2
72+
73+
- name: Build the packages
74+
# see https://github.com/docker/build-push-action/issues/252
75+
# for the cache magic here
76+
run: |
77+
./src/scripts-dev/build_debian_packages \
78+
--docker-build-arg=--cache-from=type=local,src=/tmp/.buildx-cache \
79+
--docker-build-arg=--cache-to=type=local,mode=max,dest=/tmp/.buildx-cache-new \
80+
--docker-build-arg=--progress=plain \
81+
--docker-build-arg=--load \
82+
"${{ matrix.distro }}"
83+
rm -rf /tmp/.buildx-cache
84+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
85+
86+
- name: Upload debs as artifacts
87+
uses: actions/upload-artifact@v2
5788
with:
5889
name: debs
5990
path: debs/*

changelog.d/10431.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Use a docker image cache for the prerequisites for the debian package build.

scripts-dev/build_debian_packages

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import subprocess
1717
import sys
1818
import threading
1919
from concurrent.futures import ThreadPoolExecutor
20+
from typing import Optional, Sequence
2021

2122
DISTS = (
2223
"debian:buster",
@@ -39,8 +40,11 @@ projdir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
3940

4041

4142
class Builder(object):
42-
def __init__(self, redirect_stdout=False):
43+
def __init__(
44+
self, redirect_stdout=False, docker_build_args: Optional[Sequence[str]] = None
45+
):
4346
self.redirect_stdout = redirect_stdout
47+
self._docker_build_args = tuple(docker_build_args or ())
4448
self.active_containers = set()
4549
self._lock = threading.Lock()
4650
self._failed = False
@@ -79,8 +83,8 @@ class Builder(object):
7983
stdout = None
8084

8185
# first build a docker image for the build environment
82-
subprocess.check_call(
83-
[
86+
build_args = (
87+
(
8488
"docker",
8589
"build",
8690
"--tag",
@@ -89,8 +93,13 @@ class Builder(object):
8993
"distro=" + dist,
9094
"-f",
9195
"docker/Dockerfile-dhvirtualenv",
92-
"docker",
93-
],
96+
)
97+
+ self._docker_build_args
98+
+ ("docker",)
99+
)
100+
101+
subprocess.check_call(
102+
build_args,
94103
stdout=stdout,
95104
stderr=subprocess.STDOUT,
96105
cwd=projdir,
@@ -147,9 +156,7 @@ class Builder(object):
147156
self.active_containers.remove(c)
148157

149158

150-
def run_builds(dists, jobs=1, skip_tests=False):
151-
builder = Builder(redirect_stdout=(jobs > 1))
152-
159+
def run_builds(builder, dists, jobs=1, skip_tests=False):
153160
def sig(signum, _frame):
154161
print("Caught SIGINT")
155162
builder.kill_containers()
@@ -180,6 +187,11 @@ if __name__ == "__main__":
180187
action="store_true",
181188
help="skip running tests after building",
182189
)
190+
parser.add_argument(
191+
"--docker-build-arg",
192+
action="append",
193+
help="specify an argument to pass to docker build",
194+
)
183195
parser.add_argument(
184196
"--show-dists-json",
185197
action="store_true",
@@ -195,4 +207,12 @@ if __name__ == "__main__":
195207
if args.show_dists_json:
196208
print(json.dumps(DISTS))
197209
else:
198-
run_builds(dists=args.dist, jobs=args.jobs, skip_tests=args.no_check)
210+
builder = Builder(
211+
redirect_stdout=(args.jobs > 1), docker_build_args=args.docker_build_arg
212+
)
213+
run_builds(
214+
builder,
215+
dists=args.dist,
216+
jobs=args.jobs,
217+
skip_tests=args.no_check,
218+
)

0 commit comments

Comments
 (0)