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

Test CI Times For https://github.com/swift-on-server/articles/pull/23 #284

Closed
wants to merge 8 commits into from
Closed
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
72 changes: 72 additions & 0 deletions .github/workflows/mmbm-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: mmbm-deploy
on:
pull_request: { types: [opened, reopened, synchronize, ready_for_review] }
push: { branches: [main] }

jobs:
deploy:
runs-on: ubuntu-latest
container: swift:6.0-jammy
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install zstd
run: |
apt-get update -y
apt-get install -y zstd

- name: Restore .build
id: "restore-build"
uses: actions/cache/restore@v4
with:
path: .build
key: "swiftpm-build-${{ runner.os }}-${{ github.event.pull_request.base.sha || github.event.after }}"
restore-keys: "swiftpm-build-${{ runner.os }}-"

- name: Build App
run: |
apt-get update -y
apt-get install -y libjemalloc-dev
swift build \
--product Penny \
-c release \
--static-swift-stdlib \
-Xlinker -ljemalloc \
$([ -f ./Package.resolved ] && echo "--force-resolved-versions" || true)

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

- name: Install Docker
run: |
set -eu

# https://docs.docker.com/engine/install/ubuntu/#install-using-the-repository

# Add Docker's official GPG key:
apt-get update -y
apt-get install ca-certificates curl gnupg -y
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
chmod a+r /etc/apt/keyrings/docker.gpg

# Add the repository to Apt sources:
# shellcheck source=/dev/null
echo \
"deb [arch=\"$(dpkg --print-architecture)\" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
\"$(. /etc/os-release && echo "$VERSION_CODENAME")\" stable" |
tee /etc/apt/sources.list.d/docker.list >/dev/null
apt-get update -y

# Install Docker:
apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y

- name: Build image
run: docker build --network=host -t app:latest -f template-dockerfile .

# Push the image to a Docker container registry
40 changes: 40 additions & 0 deletions .github/workflows/mmbm-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: mmbm-tests
on:
pull_request: { types: [opened, reopened, synchronize, ready_for_review] }
push: { branches: [main] }

jobs:
unit-tests:
runs-on: ubuntu-latest
container: swift:6.0-jammy
steps:
- name: Check out code
uses: actions/checkout@v4

- name: Install zstd
run: |
apt-get update -y
apt-get install -y zstd

- name: Restore .build
id: "restore-build"
uses: actions/cache/restore@v4
with:
path: .build
key: "swiftpm-build-${{ runner.os }}-${{ github.event.pull_request.base.sha || github.event.after }}"
restore-keys: "swiftpm-build-${{ runner.os }}-"

- name: Build package
run: swift build --build-tests --enable-code-coverage

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

- name: Run unit tests
run: swift test --skip-build --enable-code-coverage

# Process the code coverage report, etc...
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
on:
pull_request: { types: [opened, reopened, synchronize, ready_for_review] }
# pull_request: { types: [opened, reopened, synchronize, ready_for_review] }
push: { branches: [main] }

jobs:
Expand Down
26 changes: 13 additions & 13 deletions Dockerfile → template-dockerfile
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
# ================================
# Build image
# ================================
FROM swift:6.0-jammy as build

ARG SWIFT_CONFIGURATION
ARG EXEC_NAME
FROM swift:6.0-jammy AS build

WORKDIR /staging

# Copy .build to staging area
COPY .build ./.build
# Copy entire repo into container
COPY . .

# Move executable to the root of the staging area
RUN mv .build/$SWIFT_CONFIGURATION/$EXEC_NAME ./
# Copy main executable to staging area
RUN cp "$(swift build -c release --show-bin-path)/Penny" ./

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

# Copy resources bundled by SPM to staging area
RUN find -L ".build/$SWIFT_CONFIGURATION/" -regex '.*\.resources$' -exec cp -Ra {} ./ \;
RUN find -L "$(swift build --package-path /build -c release --show-bin-path)/" -regex '.*\.resources$' -exec cp -Ra {} ./ \;

# Remove .build directory
RUN rm -dr .build
# Copy any resources from the public directory and views directory if the directories exist
# Ensure that by default, neither the directory nor any of its contents are writable.
RUN [ -d /build/Public ] && { mv /build/Public ./Public && chmod -R a-w ./Public; } || true
RUN [ -d /build/Resources ] && { mv /build/Resources ./Resources && chmod -R a-w ./Resources; } || true

# ================================
# Run image
Expand Down Expand Up @@ -52,13 +51,14 @@ WORKDIR /app
COPY --from=build --chown=vapor:vapor /staging /app

# Provide configuration needed by the built-in crash reporter and some sensible default behaviors.
ENV SWIFT_BACKTRACE=enable=yes,sanitize=yes,threads=all,images=all,interactive=no,symbolicate=fast,swift-backtrace=./swift-backtrace-static
ENV SWIFT_BACKTRACE=enable=yes,sanitize=yes,threads=all,images=all,interactive=no,swift-backtrace=./swift-backtrace-static

# Ensure all further commands run as the vapor user
USER vapor:vapor

# Let Docker bind to port 8080
EXPOSE 8080

# Start the Penny service when the image is run.
# Start the Vapor service when the image is run, default to listening on 8080 in production environment
ENTRYPOINT ["./Penny"]
CMD ["serve", "--env", "production", "--hostname", "0.0.0.0", "--port", "8080"]
Loading