Skip to content

Commit 14238eb

Browse files
authored
improve docker setup (swiftlang#32)
motivation: make it easier to run the build changes: * use docker-compose to orchestrate the build * udpate docker file to only be focused on basic build requirments * expand build_rpm.sh to do the build end-to-end * update readme with details on how to use the new setup
1 parent 3e4112a commit 14238eb

File tree

6 files changed

+93
-39
lines changed

6 files changed

+93
-39
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
.out
1+
.output
22
.DS_Store
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.output

platforms/Linux/centos/8/Dockerfile

+11-20
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1+
# This source file is part of the Swift.org open source project
2+
#
3+
# Copyright (c) 2021 Apple Inc. and the Swift project authors
4+
# Licensed under Apache License v2.0 with Runtime Library Exception
5+
#
6+
# See http://swift.org/LICENSE.txt for license information
7+
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
8+
19
FROM centos:8
210
LABEL PURPOSE="This image is configured to build Swift for the version of CentOS listed above"
311

4-
WORKDIR /root
5-
612
RUN yum -y update
713

814
# RPM and yum development tools
@@ -12,21 +18,6 @@ RUN yum install -y rpmdevtools yum-utils
1218
RUN yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
1319
RUN yum config-manager --set-enabled powertools
1420

15-
# Add the spec
16-
RUN mkdir -p /root/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
17-
ADD swift-lang.spec /root/rpmbuild/SPECS/swift-lang.spec
18-
19-
# Install all the dependencies needed to build Swift from the spec file itself
20-
RUN yum-builddep -y /root/rpmbuild/SPECS/swift-lang.spec
21-
22-
# Get the sources for Swift as defined in the spec file
23-
RUN spectool -g -R /root/rpmbuild/SPECS/swift-lang.spec
24-
25-
# Add the patches
26-
ADD patches/*.patch /root/rpmbuild/SOURCES/
27-
28-
# Add the driver script
29-
ADD build_rpm.sh /root/build_rpm.sh
30-
RUN chmod +x /root/build_rpm.sh
31-
32-
CMD ["/root/build_rpm.sh"]
21+
# Optimization: Install all the dependencies needed to build Swift from the spec file itself
22+
ADD swift-lang.spec /tmp/swift-lang.spec
23+
RUN yum-builddep -y /tmp/swift-lang.spec

platforms/Linux/centos/8/build_rpm.sh

100644100755
+26-10
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,41 @@
1+
# This source file is part of the Swift.org open source project
2+
#
3+
# Copyright (c) 2021 Apple Inc. and the Swift project authors
4+
# Licensed under Apache License v2.0 with Runtime Library Exception
5+
#
6+
# See http://swift.org/LICENSE.txt for license information
7+
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
8+
19
#!/usr/bin/env bash
210

3-
# This script assumes it's running in a container as root
4-
# and that /out is mounted to a directory on the local
5-
# filesystem so the build output and artifacts can be
6-
# copied out and used
11+
set +ex
712

8-
OUTDIR=/out
9-
if [[ ! -d "$OUTDIR" ]]
10-
then
13+
OUTDIR=/output
14+
if [[ ! -d "$OUTDIR" ]]; then
1115
echo "$OUTDIR does not exist, so no place to copy the artifacts!"
1216
exit 1
1317
fi
1418

15-
# Always make sure we're up to date
19+
# always make sure we're up to date
1620
yum update -y
1721

22+
# prepare direcoties
23+
mkdir -p $HOME/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
24+
25+
# Add the spec
26+
cp swift-lang.spec $HOME/rpmbuild/SPECS/swift-lang.spec
27+
# Add the patches
28+
cp patches/*.patch $HOME/rpmbuild/SOURCES/
29+
30+
pushd $HOME/rpmbuild/SPECS
31+
# install all the dependencies needed to build Swift from the spec file itself
32+
yum-builddep -y ./swift-lang.spec
33+
# get the sources for Swift as defined in the spec file
34+
spectool -g -R ./swift-lang.spec
1835
# Now we proceed to build Swift. If this is successful, we
1936
# will have two files: a SRPM file which contains the source files
2037
# as well as a regular RPM file that can be installed via `dnf' or `yum'
21-
pushd $HOME/rpmbuild/SPECS
22-
rpmbuild -ba ./swift-lang.spec 2>&1 | tee $HOME/build-output.txt
38+
rpmbuild -ba ./swift-lang.spec 2>&1 | tee /root/build-output.txt
2339
popd
2440

2541
# Include the build log which can be used to determine what went
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# This source file is part of the Swift.org open source project
2+
#
3+
# Copyright (c) 2021 Apple Inc. and the Swift project authors
4+
# Licensed under Apache License v2.0 with Runtime Library Exception
5+
#
6+
# See http://swift.org/LICENSE.txt for license information
7+
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
8+
9+
version: "3"
10+
11+
services:
12+
13+
docker-setup:
14+
image: centos8-rpm-builder
15+
build:
16+
context: .
17+
dockerfile: Dockerfile
18+
19+
common: &common
20+
image: centos8-rpm-builder
21+
depends_on: [docker-setup]
22+
volumes:
23+
- .:/code:z
24+
- ./.output:/output:z
25+
working_dir: /code
26+
cap_drop:
27+
- CAP_NET_RAW
28+
- CAP_NET_BIND_SERVICE
29+
30+
build:
31+
<<: *common
32+
command: /bin/bash -cl "./build_rpm.sh"
33+
34+
shell:
35+
<<: *common
36+
entrypoint: /bin/bash -l

platforms/Linux/centos/8/readme.md

+18-8
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,33 @@
11
# Building Swift on CentOS Linux
22

33

4-
### building with docker
4+
### building with docker-compose
55

6+
* to run the build end-to-end
67

7-
Build the builder docker image, this will download the sources
8+
```
9+
docker-compose run build
10+
```
11+
12+
* to enter the docker env in shell mode
813

914
```
10-
docker build . -t rpm-builder
15+
docker-compose run shell
1116
```
1217

13-
Run the builder, this will run the build
18+
then you can run `./build_rpm.sh` to run the build manually inside the docker
19+
20+
21+
* to rebuild the base image
1422

1523
```
16-
docker run -v `pwd`/.out:/out rpm-builder
24+
docker-compose build --pull
1725
```
1826

27+
note this still uses the docker cache, so will rebuild only if the version of the underlying base image changed upstream
28+
1929

20-
Open Issues / Introduction
21-
* the swift release version should be an argument
22-
* the versions of source packages are no pinned to the swift release version (eg yams) should come from an external file, likely one per swift release version
30+
### Open Issues / TODO
31+
* the swift release version should be an argument?
32+
* the versions of source packages (eg yams) should come from an external file, likely one per swift release version
2333
* the list of build requirements (BuildRequires) and especially requirements (Requires) should come from an external file, likely one per swift release version (which we can use it to also drive documentation)

0 commit comments

Comments
 (0)