Skip to content

Commit bdd1aba

Browse files
authored
Add slim images (#140)
Add "slim" images for Ubuntu 16.04 and 18.04. Slim images are images designed just for running an already built Swift program. Consequently, they do not contain the Swift compiler. The normal and slim images can be combined via a multi-stage `Dockerfile` to produce a lighter-weight image ready for deployment.
1 parent 0aafffe commit bdd1aba

File tree

5 files changed

+142
-107
lines changed

5 files changed

+142
-107
lines changed

5.0/ubuntu/16.04/slim/Dockerfile

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
FROM ubuntu:16.04
2+
LABEL maintainer="Swift Infrastructure <[email protected]>"
3+
LABEL Description="Docker Container for the Swift programming language"
4+
5+
RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true && apt-get -q update && \
6+
apt-get -q install -y \
7+
libatomic1 \
8+
libbsd0 \
9+
libcurl3 \
10+
libxml2 \
11+
tzdata \
12+
&& rm -r /var/lib/apt/lists/*
13+
14+
# Everything up to here should cache nicely between Swift versions, assuming dev dependencies change little
15+
ARG SWIFT_PLATFORM=ubuntu16.04
16+
ARG SWIFT_BRANCH=swift-5.0.1-release
17+
ARG SWIFT_VERSION=swift-5.0.1-RELEASE
18+
19+
ENV SWIFT_PLATFORM=$SWIFT_PLATFORM \
20+
SWIFT_BRANCH=$SWIFT_BRANCH \
21+
SWIFT_VERSION=$SWIFT_VERSION
22+
23+
# Download GPG keys, signature and Swift package, then unpack, cleanup and execute permissions for foundation libs
24+
RUN SWIFT_URL=https://swift.org/builds/$SWIFT_BRANCH/$(echo "$SWIFT_PLATFORM" | tr -d .)/$SWIFT_VERSION/$SWIFT_VERSION-$SWIFT_PLATFORM.tar.gz \
25+
&& apt-get update \
26+
&& apt-get install -y curl \
27+
&& curl -fSsL $SWIFT_URL -o swift.tar.gz \
28+
&& curl -fSsL $SWIFT_URL.sig -o swift.tar.gz.sig \
29+
&& export GNUPGHOME="$(mktemp -d)" \
30+
&& set -e; \
31+
for key in \
32+
# pub 4096R/ED3D1561 2019-03-22 [expires: 2021-03-21]
33+
# Key fingerprint = A62A E125 BBBF BB96 A6E0 42EC 925C C1CC ED3D 1561
34+
# uid Swift 5.x Release Signing Key <[email protected]>
35+
A62AE125BBBFBB96A6E042EC925CC1CCED3D1561 \
36+
; do \
37+
gpg --quiet --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \
38+
done \
39+
&& gpg --batch --verify --quiet swift.tar.gz.sig swift.tar.gz \
40+
&& tar -xzf swift.tar.gz --directory / --strip-components=1 $SWIFT_VERSION-$SWIFT_PLATFORM/usr/lib/swift/linux \
41+
&& apt-get purge -y curl \
42+
&& apt-get -y autoremove \
43+
&& rm -r /var/lib/apt/lists/* \
44+
&& rm -r "$GNUPGHOME" swift.tar.gz.sig swift.tar.gz \
45+
&& chmod -R o+r /usr/lib/swift

5.0/ubuntu/18.04/slim/Dockerfile

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
FROM ubuntu:18.04
2+
LABEL maintainer="Swift Infrastructure <[email protected]>"
3+
LABEL Description="Docker Container for the Swift programming language"
4+
5+
RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true && apt-get -q update && \
6+
apt-get -q install -y \
7+
libatomic1 \
8+
libbsd0 \
9+
libcurl4 \
10+
libxml2 \
11+
tzdata \
12+
&& rm -r /var/lib/apt/lists/*
13+
14+
# Everything up to here should cache nicely between Swift versions, assuming dev dependencies change little
15+
ARG SWIFT_PLATFORM=ubuntu18.04
16+
ARG SWIFT_BRANCH=swift-5.0.1-release
17+
ARG SWIFT_VERSION=swift-5.0.1-RELEASE
18+
19+
ENV SWIFT_PLATFORM=$SWIFT_PLATFORM \
20+
SWIFT_BRANCH=$SWIFT_BRANCH \
21+
SWIFT_VERSION=$SWIFT_VERSION
22+
23+
# Download GPG keys, signature and Swift package, then unpack, cleanup and execute permissions for foundation libs
24+
RUN SWIFT_URL=https://swift.org/builds/$SWIFT_BRANCH/$(echo "$SWIFT_PLATFORM" | tr -d .)/$SWIFT_VERSION/$SWIFT_VERSION-$SWIFT_PLATFORM.tar.gz \
25+
&& apt-get update \
26+
&& apt-get install -y curl gpg \
27+
&& curl -fSsL $SWIFT_URL -o swift.tar.gz \
28+
&& curl -fSsL $SWIFT_URL.sig -o swift.tar.gz.sig \
29+
&& export GNUPGHOME="$(mktemp -d)" \
30+
&& set -e; \
31+
for key in \
32+
# pub 4096R/ED3D1561 2019-03-22 [expires: 2021-03-21]
33+
# Key fingerprint = A62A E125 BBBF BB96 A6E0 42EC 925C C1CC ED3D 1561
34+
# uid Swift 5.x Release Signing Key <[email protected]>
35+
A62AE125BBBFBB96A6E042EC925CC1CCED3D1561 \
36+
; do \
37+
gpg --quiet --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \
38+
done \
39+
&& gpg --batch --verify --quiet swift.tar.gz.sig swift.tar.gz \
40+
&& tar -xzf swift.tar.gz --directory / --strip-components=1 $SWIFT_VERSION-$SWIFT_PLATFORM/usr/lib/swift/linux \
41+
&& apt-get purge -y curl gpg \
42+
&& apt-get -y autoremove \
43+
&& rm -r /var/lib/apt/lists/* \
44+
&& rm -r "$GNUPGHOME" swift.tar.gz.sig swift.tar.gz \
45+
&& chmod -R o+r /usr/lib/swift

Dockerfile.template

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

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# swift-docker
2+
3+
<img src="https://swift.org/assets/images/swift.svg" alt="Swift logo" height="70" >
4+
5+
### An Ubuntu 16.04 and Ubuntu 18.04 Docker image for [Swift](https://swift.org).
6+
7+
#### You can find the Docker Hub repo here: [https://hub.docker.com/_/swift/](https://hub.docker.com/_/swift/)
8+
9+
10+
### Usage
11+
12+
##### Pull the Docker image from Docker Hub:
13+
14+
```bash
15+
docker pull swift
16+
```
17+
18+
##### Create a container from the image and run it:
19+
20+
```bash
21+
docker run -it swift /bin/bash
22+
```
23+
24+
If you want to run the Swift REPL you will need to run the container with additional privileges:
25+
26+
```bash
27+
docker run --security-opt seccomp=unconfined -it swift
28+
```
29+
30+
We also provide a "slim" image. Slim images are images designed just for running an already built Swift program. Consequently, they do not contain the Swift compiler.
31+
32+
The normal and slim images can be combined via a multi-stage Dockerfile to produce a lighter-weight image ready for deployment. For example:
33+
34+
```dockerfile
35+
FROM swift:latest as builder
36+
WORKDIR /root
37+
COPY . .
38+
RUN swift build -c release
39+
40+
FROM swift:slim
41+
WORKDIR /root
42+
COPY --from=builder /root .
43+
CMD [".build/x86_64-unknown-linux/release/docker-test"]
44+
```
45+
46+
## Contributions
47+
48+
Contributions via pull requests are welcome and encouraged :)
49+
50+
## License
51+
52+
docker-swift is licensed under the [Apache License, Version 2.0](LICENSE.md).

Readme.md

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

0 commit comments

Comments
 (0)