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

Update to match latest vapor template + expose test env variables for… #8

Merged
merged 3 commits into from
Jan 21, 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
9 changes: 9 additions & 0 deletions .env.testing
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Please don't molest this sample firebase project. I'm exposing these credentials for your convenience, and I
# will disable the project it it's causing me a headache. You should create your own
# firebase project (it's free) and generate your own credentials.
FIREBASE_PROJECT_ID=vapor-saas-backend-template
TEST_FIREBASE_WEB_API_KEY=AIzaSyAesbeFK6uCEvYZNCJZN0bs-Ab9Ya01Egg
[email protected]
TEST_FIREBASE_USER_PASSWORD=testtest
TEST_FIREBASE_USER_2_EMAIL=saastemplatetestuser2@indiepitcher.com
TEST_FIREBASE_USER_2_PASSWORD=testtest
7 changes: 0 additions & 7 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,4 @@ jobs:
- name: Build
run: swift build -v
- name: Run tests
env:
TEST_FIREBASE_WEB_API_KEY: ${{ secrets.TEST_FIREBASE_WEB_API_KEY }}
TEST_FIREBASE_USER_EMAIL: ${{ secrets.TEST_FIREBASE_USER_EMAIL }}
TEST_FIREBASE_USER_PASSWORD: ${{ secrets.TEST_FIREBASE_USER_PASSWORD }}
TEST_FIREBASE_USER_2_EMAIL: ${{ secrets.TEST_FIREBASE_USER_2_EMAIL }}
TEST_FIREBASE_USER_2_PASSWORD: ${{ secrets.TEST_FIREBASE_USER_2_PASSWORD }}
FIREBASE_PROJECT_ID: ${{ secrets.FIREBASE_PROJECT_ID }}
run: swift test -v
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ DerivedData/
db.sqlite
.swiftpm
.env
/.env.testing
28 changes: 28 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"configurations": [
{
"type": "lldb",
"request": "launch",
"sourceLanguages": [
"swift"
],
"args": [],
"cwd": "${workspaceFolder:vapor-saas-backend-template}",
"name": "Debug App",
"program": "${workspaceFolder:vapor-saas-backend-template}/.build/debug/App",
"preLaunchTask": "swift: Build Debug App"
},
{
"type": "lldb",
"request": "launch",
"sourceLanguages": [
"swift"
],
"args": [],
"cwd": "${workspaceFolder:vapor-saas-backend-template}",
"name": "Release App",
"program": "${workspaceFolder:vapor-saas-backend-template}/.build/release/App",
"preLaunchTask": "swift: Build Release App"
}
]
}
24 changes: 14 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ FROM swift:5.9-jammy as build
# Install OS updates
RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \
&& apt-get -q update \
&& apt-get -q dist-upgrade -y\
&& rm -rf /var/lib/apt/lists/*
&& apt-get -q dist-upgrade -y \
&& apt-get install -y libjemalloc-dev

# Set up a build area
WORKDIR /build
Expand All @@ -23,18 +23,21 @@ RUN swift package resolve --skip-update \
# Copy entire repo into container
COPY . .

# Build everything, with optimizations
RUN swift build -c release --static-swift-stdlib \
# Workaround for https://github.com/apple/swift/pull/68669
# This can be removed as soon as 5.9.1 is released, but is harmless if left in.
-Xlinker -u -Xlinker _swift_backtrace_isThunkFunction
# 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 \
--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)/App" ./

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

Expand All @@ -46,13 +49,14 @@ RUN [ -d /build/Resources ] && { mv /build/Resources ./Resources && chmod -R a-w
# ================================
# Run image
# ================================
FROM swift:5.9-jammy-slim
FROM ubuntu:jammy

# 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`.
Expand All @@ -71,7 +75,7 @@ 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_ROOT=/usr SWIFT_BACKTRACE=enable=yes,sanitize=yes,threads=all,images=all,interactive=no
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
Expand All @@ -81,4 +85,4 @@ EXPOSE 8080

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