app-emulation/docker: Stable on amd64
[gentoo.git] / app-emulation / docker / docker-18.09.3.ebuild
1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=6
5
6 EGO_PN="github.com/docker/docker-ce"
7
8 if [[ ${PV} = *9999* ]]; then
9         # Docker cannot be fetched via "go get", thanks to autogenerated code
10         EGIT_REPO_URI="https://${EGO_PN}.git"
11         EGIT_CHECKOUT_DIR="${WORKDIR}/${P}/src/${EGO_PN}"
12         inherit git-r3
13 else
14         DOCKER_GITCOMMIT="774a1f4"
15         SRC_URI="https://${EGO_PN}/archive/v${PV}.tar.gz -> ${P}.tar.gz"
16         KEYWORDS="~amd64 ~arm ~arm64"
17         [ "$DOCKER_GITCOMMIT" ] || die "DOCKER_GITCOMMIT must be added manually for each bump!"
18         inherit golang-vcs-snapshot
19 fi
20 inherit bash-completion-r1 golang-base linux-info systemd udev user
21
22 DESCRIPTION="The core functions you need to create Docker images and run Docker containers"
23 HOMEPAGE="https://dockerproject.org"
24 LICENSE="Apache-2.0"
25 SLOT="0"
26 IUSE="apparmor aufs btrfs +container-init device-mapper hardened +overlay pkcs11 seccomp"
27
28 # https://github.com/docker/docker/blob/master/project/PACKAGERS.md#build-dependencies
29 CDEPEND="
30         >=dev-db/sqlite-3.7.9:3
31         device-mapper? (
32                 >=sys-fs/lvm2-2.02.89[thin]
33         )
34         seccomp? ( >=sys-libs/libseccomp-2.2.1 )
35         apparmor? ( sys-libs/libapparmor )
36 "
37
38 DEPEND="
39         ${CDEPEND}
40
41         dev-go/go-md2man
42
43         btrfs? (
44                 >=sys-fs/btrfs-progs-3.16.1
45         )
46 "
47
48 # https://github.com/docker/docker/blob/master/project/PACKAGERS.md#runtime-dependencies
49 # https://github.com/docker/docker/blob/master/project/PACKAGERS.md#optional-dependencies
50 RDEPEND="
51         ${CDEPEND}
52         >=net-firewall/iptables-1.4
53         sys-process/procps
54         >=dev-vcs/git-1.7
55         >=app-arch/xz-utils-4.9
56         dev-libs/libltdl
57         ~app-emulation/containerd-1.2.2
58         ~app-emulation/runc-1.0.0_rc6_p20181203[apparmor?,seccomp?]
59         >=app-emulation/runc-1.0.0_rc6_p20181203-r1
60         ~app-emulation/docker-proxy-0.8.0_p20181207
61         container-init? ( >=sys-process/tini-0.18.0[static] )
62 "
63
64 RESTRICT="installsources strip"
65
66 S="${WORKDIR}/${P}/src/${EGO_PN}"
67
68 # see "contrib/check-config.sh" from upstream's sources
69 CONFIG_CHECK="
70         ~NAMESPACES ~NET_NS ~PID_NS ~IPC_NS ~UTS_NS
71         ~CGROUPS ~CGROUP_CPUACCT ~CGROUP_DEVICE ~CGROUP_FREEZER ~CGROUP_SCHED ~CPUSETS ~MEMCG
72         ~KEYS
73         ~VETH ~BRIDGE ~BRIDGE_NETFILTER
74         ~NF_NAT_IPV4 ~IP_NF_FILTER ~IP_NF_TARGET_MASQUERADE
75         ~NETFILTER_XT_MATCH_ADDRTYPE ~NETFILTER_XT_MATCH_CONNTRACK ~NETFILTER_XT_MATCH_IPVS
76         ~IP_NF_NAT ~NF_NAT ~NF_NAT_NEEDED
77         ~POSIX_MQUEUE
78
79         ~USER_NS
80         ~SECCOMP
81         ~CGROUP_PIDS
82         ~MEMCG_SWAP ~MEMCG_SWAP_ENABLED
83
84         ~BLK_CGROUP ~BLK_DEV_THROTTLING ~IOSCHED_CFQ ~CFQ_GROUP_IOSCHED
85         ~CGROUP_PERF
86         ~CGROUP_HUGETLB
87         ~NET_CLS_CGROUP
88         ~CFS_BANDWIDTH ~FAIR_GROUP_SCHED ~RT_GROUP_SCHED
89         ~IP_VS ~IP_VS_PROTO_TCP ~IP_VS_PROTO_UDP ~IP_VS_NFCT ~IP_VS_RR
90
91         ~VXLAN
92         ~CRYPTO ~CRYPTO_AEAD ~CRYPTO_GCM ~CRYPTO_SEQIV ~CRYPTO_GHASH ~XFRM_ALGO ~XFRM_USER
93         ~IPVLAN
94         ~MACVLAN ~DUMMY
95 "
96
97 ERROR_KEYS="CONFIG_KEYS: is mandatory"
98 ERROR_MEMCG_SWAP="CONFIG_MEMCG_SWAP: is required if you wish to limit swap usage of containers"
99 ERROR_RESOURCE_COUNTERS="CONFIG_RESOURCE_COUNTERS: is optional for container statistics gathering"
100
101 ERROR_BLK_CGROUP="CONFIG_BLK_CGROUP: is optional for container statistics gathering"
102 ERROR_IOSCHED_CFQ="CONFIG_IOSCHED_CFQ: is optional for container statistics gathering"
103 ERROR_CGROUP_PERF="CONFIG_CGROUP_PERF: is optional for container statistics gathering"
104 ERROR_CFS_BANDWIDTH="CONFIG_CFS_BANDWIDTH: is optional for container statistics gathering"
105 ERROR_XFRM_ALGO="CONFIG_XFRM_ALGO: is optional for secure networks"
106 ERROR_XFRM_USER="CONFIG_XFRM_USER: is optional for secure networks"
107
108 pkg_setup() {
109         if kernel_is lt 3 10; then
110                 ewarn ""
111                 ewarn "Using Docker with kernels older than 3.10 is unstable and unsupported."
112                 ewarn " - http://docs.docker.com/engine/installation/binaries/#check-kernel-dependencies"
113         fi
114
115         if kernel_is le 3 18; then
116                 CONFIG_CHECK+="
117                         ~RESOURCE_COUNTERS
118                 "
119         fi
120
121         if kernel_is le 3 13; then
122                 CONFIG_CHECK+="
123                         ~NETPRIO_CGROUP
124                 "
125         else
126                 CONFIG_CHECK+="
127                         ~CGROUP_NET_PRIO
128                 "
129         fi
130
131         if kernel_is lt 4 5; then
132                 CONFIG_CHECK+="
133                         ~MEMCG_KMEM
134                 "
135                 ERROR_MEMCG_KMEM="CONFIG_MEMCG_KMEM: is optional"
136         fi
137
138         if kernel_is lt 4 7; then
139                 CONFIG_CHECK+="
140                         ~DEVPTS_MULTIPLE_INSTANCES
141                 "
142         fi
143
144         if use aufs; then
145                 CONFIG_CHECK+="
146                         ~AUFS_FS
147                         ~EXT4_FS_POSIX_ACL ~EXT4_FS_SECURITY
148                 "
149                 ERROR_AUFS_FS="CONFIG_AUFS_FS: is required to be set if and only if aufs-sources are used instead of aufs4/aufs3"
150         fi
151
152         if use btrfs; then
153                 CONFIG_CHECK+="
154                         ~BTRFS_FS
155                         ~BTRFS_FS_POSIX_ACL
156                 "
157         fi
158
159         if use device-mapper; then
160                 CONFIG_CHECK+="
161                         ~BLK_DEV_DM ~DM_THIN_PROVISIONING ~EXT4_FS ~EXT4_FS_POSIX_ACL ~EXT4_FS_SECURITY
162                 "
163         fi
164
165         if use overlay; then
166                 CONFIG_CHECK+="
167                         ~OVERLAY_FS ~EXT4_FS_SECURITY ~EXT4_FS_POSIX_ACL
168                 "
169         fi
170
171         linux-info_pkg_setup
172
173         # create docker group for the code checking for it in /etc/group
174         enewgroup docker
175 }
176
177 src_compile() {
178         export GOPATH="${WORKDIR}/${P}"
179
180         # setup CFLAGS and LDFLAGS for separate build target
181         # see https://github.com/tianon/docker-overlay/pull/10
182         export CGO_CFLAGS="-I${ROOT}/usr/include"
183         export CGO_LDFLAGS="-L${ROOT}/usr/$(get_libdir)"
184
185         # if we're building from a tarball, we need the GITCOMMIT value
186         [ "$DOCKER_GITCOMMIT" ] && export DOCKER_GITCOMMIT
187
188         # fake golang layout
189         ln -s docker-ce/components/engine ../docker || die
190         ln -s docker-ce/components/cli ../cli || die
191
192         # let's set up some optional features :)
193         export DOCKER_BUILDTAGS=''
194         for gd in aufs btrfs device-mapper overlay; do
195                 if ! use $gd; then
196                         DOCKER_BUILDTAGS+=" exclude_graphdriver_${gd//-/}"
197                 fi
198         done
199
200         for tag in apparmor pkcs11 seccomp; do
201                 if use $tag; then
202                         DOCKER_BUILDTAGS+=" $tag"
203                 fi
204         done
205
206         pushd components/engine || die
207
208         if use hardened; then
209                 sed -i "s/EXTLDFLAGS_STATIC='/&-fno-PIC /" hack/make.sh || die
210                 grep -q -- '-fno-PIC' hack/make.sh || die 'hardened sed failed'
211                 sed  "s/LDFLAGS_STATIC_DOCKER='/&-extldflags -fno-PIC /" \
212                         -i hack/make/dynbinary-daemon || die
213                 grep -q -- '-fno-PIC' hack/make/dynbinary-daemon || die 'hardened sed failed'
214         fi
215
216         # build daemon
217         VERSION="$(cat ../../VERSION)" \
218         ./hack/make.sh dynbinary || die 'dynbinary failed'
219
220         popd || die # components/engine
221
222         pushd components/cli || die
223
224         # build cli
225         emake \
226                 LDFLAGS="$(usex hardened '-extldflags -fno-PIC' '')" \
227                 VERSION="$(cat ../../VERSION)" \
228                 GITCOMMIT="${DOCKER_GITCOMMIT}" \
229                 DISABLE_WARN_OUTSIDE_CONTAINER=1 \
230                 dynbinary || die
231
232         # build man pages
233         go build -o gen-manpages github.com/docker/cli/man || die
234         ./gen-manpages --root . --target ./man/man1 || die
235         ./man/md2man-all.sh -q || die
236         rm gen-manpages || die
237         # see "components/cli/scripts/docs/generate-man.sh" (which also does "go get" for go-md2man)
238
239         popd || die # components/cli
240 }
241
242 src_install() {
243         dosym containerd /usr/bin/docker-containerd
244         dosym containerd-shim /usr/bin/docker-containerd-shim
245         dosym runc /usr/bin/docker-runc
246         use container-init && dosym tini /usr/bin/docker-init
247
248         pushd components/engine || die
249         newbin "$(readlink -f bundles/latest/dynbinary-daemon/dockerd)" dockerd
250
251         newinitd contrib/init/openrc/docker.initd docker
252         newconfd contrib/init/openrc/docker.confd docker
253
254         systemd_dounit contrib/init/systemd/docker.{service,socket}
255
256         udev_dorules contrib/udev/*.rules
257
258         dodoc AUTHORS CONTRIBUTING.md CHANGELOG.md NOTICE README.md
259         dodoc -r docs/*
260
261         insinto /usr/share/vim/vimfiles
262         doins -r contrib/syntax/vim/ftdetect
263         doins -r contrib/syntax/vim/syntax
264
265         # note: intentionally not using "doins" so that we preserve +x bits
266         dodir /usr/share/${PN}/contrib
267         cp -R contrib/* "${ED}/usr/share/${PN}/contrib"
268         popd || die # components/engine
269
270         pushd components/cli || die
271
272         newbin build/docker-* docker
273
274         doman man/man*/*
275
276         dobashcomp contrib/completion/bash/*
277         insinto /usr/share/fish/vendor_completions.d/
278         doins contrib/completion/fish/docker.fish
279         insinto /usr/share/zsh/site-functions
280         doins contrib/completion/zsh/_*
281         popd || die # components/cli
282 }
283
284 pkg_postinst() {
285         udev_reload
286
287         elog
288         elog "To use Docker, the Docker daemon must be running as root. To automatically"
289         elog "start the Docker daemon at boot, add Docker to the default runlevel:"
290         elog "  rc-update add docker default"
291         elog "Similarly for systemd:"
292         elog "  systemctl enable docker.service"
293         elog
294         elog "To use Docker as a non-root user, add yourself to the 'docker' group:"
295         elog "  usermod -aG docker youruser"
296         elog
297
298         elog " Devicemapper storage driver has been deprecated"
299         elog " It will be removed in a future release"
300 }