-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
47 lines (37 loc) · 1.55 KB
/
Copy pathDockerfile
File metadata and controls
47 lines (37 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# ================================
# Build image
# ================================
FROM swift:6.0-bookworm AS build
RUN apt-get -q update && apt-get -q install -y libjemalloc-dev
WORKDIR /build
COPY ./Package.* ./
RUN swift package resolve \
$([ -f ./Package.resolved ] && echo "--force-resolved-versions" || true)
COPY . .
RUN swift build -c release \
--product backend \
--static-swift-stdlib \
-Xlinker -ljemalloc
WORKDIR /staging
RUN cp "$(swift build --package-path /build -c release --show-bin-path)/backend" ./ \
&& cp "/usr/libexec/swift/linux/swift-backtrace-static" ./ \
&& strip ./backend ./swift-backtrace-static || true \
&& find -L "$(swift build --package-path /build -c release --show-bin-path)/" -regex '.*\.resources$' -exec cp -Ra {} ./ \; \
&& [ -d /build/Public ] && { mv /build/Public ./Public && chmod -R a-w ./Public; } || true \
&& [ -d /build/Resources ] && { mv /build/Resources ./Resources && chmod -R a-w ./Resources; } || true
# ================================
# Run image
# ================================
FROM debian:bookworm-slim
RUN apt-get -q update && apt-get -q install -y \
libjemalloc2 \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
RUN useradd --user-group --create-home --system --skel /dev/null --home-dir /app vapor
WORKDIR /app
COPY --from=build --chown=vapor:vapor /staging /app
ENV SWIFT_BACKTRACE=enable=no,sanitize=yes,threads=all,images=all,interactive=no
USER vapor:vapor
EXPOSE 8080
ENTRYPOINT ["./backend"]
CMD ["serve", "--env", "production", "--hostname", "0.0.0.0", "--port", "8080"]