Skip to content

Commit 1aa129c

Browse files
authored
Try caching .build to speed up CI (#274)
* Try caching .build to speed up CI * use caching in lambda deploys as well * use caching in Penny deploys as well
1 parent 2068605 commit 1aa129c

File tree

4 files changed

+50
-26
lines changed

4 files changed

+50
-26
lines changed

.github/workflows/deploy-all-lambdas.yml

+14
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ jobs:
3232
cd ${{ github.event.repository.name }}
3333
git checkout ${{ github.sha }}
3434
35+
- name: Restore .build
36+
id: "restore-cache"
37+
uses: actions/cache/restore@v4
38+
with:
39+
path: ${{ github.event.repository.name }}/.build
40+
key: "lambdas-build-${{ runner.os }}-${{ github.event.after }}"
41+
restore-keys: "lambdas-build-${{ runner.os }}-"
42+
3543
- name: Find package names
3644
working-directory: ${{ github.event.repository.name }}
3745
id: find_package_names
@@ -62,6 +70,12 @@ jobs:
6270
--body ./zips/${name}/${name}.zip
6371
done
6472
73+
- name: Cache .build
74+
uses: actions/cache/save@v4
75+
with:
76+
path: ${{ github.event.repository.name }}/.build
77+
key: "lambdas-build-${{ runner.os }}-${{ github.event.after }}"
78+
6579
- name: Deploy
6680
working-directory: ${{ github.event.repository.name }}
6781
run: |

.github/workflows/deploy-penny.yml

+30-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,33 @@ jobs:
1515
- name: Checkout
1616
uses: actions/checkout@v4
1717

18+
- name: Restore .build
19+
if: ${{ !(github.run_attempt > 1) }} # Because maybe the cache is causing issues
20+
id: "restore-cache"
21+
uses: actions/cache/restore@v4
22+
with:
23+
path: .build
24+
key: "penny-release-static-build-${{ runner.os }}-${{ github.event.after }}"
25+
restore-keys: "penny-release-static-build-${{ runner.os }}-"
26+
27+
- name: Build Penny
28+
run: |
29+
apt-get update -y
30+
apt-get install -y libjemalloc-dev
31+
swift build \
32+
--product Penny \
33+
-c release \
34+
--force-resolved-versions \
35+
--static-swift-stdlib \
36+
-Xlinker -ljemalloc
37+
38+
- name: Cache .build
39+
if: steps.restore-cache.outputs.cache-hit != 'true'
40+
uses: actions/cache/save@v4
41+
with:
42+
path: .build
43+
key: "penny-release-static-build-${{ runner.os }}-${{ github.event.after }}"
44+
1845
- name: Configure AWS credentials
1946
uses: aws-actions/configure-aws-credentials@v4
2047
with:
@@ -36,7 +63,9 @@ jobs:
3663
# Build a docker container and
3764
# push it to ECR so that it can
3865
# be deployed to ECS.
39-
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f Dockerfile .
66+
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f Dockerfile . \
67+
--build-arg SWIFT_CONFIGURATION=release \
68+
--build-arg EXEC_NAME=Penny
4069
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
4170
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
4271

.github/workflows/test.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ on:
88

99
jobs:
1010
unit-tests:
11-
uses: vapor/ci/.github/workflows/run-unit-tests.yml@main
11+
uses: mahdibm/ci/.github/workflows/run-unit-tests.yml@mmbm-caching
1212
with:
1313
with_release_mode_testing: true
14+
with_experimental_caching: true
1415
with_coverage: false
1516
with_tsan: false
1617
with_api_check: false

Dockerfile

+4-24
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,19 @@
33
# ================================
44
FROM swift:6.0-jammy as build
55

6+
ARG SWIFT_CONFIGURATION
7+
ARG EXEC_NAME
8+
69
# Install OS updates
710
RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \
811
&& apt-get -q update \
912
&& apt-get -q dist-upgrade -y \
1013
&& apt-get install -y libjemalloc-dev
1114

12-
# Set up a build area
13-
WORKDIR /build
14-
15-
# First just resolve dependencies.
16-
# This creates a cached layer that can be reused
17-
# as long as your Package.swift/Package.resolved
18-
# files do not change.
19-
COPY ./Package.* ./
20-
RUN swift package resolve --skip-update \
21-
$([ -f ./Package.resolved ] && echo "--force-resolved-versions" || true)
22-
23-
# Copy entire repo into container
24-
COPY . .
25-
26-
# Build everything, with optimizations, with static linking, and using jemalloc
27-
# N.B.: The static version of jemalloc is incompatible with the static Swift runtime.
28-
RUN swift build \
29-
-c release \
30-
--product Penny \
31-
--static-swift-stdlib \
32-
-Xlinker -ljemalloc
33-
34-
# Switch to the staging area
3515
WORKDIR /staging
3616

3717
# Copy main executable to staging area
38-
RUN cp "$(swift build --package-path /build -c release --show-bin-path)/Penny" ./
18+
COPY .build/$SWIFT_CONFIGURATION/$EXEC_NAME ./
3919

4020
# Copy static swift backtracer binary to staging area
4121
RUN cp "/usr/libexec/swift/linux/swift-backtrace-static" ./

0 commit comments

Comments
 (0)