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