Skip to content

Commit 5a76e5a

Browse files
authored
Merge pull request swiftlang#131 from apple/debian-docker-2
refactor debian packager
2 parents 3e6506c + b875a92 commit 5a76e5a

File tree

13 files changed

+250
-37
lines changed

13 files changed

+250
-37
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# This source file is part of the Swift.org open source project
2+
#
3+
# Copyright (c) 2022 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+
#!/bin/bash
10+
11+
set -eux
12+
13+
here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
14+
15+
# load version definitions
16+
. ${here}/versions.sh
17+
18+
# working in /tmp since docker file sharing makes this very slow to do dirctly on the share
19+
staging_dir=/tmp/swift-deb-builder
20+
package_dir=${staging_dir}/swiftlang-${debversion}
21+
22+
# clean
23+
rm -rf ${package_dir} && mkdir -p ${package_dir}
24+
25+
# copy control files to pakcage build directory
26+
cp -r ${here}/debian ${package_dir}/
27+
cp -r ${package_dir}/debian/control.in ${package_dir}/debian/control
28+
29+
# build the source package
30+
${here}/build_source_package.sh ${staging_dir}
31+
32+
# install the build dependencies
33+
cd ${staging_dir}
34+
mk-build-deps --install ${package_dir}/debian/control.in --tool 'apt-get -y -o Debug::pkgProblemResolver=yes --no-install-recommends'
35+
36+
# build the installable package
37+
# TODO: add signing key information
38+
cd ${package_dir}
39+
DEB_BUILD_OPTIONS=parallel=64 debuild
40+
41+
# copy the final packages to /output
42+
cd ${staging_dir}
43+
cp *.deb /output/
44+
cp *.ddeb /output/
45+
cp *.dsc /output/
46+
cp *.tar.* /output/

platforms/Linux/DEB/Ubuntu/focal/debian/getsource.sh renamed to platforms/Linux/DEB/Shared/build_source_package.sh

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# This source file is part of the Swift.org open source project
2+
#
3+
# Copyright (c) 2022 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
#!/bin/sh
210

311
# This helper script will fetch the Swift sources, save the
@@ -27,16 +35,22 @@
2735
# $ cd swiftlang-X.Y.Z
2836
# $ DEB_BUILD_OPTIONS=parallel=64 debuild
2937

30-
set -eu
38+
set -eux
3139

32-
. $(dirname $0)/source-versions.sh
40+
here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
41+
42+
# load version definitions
43+
. ${here}/versions.sh
44+
45+
staging_dir=$1
46+
package_dir=$staging_dir/swiftlang-${debversion}
3347

3448
get_component ()
3549
{
3650
component=$1
3751
url="$2"
3852

39-
dest=swiftlang_${debversion}.orig-${component}
53+
dest=${staging_dir}/swiftlang_${debversion}.orig-${component}
4054

4155
echo "Downloading ${component} from ${url}"
4256

@@ -69,8 +83,9 @@ get_component ()
6983
exit 1
7084
esac
7185

72-
mkdir swiftlang-${debversion}/${component}
73-
tar -C swiftlang-${debversion}/${component} --strip-components=1 -axf ${dest}
86+
echo "Extracting ${component}"
87+
mkdir ${package_dir}/${component}
88+
tar -C ${package_dir}/${component} --strip-components=1 -axf ${dest}
7489
}
7590

7691
get_component swift https://github.com/apple/swift/archive/swift-${swift_version}.tar.gz
@@ -112,7 +127,7 @@ get_component swift-markdown https://github.com/apple/swift-markdown/archive/swi
112127
if [ -s swiftlang-${debversion}/debian/patches/series ]; then
113128
cd swiftlang-${debversion}
114129

115-
export QUILT_PATCHES=debian/patches
130+
export QUILT_PATCHES=debian/patches
116131
export QUILT_REFRESH_ARGS="-p ab --no-timestamps --no-index"
117132

118133
while quilt push; do quilt refresh; done
@@ -121,6 +136,6 @@ if [ -s swiftlang-${debversion}/debian/patches/series ]; then
121136
cd -
122137
fi
123138

124-
cp -f swiftlang-${debversion}/debian/control.in swiftlang-${debversion}/debian/control
125-
126-
dpkg-source --create-empty-orig -b swiftlang-${debversion}
139+
# create a source package
140+
cd $staging_dir
141+
dpkg-source --create-empty-orig -b ${package_dir}

