Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try caching .build to speed up CI #274

Merged
merged 3 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/deploy-all-lambdas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ jobs:
cd ${{ github.event.repository.name }}
git checkout ${{ github.sha }}

- name: Restore .build
id: "restore-cache"
uses: actions/cache/restore@v4
with:
path: ${{ github.event.repository.name }}/.build
key: "lambdas-build-${{ runner.os }}-${{ github.event.after }}"
restore-keys: "lambdas-build-${{ runner.os }}-"

- name: Find package names
working-directory: ${{ github.event.repository.name }}
id: find_package_names
Expand Down Expand Up @@ -62,6 +70,12 @@ jobs:
--body ./zips/${name}/${name}.zip
done

- name: Cache .build
uses: actions/cache/save@v4
with:
path: ${{ github.event.repository.name }}/.build
key: "lambdas-build-${{ runner.os }}-${{ github.event.after }}"

- name: Deploy
working-directory: ${{ github.event.repository.name }}
run: |
Expand Down
31 changes: 30 additions & 1 deletion .github/workflows/deploy-penny.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,33 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Restore .build
if: ${{ !(github.run_attempt > 1) }} # Because maybe the cache is causing issues
id: "restore-cache"
uses: actions/cache/restore@v4
with:
path: .build
key: "penny-release-static-build-${{ runner.os }}-${{ github.event.after }}"
restore-keys: "penny-release-static-build-${{ runner.os }}-"

- name: Build Penny
run: |
apt-get update -y
apt-get install -y libjemalloc-dev
swift build \
--product Penny \
-c release \
--force-resolved-versions \
--static-swift-stdlib \
-Xlinker -ljemalloc

- name: Cache .build
if: steps.restore-cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: .build
key: "penny-release-static-build-${{ runner.os }}-${{ github.event.after }}"

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
Expand All @@ -36,7 +63,9 @@ jobs:
# Build a docker container and
# push it to ECR so that it can
# be deployed to ECS.
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f Dockerfile .
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f Dockerfile . \
--build-arg SWIFT_CONFIGURATION=release \
--build-arg EXEC_NAME=Penny
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT

Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ on:

jobs:
unit-tests:
uses: vapor/ci/.github/workflows/run-unit-tests.yml@main
uses: mahdibm/ci/.github/workflows/run-unit-tests.yml@mmbm-caching
with:
with_release_mode_testing: true
with_experimental_caching: true
with_coverage: false
with_tsan: false
with_api_check: false
Expand Down
28 changes: 4 additions & 24 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,19 @@
# ================================
FROM swift:6.0-jammy as build

ARG SWIFT_CONFIGURATION
ARG EXEC_NAME

# Install OS updates
RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \
&& apt-get -q update \
&& apt-get -q dist-upgrade -y \
&& apt-get install -y libjemalloc-dev

# Set up a build area
WORKDIR /build

# First just resolve dependencies.
# This creates a cached layer that can be reused
# as long as your Package.swift/Package.resolved
# files do not change.
COPY ./Package.* ./
RUN swift package resolve --skip-update \
$([ -f ./Package.resolved ] && echo "--force-resolved-versions" || true)

# Copy entire repo into container
COPY . .

# Build everything, with optimizations, with static linking, and using jemalloc
# N.B.: The static version of jemalloc is incompatible with the static Swift runtime.
RUN swift build \
-c release \
--product Penny \
--static-swift-stdlib \
-Xlinker -ljemalloc

# Switch to the staging area
WORKDIR /staging

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

# Copy static swift backtracer binary to staging area
RUN cp "/usr/libexec/swift/linux/swift-backtrace-static" ./
Expand Down
Loading