Skip to content

Commit a6c1c20

Browse files
committed
Docker and static files working
1 parent e304be9 commit a6c1c20

File tree

8 files changed

+323
-81
lines changed

8 files changed

+323
-81
lines changed

.dockerignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
11
.build/
2+
.env
3+
*.env
4+
*.md
5+
*.old
26
.swiftpm/
7+
*.sh
8+
tmp/
9+
*.tmp

Dockerfile

Lines changed: 15 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,31 @@
11
# ================================
22
# Build image
33
# ================================
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
135
WORKDIR /build
146

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-
227
# Copy entire repo into container
238
COPY . .
249

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
3315

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
3816

3917
# ================================
4018
# Run image
4119
# ================================
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
5922

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
6229

63-
# Start the Vapor service when the image is run, default to listening on 8080 in production environment
6430
ENTRYPOINT ["./Run"]
65-
CMD ["serve", "--env", "production", "--hostname", "0.0.0.0", "--port", "8080"]
31+
CMD ["serve", "--env", "production", "--hostname", "0.0.0.0"]

Public/favicon.ico

87.9 KB
Binary file not shown.

Public/favicon.svg

Lines changed: 271 additions & 0 deletions
Loading

Public/robots.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#
2+
# just a backend for the main RegexPlanet.com site: go there to index stuff!
3+
#
4+
User-agent: *
5+
Disallow: /

Sources/App/configure.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import Vapor
22

33
// configures your application
44
public func configure(_ app: Application) throws {
5-
// uncomment to serve files from /Public folder
6-
// app.middleware.use(FileMiddleware(publicDirectory: app.directory.publicDirectory))
5+
app.middleware.use(FileMiddleware(publicDirectory: app.directory.publicDirectory))
76

87
// register routes
98
try routes(app)

docker-compose.yml

Lines changed: 0 additions & 30 deletions
This file was deleted.

docker-run.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env bash
2+
#
3+
# run it in Docker
4+
#
5+
6+
set -o errexit
7+
set -o pipefail
8+
set -o nounset
9+
10+
ENVFILE=".env"
11+
12+
if [ -f "${ENVFILE}" ]
13+
then
14+
export $(cat "${ENVFILE}")
15+
fi
16+
17+
18+
DOCKER_BUILDKIT=1 docker build -t regexplanet-swift .
19+
20+
docker run -it \
21+
-p 8080:8080 \
22+
-e LOG_LEVEL=${LOG_LEVEL:-trace} \
23+
-e PORT=8080 \
24+
regexplanet-swift

0 commit comments

Comments
 (0)