WIP
Swift to test with a Docker
Init with swift package init --type executable
cd Sources
swift run server
Debug:
swift build
Release:
swift build -c release
swift package clean
swift package reset
podman run --rm \
-v "$PWD:/workspace" \
-w /workspace \
<SWIFT_DOCKER_IMAGE> \
/bin/bash -cl ' \
swift build && \
rm -rf .build/install && mkdir -p .build/install && \
cp -P .build/debug/NIOHTTP1Server .build/install/ && \
cp -P /usr/lib/swift/linux/lib*so* .build/install/'
podman run --rm \
-v "$PWD:/workspace" \
-w /workspace \
swift:5.10 \
/bin/bash -cl ' \
swift build && \
rm -rf .build/install && mkdir -p .build/install && \
cp -P .build/release/server .build/install/ && \
cp -P /usr/lib/swift/linux/lib*so* .build/install/'
Dockerfile example:
# 1
## <OPTIONAL_ARCHITECTURE>/swift:<TAG_VERSION>
#FROM swift:5.10.0
FROM amd64/swift:5.10.0
WORKDIR /app
COPY . .
# 2
#RUN apt-get update && apt-get install libsqlite3-dev
# 3
RUN swift package clean
RUN swift build
# 4
RUN mkdir /app/bin
RUN mv `swift build --show-bin-path` /app/bin
# 5
EXPOSE 9080
#ENTRYPOINT ./bin/debug/Run serve --env local --hostname 0.0.0.0
ENTRYPOINT ./bin/debug/server
First build it:
podman build . -tag <TAG>
Then save it:
podman save -o <OUTPUT_FILE> localhost/<TAG>
Send to the server:
scp <OUTPUT_FILE> <USERNAME>@<HOST>:~/
Add it to local podman instance:
podman load -i <OUTPUT_FILE>
Finally run it:
podman run -d --rmi -p 9080:9080 localhost/<TAG>
Remark: The is saved in the saved imaged, that's why we are using the same value from one machine to another
Remark:
In the Dockerfile, the image used is base on amd64
architecture because the targer server.
Swift Programming Language Book
(https://www.swift.org/documentation/server/guides/packaging.html)
(https://www.swift.org/documentation/server/guides/deploying/ubuntu.html)
Use of FoundationNetworking framework for Linux instead of Foundation:
Some types and related have been split out of Foundation
framework (only for Linux - MacOS still find those types in Foundation
).