Skip to content

improve docker setup #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
.out
.output
.DS_Store
1 change: 1 addition & 0 deletions platforms/Linux/centos/8/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.output
31 changes: 11 additions & 20 deletions platforms/Linux/centos/8/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# This source file is part of the Swift.org open source project
#
# Copyright (c) 2021 Apple Inc. and the Swift project authors
# Licensed under Apache License v2.0 with Runtime Library Exception
#
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors

FROM centos:8
LABEL PURPOSE="This image is configured to build Swift for the version of CentOS listed above"

WORKDIR /root

RUN yum -y update

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

# Add the spec
RUN mkdir -p /root/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
ADD swift-lang.spec /root/rpmbuild/SPECS/swift-lang.spec

# Install all the dependencies needed to build Swift from the spec file itself
RUN yum-builddep -y /root/rpmbuild/SPECS/swift-lang.spec

# Get the sources for Swift as defined in the spec file
RUN spectool -g -R /root/rpmbuild/SPECS/swift-lang.spec

# Add the patches
ADD patches/*.patch /root/rpmbuild/SOURCES/

# Add the driver script
ADD build_rpm.sh /root/build_rpm.sh
RUN chmod +x /root/build_rpm.sh

CMD ["/root/build_rpm.sh"]
# Optimization: Install all the dependencies needed to build Swift from the spec file itself
ADD swift-lang.spec /tmp/swift-lang.spec
RUN yum-builddep -y /tmp/swift-lang.spec
36 changes: 26 additions & 10 deletions platforms/Linux/centos/8/build_rpm.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,25 +1,41 @@
# This source file is part of the Swift.org open source project
#
# Copyright (c) 2021 Apple Inc. and the Swift project authors
# Licensed under Apache License v2.0 with Runtime Library Exception
#
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors

#!/usr/bin/env bash

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

OUTDIR=/out
if [[ ! -d "$OUTDIR" ]]
then
OUTDIR=/output
if [[ ! -d "$OUTDIR" ]]; then
echo "$OUTDIR does not exist, so no place to copy the artifacts!"
exit 1
fi

# Always make sure we're up to date
# always make sure we're up to date
yum update -y

# prepare direcoties
mkdir -p $HOME/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}

# Add the spec
cp swift-lang.spec $HOME/rpmbuild/SPECS/swift-lang.spec
# Add the patches
cp patches/*.patch $HOME/rpmbuild/SOURCES/

pushd $HOME/rpmbuild/SPECS
# install all the dependencies needed to build Swift from the spec file itself
yum-builddep -y ./swift-lang.spec
# get the sources for Swift as defined in the spec file
spectool -g -R ./swift-lang.spec
# Now we proceed to build Swift. If this is successful, we
# will have two files: a SRPM file which contains the source files
# as well as a regular RPM file that can be installed via `dnf' or `yum'
pushd $HOME/rpmbuild/SPECS
rpmbuild -ba ./swift-lang.spec 2>&1 | tee $HOME/build-output.txt
rpmbuild -ba ./swift-lang.spec 2>&1 | tee /root/build-output.txt
popd

# Include the build log which can be used to determine what went
Expand Down
36 changes: 36 additions & 0 deletions platforms/Linux/centos/8/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This source file is part of the Swift.org open source project
#
# Copyright (c) 2021 Apple Inc. and the Swift project authors
# Licensed under Apache License v2.0 with Runtime Library Exception
#
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors

version: "3"

services:

docker-setup:
image: centos8-rpm-builder
build:
context: .
dockerfile: Dockerfile

common: &common
image: centos8-rpm-builder
depends_on: [docker-setup]
volumes:
- .:/code:z
- ./.output:/output:z
working_dir: /code
cap_drop:
- CAP_NET_RAW
- CAP_NET_BIND_SERVICE

build:
<<: *common
command: /bin/bash -cl "./build_rpm.sh"

shell:
<<: *common
entrypoint: /bin/bash -l
26 changes: 18 additions & 8 deletions platforms/Linux/centos/8/readme.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
# Building Swift on CentOS Linux


### building with docker
### building with docker-compose

* to run the build end-to-end

Build the builder docker image, this will download the sources
```
docker-compose run build
```

* to enter the docker env in shell mode

```
docker build . -t rpm-builder
docker-compose run shell
```

Run the builder, this will run the build
then you can run `./build_rpm.sh` to run the build manually inside the docker


* to rebuild the base image

```
docker run -v `pwd`/.out:/out rpm-builder
docker-compose build --pull
```

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


Open Issues / Introduction
* the swift release version should be an argument
* 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
### Open Issues / TODO
* the swift release version should be an argument?
* the versions of source packages (eg yams) should come from an external file, likely one per swift release version
* 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)