Skip to content

Commit

Permalink
use caching in Penny deploys as well
Browse files Browse the repository at this point in the history
  • Loading branch information
MahdiBM committed Dec 15, 2024
1 parent f28ddb2 commit a215870
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 25 deletions.
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
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

0 comments on commit a215870

Please sign in to comment.