|
1 | 1 | # ================================ |
2 | 2 | # Build image |
3 | 3 | # ================================ |
4 | | -FROM swift:5.3-focal as build |
5 | | - |
6 | | -# Install OS updates and, if needed, sqlite3 |
7 | | -RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \ |
8 | | - && apt-get -q update \ |
9 | | - && apt-get -q dist-upgrade -y \ |
10 | | - && rm -rf /var/lib/apt/lists/* |
11 | | - |
12 | | -# Set up a build area |
| 4 | +FROM vapor/swift:5.2 as build |
13 | 5 | WORKDIR /build |
14 | 6 |
|
15 | | -# First just resolve dependencies. |
16 | | -# This creates a cached layer that can be reused |
17 | | -# as long as your Package.swift/Package.resolved |
18 | | -# files do not change. |
19 | | -COPY ./Package.* ./ |
20 | | -RUN swift package resolve |
21 | | - |
22 | 7 | # Copy entire repo into container |
23 | 8 | COPY . . |
24 | 9 |
|
25 | | -# Build everything, with optimizations and test discovery |
26 | | -RUN swift build --enable-test-discovery -c release |
27 | | - |
28 | | -# Switch to the staging area |
29 | | -WORKDIR /staging |
30 | | - |
31 | | -# Copy main executable to staging area |
32 | | -RUN cp "$(swift build --package-path /build -c release --show-bin-path)/Run" ./ |
| 10 | +# Compile with optimizations |
| 11 | +RUN swift build \ |
| 12 | + --enable-test-discovery \ |
| 13 | + -c release \ |
| 14 | + -Xswiftc -g |
33 | 15 |
|
34 | | -# Copy any resouces from the public directory and views directory if the directories exist |
35 | | -# Ensure that by default, neither the directory nor any of its contents are writable. |
36 | | -RUN [ -d /build/Public ] && { mv /build/Public ./Public && chmod -R a-w ./Public; } || true |
37 | | -RUN [ -d /build/Resources ] && { mv /build/Resources ./Resources && chmod -R a-w ./Resources; } || true |
38 | 16 |
|
39 | 17 | # ================================ |
40 | 18 | # Run image |
41 | 19 | # ================================ |
42 | | -FROM swift:5.3-focal-slim |
43 | | - |
44 | | -# Make sure all system packages are up to date. |
45 | | -RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true && \ |
46 | | - apt-get -q update && apt-get -q dist-upgrade -y && rm -r /var/lib/apt/lists/* |
47 | | - |
48 | | -# Create a vapor user and group with /app as its home directory |
49 | | -RUN useradd --user-group --create-home --system --skel /dev/null --home-dir /app vapor |
50 | | - |
51 | | -# Switch to the new home directory |
52 | | -WORKDIR /app |
53 | | - |
54 | | -# Copy built executable and any staged resources from builder |
55 | | -COPY --from=build --chown=vapor:vapor /staging /app |
56 | | - |
57 | | -# Ensure all further commands run as the vapor user |
58 | | -USER vapor:vapor |
| 20 | +FROM vapor/ubuntu:18.04 |
| 21 | +WORKDIR /run |
59 | 22 |
|
60 | | -# Let Docker bind to port 8080 |
61 | | -EXPOSE 8080 |
| 23 | +# Copy build artifacts |
| 24 | +COPY --from=build /build/.build/release /run |
| 25 | +# Copy Swift runtime libraries |
| 26 | +COPY --from=build /usr/lib/swift/ /usr/lib/swift/ |
| 27 | +# Uncomment the next line if you need to load resources from the `Public` directory |
| 28 | +COPY --from=build /build/Public /run/Public |
62 | 29 |
|
63 | | -# Start the Vapor service when the image is run, default to listening on 8080 in production environment |
64 | 30 | ENTRYPOINT ["./Run"] |
65 | | -CMD ["serve", "--env", "production", "--hostname", "0.0.0.0", "--port", "8080"] |
| 31 | +CMD ["serve", "--env", "production", "--hostname", "0.0.0.0"] |
0 commit comments