diff --git a/.gitignore b/.gitignore index a52722c3..146c62e8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -.out +.output .DS_Store diff --git a/platforms/Linux/centos/8/.dockerignore b/platforms/Linux/centos/8/.dockerignore new file mode 100644 index 00000000..16ff3c79 --- /dev/null +++ b/platforms/Linux/centos/8/.dockerignore @@ -0,0 +1 @@ +.output diff --git a/platforms/Linux/centos/8/Dockerfile b/platforms/Linux/centos/8/Dockerfile index bd6f4780..21d39173 100644 --- a/platforms/Linux/centos/8/Dockerfile +++ b/platforms/Linux/centos/8/Dockerfile @@ -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 @@ -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 diff --git a/platforms/Linux/centos/8/build_rpm.sh b/platforms/Linux/centos/8/build_rpm.sh old mode 100644 new mode 100755 index 77922daf..fb0cad96 --- a/platforms/Linux/centos/8/build_rpm.sh +++ b/platforms/Linux/centos/8/build_rpm.sh @@ -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 diff --git a/platforms/Linux/centos/8/docker-compose.yaml b/platforms/Linux/centos/8/docker-compose.yaml new file mode 100644 index 00000000..dd4b921e --- /dev/null +++ b/platforms/Linux/centos/8/docker-compose.yaml @@ -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 diff --git a/platforms/Linux/centos/8/readme.md b/platforms/Linux/centos/8/readme.md index 529c7b9f..65a7008e 100644 --- a/platforms/Linux/centos/8/readme.md +++ b/platforms/Linux/centos/8/readme.md @@ -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)