platforms/Linux/DEB/Shared/copyright

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
2+
Upstream-Name: Swift.org
3+
Upstream-Contact: Swift Maintainers <[email protected]>
4+
Source: https://github.com/apple/swift-installer-scripts
5+
6+
Files: *
7+
Copyright: Apple Inc. and the Swift project authors
8+
License: Apache-2.0
9+
10+
Files: debian/*
11+
Copyright: Apple Inc. and the Swift project authors
12+
License: Apache-2.0
13+
14+
License: Apache-2.0
15+
Licensed under the Apache License, Version 2.0 (the "License");
16+
you may not use this file except in compliance with the License.
17+
You may obtain a copy of the License at
18+
.
19+
https://www.apache.org/licenses/LICENSE-2.0
20+
.
21+
Unless required by applicable law or agreed to in writing, software
22+
distributed under the License is distributed on an "AS IS" BASIS,
23+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24+
See the License for the specific language governing permissions and
25+
limitations under the License.
26+
.
27+
On Debian systems, the complete text of the Apache version 2.0 license
28+
can be found in "/usr/share/common-licenses/Apache-2.0".
29+
30+
# Please also look if there are files or directories which have a
31+
# different copyright/license attached and list them here.
32+
# Please avoid picking licenses with terms that are more restrictive than the
33+
# packaged work, as it may make Debian's contributions unacceptable upstream.
34+
#
35+
# If you need, there are some extra license texts available in two places:
36+
# /usr/share/debhelper/dh_make/licenses/
37+
# /usr/share/common-licenses/

platforms/Linux/DEB/Ubuntu/README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,71 @@
11
## Ubuntu
2+
3+
Ubuntu uses the [Deb package format]() to install software packages.
4+
The Swift Deb package can be built either by creating a Linux container image or manually on a computer running Ubuntu.
5+
6+
There are separate directories for each version of Ubuntu.
7+
The instructions below are applicable to all versions.
8+
9+
## Important file and directories
10+
11+
**build_deb.sh**
12+
Driver file to build the deb package
13+
14+
**build_source.sh**
15+
Driver file to build the deb source package (which is a step in `build_deb`)
16+
17+
**patches/*.patch**
18+
Any post-release patches that have not yet been merged upstream that are temporarily necessary to build Swift.
19+
20+
**control.in**
21+
Debian package metadata, including the `BuildDepends` and `Depends` definitions.
22+
23+
**changelog**
24+
Debian package changelog
25+
26+
**rules**
27+
Debian package recipe
28+
29+
**Dockerfile**
30+
Defines the base docker image to run the install scripts in.
31+
32+
**docker-compose**
33+
Defines docker compose tasks to drive the pacakge build in Docker.
34+
35+
## Importand file and directories
36+
37+
**Shared/version.sh**
38+
Shell fragment versions.sh containing version information for all source components, and the Debian package upstream version (debversion).
39+
40+
**Shared/copyright**
41+
Copyright information
42+
43+
### Building with docker-compose
44+
45+
* to run the build end-to-end
46+
47+
```
48+
docker-compose run build
49+
```
50+
51+
* to enter the docker env in shell mode
52+
53+
```
54+
docker-compose run shell
55+
```
56+
57+
then you can run `./build_deb.sh` to run the build manually inside the docker
58+
59+
60+
* to rebuild the base image
61+
62+
```
63+
docker-compose build --pull
64+
```
65+
66+
note this still uses the docker cache, so will rebuild only if the version of the underlying base image changed upstream
67+
68+
### Building locally on an Ubuntu machine
69+
70+
1. Install required development tools (see Dockerfile)
71+
2. Run `./build_deb.sh`
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.output
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# This source file is part of the Swift.org open source project
2+
#
3+
# Copyright (c) 2022 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+
FROM ubuntu:focal
10+
LABEL PURPOSE="This image is configured to build Swift for the version of Ubuntu listed above"
11+
12+
ARG DEBIAN_FRONTEND=noninteractive
13+
14+
RUN apt-get update
15+
16+
# Required deb packaging tools
17+
RUN apt-get install -y curl devscripts equivs quilt tar
18+
19+
# Optimization: Install Swift build requirements listed in the control file
20+
ADD debian/control.in /tmp/control.in
21+
RUN mk-build-deps --install /tmp/control.in --tool 'apt-get -y -o Debug::pkgProblemResolver=yes --no-install-recommends'

platforms/Linux/DEB/Ubuntu/focal/README.md

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../Shared/build_deb.sh
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../Shared/build_source_package.sh

platforms/Linux/DEB/Ubuntu/focal/debian/copyright

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../Shared/copyright
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# This source file is part of the Swift.org open source project
2+
#
3+
# Copyright (c) 2022 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+
# this setup is designed to build the Deb with docker
10+
# usage:
11+
# docker-compose -f platforms/Linux/DEB/ubuntu/focal/docker-compose.yaml run build
12+
13+
# to rebuild the base image
14+
# docker-compose -f platforms/Linux/DEB/ubuntu/focal/docker-compose.yaml build
15+
16+
# to shell into the container for debugging purposes:
17+
# docker-compose -f platforms/Linux/DEB/ubuntu/focal/docker-compose.yaml run shell
18+
19+
version: "2"
20+
21+
services:
22+
23+
docker-setup:
24+
image: ubuntu-focal-deb-builder
25+
build:
26+
context: .
27+
dockerfile: Dockerfile
28+
29+
common: &common
30+
image: ubuntu-focal-deb-builder
31+
depends_on: [docker-setup]
32+
volumes:
33+
- ../../Ubuntu/focal:/code/Ubuntu/focal:z
34+
- ../../Shared:/code/Shared:z
35+
- ./.output:/output:z
36+
working_dir: /code/Ubuntu/focal
37+
cap_drop:
38+
- CAP_NET_RAW
39+
- CAP_NET_BIND_SERVICE
40+
41+
build:
42+
<<: *common
43+
command: /bin/bash -cl "./build_deb.sh"
44+
45+
shell:
46+
<<: *common
47+
entrypoint: /bin/bash -l
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../Shared/versions.sh

0 commit comments

Comments
 (0)