Skip to content

Commit 65aab80

Browse files
authored
chore(ci): add caching to local docker build (#708)
* .ci: Improve dockerfile to include caching Improves dockerfile / .ci/build.sh script to output lambda zips in a central location as well as adds buildkit caching to the docker build so that you don't have to re-download the node_modules of each zip directly each time you build with .ci/build.sh This also makes improvements in that if there are only changes in one directory then the cache will remain and the remaining lambdas will not be re-built. Signed-off-by: Eli Uriegas <[email protected]> * Add comment about memory size
1 parent a758320 commit 65aab80

File tree

2 files changed

+40
-19
lines changed

2 files changed

+40
-19
lines changed

.ci/Dockerfile

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
1-
FROM node:12
2-
1+
#syntax=docker/dockerfile:1.2
2+
FROM node:12 as build
3+
WORKDIR /lambda
34
RUN apt-get update \
4-
&& apt-get install -y zip \
5-
&& rm -rf /var/lib/apt/lists/*
5+
&& apt-get install -y zip \
6+
&& rm -rf /var/lib/apt/lists/*
67

7-
WORKDIR /lambda
8+
FROM build as runner-binaries-syncer
9+
COPY modules/runner-binaries-syncer/lambdas/runner-binaries-syncer /lambda
10+
RUN --mount=type=cache,target=/lambda/node_modules,id=runner-binaries-syncer \
11+
yarn install && yarn dist
812

9-
COPY . /lambda
13+
FROM build as runners
14+
COPY modules/runners/lambdas/runners /lambda
15+
RUN --mount=type=cache,target=/lambda/node_modules,id=runners \
16+
yarn install && yarn dist
1017

11-
RUN yarn install \
12-
&& yarn run dist
18+
FROM build as webhook
19+
COPY modules/webhook/lambdas/webhook /lambda
20+
RUN --mount=type=cache,target=/lambda/node_modules,id=webhook \
21+
yarn install && yarn dist
1322

23+
FROM scratch as final
24+
COPY --from=runner-binaries-syncer /lambda/runner-binaries-syncer.zip /runner-binaries-syncer.zip
25+
COPY --from=runners /lambda/runners.zip /runners.zip
26+
COPY --from=webhook /lambda/webhook.zip /webhook.zip

.ci/build.sh

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
#!/usr/bin/env bash
22
set -e
33

4-
lambdaSrcDirs=("modules/runner-binaries-syncer/lambdas/runner-binaries-syncer" "modules/runners/lambdas/runners" "modules/webhook/lambdas/webhook")
5-
repoRoot=$(dirname $(dirname $(realpath ${BASH_SOURCE[0]})))
6-
7-
for lambdaDir in ${lambdaSrcDirs[@]}; do
8-
cd "$repoRoot/${lambdaDir}"
9-
docker build -t lambda -f ../../../../.ci/Dockerfile .
10-
docker create --name lambda lambda
11-
zipName=$(basename "$PWD")
12-
docker cp lambda:/lambda/${zipName}.zip ${zipName}.zip
13-
docker rm lambda
14-
done
4+
# NOTE: This build requires docker buildkit integration which was introduced
5+
# in Docker v19.03+ and at least 4GB of memory available to the
6+
# docker daemon
7+
8+
set -eou pipefail
9+
10+
TOP_DIR=$(git rev-parse --show-toplevel)
11+
OUTPUT_DIR=${OUTPUT_DIR:-${TOP_DIR}/lambda_output}
12+
13+
mkdir -p "${OUTPUT_DIR}"
14+
15+
(
16+
set -x
17+
DOCKER_BUILDKIT=1 docker build \
18+
--target=final \
19+
--output=type=local,dest="${OUTPUT_DIR}" \
20+
-f "${TOP_DIR}/.ci/Dockerfile" \
21+
"${TOP_DIR}"
22+
)

0 commit comments

Comments
 (0)