From a215870470c239a1b34a6f46f58996de48768759 Mon Sep 17 00:00:00 2001 From: MahdiBM Date: Sun, 15 Dec 2024 17:35:09 +0330 Subject: [PATCH] use caching in Penny deploys as well --- .github/workflows/deploy-penny.yml | 31 +++++++++++++++++++++++++++++- Dockerfile | 28 ++++----------------------- 2 files changed, 34 insertions(+), 25 deletions(-) diff --git a/.github/workflows/deploy-penny.yml b/.github/workflows/deploy-penny.yml index 63262202..ba92c4b1 100644 --- a/.github/workflows/deploy-penny.yml +++ b/.github/workflows/deploy-penny.yml @@ -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: @@ -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 diff --git a/Dockerfile b/Dockerfile index 63100bbf..5dd81dd2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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" ./