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