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 #285

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
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-noble
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-deploy-build-${{ runner.os }}-${{ github.event.pull_request.base.sha || github.event.after }}"
restore-keys: "swiftpm-deploy-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-deploy-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-noble
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
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ================================
# Build image
# ================================
FROM swift:6.0-jammy as build
FROM swift:6.0-noble as build

ARG SWIFT_CONFIGURATION
ARG EXEC_NAME
Expand All @@ -26,7 +26,7 @@ RUN rm -dr .build
# ================================
# Run image
# ================================
FROM ubuntu:jammy
FROM ubuntu:noble

# Make sure all system packages are up to date, and install only essential packages.
RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \
Expand Down
64 changes: 64 additions & 0 deletions template-dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# ================================
# Build image
# ================================
FROM swift:6.0-noble AS build

WORKDIR /staging

# Copy entire repo into container
COPY . .

# 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 "$(swift build -c release --show-bin-path)/" -regex '.*\.resources$' -exec cp -Ra {} ./ \;

# 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 ./Public ] && { chmod -R a-w ./Public; } || true
RUN [ -d ./Resources ] && { chmod -R a-w ./Resources; } || true

# ================================
# Run image
# ================================
FROM ubuntu:noble

# Make sure all system packages are up to date, and install only essential packages.
RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \
&& apt-get -q update \
&& apt-get -q dist-upgrade -y \
&& apt-get -q install -y \
libjemalloc2 \
ca-certificates \
tzdata \
# If your app or its dependencies import FoundationNetworking, also install `libcurl4`.
# libcurl4 \
# If your app or its dependencies import FoundationXML, also install `libxml2`.
# libxml2 \
&& rm -r /var/lib/apt/lists/*

# Create a vapor user and group with /app as its home directory
RUN useradd --user-group --create-home --system --skel /dev/null --home-dir /app vapor

# Switch to the new home directory
WORKDIR /app

# Copy built executable and any staged resources from builder
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,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 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