Skip to content

Commit 48b4d96

Browse files
authored
Merge pull request #239 from fabianfett/ff-multiarch
Adds a buildx Dockerfile for ubuntu 20.04 supporting multiarch
2 parents 0943618 + 38e6a4e commit 48b4d96

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

ci_test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ def main():
7070
log_file = dockerfile.replace(docker_dir,"").replace("/", "_")
7171
log_file = "{}.log".format(log_file)
7272
cmd = "docker build --no-cache=true {}".format(dockerfile)
73+
if "buildx" in dockerfile:
74+
# if "buildx" is part of the path, we want to use the new buildx build system and build
75+
# for both amd64 and arm64.
76+
cmd = "docker buildx build --platform linux/arm64,linux/amd64 --no-cache=true {}".format(dockerfile)
7377
status = run_command(cmd, log_file)
7478
results[dockerfile] = status
7579
if status != 0:
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
FROM ubuntu:20.04 AS base
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+
binutils \
8+
git \
9+
gnupg2 \
10+
libc6-dev \
11+
libcurl4 \
12+
libedit2 \
13+
libgcc-9-dev \
14+
libpython3.8 \
15+
libsqlite3-0 \
16+
libstdc++-9-dev \
17+
libxml2 \
18+
libz3-dev \
19+
pkg-config \
20+
tzdata \
21+
zlib1g-dev \
22+
&& rm -r /var/lib/apt/lists/*
23+
24+
# Everything up to here should cache nicely between Swift versions, assuming dev dependencies change little
25+
26+
# gpg --keyid-format LONG -k FAF6989E1BC16FEA
27+
# pub rsa4096/FAF6989E1BC16FEA 2019-11-07 [SC] [expires: 2021-11-06]
28+
# 8A7495662C3CD4AE18D95637FAF6989E1BC16FEA
29+
# uid [ unknown] Swift Automatic Signing Key #3 <[email protected]>
30+
ARG SWIFT_SIGNING_KEY=8A7495662C3CD4AE18D95637FAF6989E1BC16FEA
31+
ARG SWIFT_PLATFORM=ubuntu
32+
ARG OS_MAJOR_VER=20
33+
ARG OS_MIN_VER=04
34+
ARG SWIFT_WEBROOT=https://swift.org/builds/development
35+
36+
# This is a small trick to enable if/else for arm64 and amd64.
37+
# Because of https://bugs.swift.org/browse/SR-14872 we need adjust tar options.
38+
FROM base AS base-amd64
39+
ARG OS_ARCH_SUFFIX=
40+
ARG ADDITIONAL_TAR_OPTIONS="--strip-components=1"
41+
42+
FROM base AS base-arm64
43+
ARG OS_ARCH_SUFFIX=-aarch64
44+
ARG ADDITIONAL_TAR_OPTIONS=
45+
46+
FROM base-$TARGETARCH AS final
47+
48+
ARG OS_VER=$SWIFT_PLATFORM$OS_MAJOR_VER.$OS_MIN_VER$OS_ARCH_SUFFIX
49+
ARG PLATFORM_WEBROOT="$SWIFT_WEBROOT/$SWIFT_PLATFORM$OS_MAJOR_VER$OS_MIN_VER$OS_ARCH_SUFFIX"
50+
51+
RUN echo "${PLATFORM_WEBROOT}/latest-build.yml"
52+
53+
RUN set -e; \
54+
# - Grab curl here so we cache better up above
55+
export DEBIAN_FRONTEND=noninteractive \
56+
&& apt-get -q update && apt-get -q install -y curl && rm -rf /var/lib/apt/lists/* \
57+
# - Latest Toolchain info
58+
&& export $(curl -s ${PLATFORM_WEBROOT}/latest-build.yml | grep 'download:' | sed 's/:[^:\/\/]/=/g') \
59+
&& export $(curl -s ${PLATFORM_WEBROOT}/latest-build.yml | grep 'download_signature:' | sed 's/:[^:\/\/]/=/g') \
60+
&& export DOWNLOAD_DIR=$(echo $download | sed "s/-${OS_VER}.tar.gz//g") \
61+
&& echo $DOWNLOAD_DIR > .swift_tag \
62+
# - Download the GPG keys, Swift toolchain, and toolchain signature, and verify.
63+
&& export GNUPGHOME="$(mktemp -d)" \
64+
&& curl -fsSL ${PLATFORM_WEBROOT}/${DOWNLOAD_DIR}/${download} -o latest_toolchain.tar.gz \
65+
${PLATFORM_WEBROOT}/${DOWNLOAD_DIR}/${download_signature} -o latest_toolchain.tar.gz.sig \
66+
&& curl -fSsL https://swift.org/keys/all-keys.asc | gpg --import - \
67+
&& gpg --batch --verify latest_toolchain.tar.gz.sig latest_toolchain.tar.gz \
68+
# - Unpack the toolchain, set libs permissions, and clean up.
69+
&& tar -xzf latest_toolchain.tar.gz --directory / ${ADDITIONAL_TAR_OPTIONS} \
70+
&& chmod -R o+r /usr/lib/swift \
71+
&& rm -rf "$GNUPGHOME" latest_toolchain.tar.gz.sig latest_toolchain.tar.gz \
72+
&& apt-get purge --auto-remove -y curl
73+
74+
# Print Installed Swift Version
75+
RUN swift --version
76+
77+
RUN echo '[ ! -z "$TERM" -a -r /etc/motd ] && cat /etc/motd' \
78+
>> /etc/bash.bashrc; \
79+
echo " ################################################################\n" \
80+
"#\t\t\t\t\t\t\t\t#\n" \
81+
"# Swift Nightly Docker Image\t\t\t\t\t#\n" \
82+
"# Tag: $(cat .swift_tag)\t\t\t#\n" \
83+
"#\t\t\t\t\t\t\t\t#\n" \
84+
"################################################################\n" > /etc/motd

0 commit comments

Comments
 (0)