app-admin/fluentd: new package, data collector and unified logging layer
[gentoo.git] / app-emulation / docker / docker-18.03.0.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="0520e24"
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         dev-libs/libltdl
64         ~app-emulation/containerd-1.0.2
65         ~app-emulation/runc-1.0.0_rc5[apparmor?,seccomp?]
66         ~app-emulation/docker-proxy-0.8.0_p20180314
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 ~NETFILTER_XT_MATCH_IPVS
82         ~IP_NF_NAT ~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         ~CRYPTO ~CRYPTO_AEAD ~CRYPTO_GCM ~CRYPTO_SEQIV ~CRYPTO_GHASH ~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         if kernel_is le 3 18; then
122                 CONFIG_CHECK+="
123                         ~RESOURCE_COUNTERS
124                 "
125         fi
126
127         if kernel_is le 3 13; then
128                 CONFIG_CHECK+="
129                         ~NETPRIO_CGROUP
130                 "
131         else
132                 CONFIG_CHECK+="
133                         ~CGROUP_NET_PRIO
134                 "
135         fi
136
137         if kernel_is lt 4 5; then
138                 CONFIG_CHECK+="
139                         ~MEMCG_KMEM
140                 "
141                 ERROR_MEMCG_KMEM="CONFIG_MEMCG_KMEM: is optional"
142         fi
143
144         if kernel_is lt 4 7; then
145                 CONFIG_CHECK+="
146                         ~DEVPTS_MULTIPLE_INSTANCES
147                 "
148         fi
149
150         if use aufs; then
151                 CONFIG_CHECK+="
152                         ~AUFS_FS
153                         ~EXT4_FS_POSIX_ACL ~EXT4_FS_SECURITY
154                 "
155                 ERROR_AUFS_FS="CONFIG_AUFS_FS: is required to be set if and only if aufs-sources are used instead of aufs4/aufs3"
156         fi
157
158         if use btrfs; then
159                 CONFIG_CHECK+="
160                         ~BTRFS_FS
161                         ~BTRFS_FS_POSIX_ACL
162                 "
163         fi
164
165         if use device-mapper; then
166                 CONFIG_CHECK+="
167                         ~BLK_DEV_DM ~DM_THIN_PROVISIONING ~EXT4_FS ~EXT4_FS_POSIX_ACL ~EXT4_FS_SECURITY
168                 "
169         fi
170
171         if use overlay; then
172                 CONFIG_CHECK+="
173                         ~OVERLAY_FS ~EXT4_FS_SECURITY ~EXT4_FS_POSIX_ACL
174                 "
175         fi
176
177         linux-info_pkg_setup
178
179         # create docker group for the code checking for it in /etc/group
180         enewgroup docker
181 }
182
183 src_compile() {
184         export GOPATH="${WORKDIR}/${P}"
185
186         # setup CFLAGS and LDFLAGS for separate build target
187         # see https://github.com/tianon/docker-overlay/pull/10
188         export CGO_CFLAGS="-I${ROOT}/usr/include"
189         export CGO_LDFLAGS="-L${ROOT}/usr/$(get_libdir)"
190
191         # if we're building from a tarball, we need the GITCOMMIT value
192         [ "$DOCKER_GITCOMMIT" ] && export DOCKER_GITCOMMIT
193
194         # fake golang layout
195         ln -s docker-ce/components/engine ../docker || die
196         ln -s docker-ce/components/cli ../cli || die
197
198         # let's set up some optional features :)
199         export DOCKER_BUILDTAGS=''
200         for gd in aufs btrfs device-mapper overlay; do
201                 if ! use $gd; then
202                         DOCKER_BUILDTAGS+=" exclude_graphdriver_${gd//-/}"
203                 fi
204         done
205
206         for tag in apparmor pkcs11 seccomp; do
207                 if use $tag; then
208                         DOCKER_BUILDTAGS+=" $tag"
209                 fi
210         done
211
212         pushd components/engine || die
213
214         if use hardened; then
215                 sed -i "s/EXTLDFLAGS_STATIC='/&-fno-PIC /" hack/make.sh || die
216                 grep -q -- '-fno-PIC' hack/make.sh || die 'hardened sed failed'
217                 sed  "s/LDFLAGS_STATIC_DOCKER='/&-extldflags -fno-PIC /" \
218                         -i hack/make/dynbinary-daemon || die
219                 grep -q -- '-fno-PIC' hack/make/dynbinary-daemon || die 'hardened sed failed'
220         fi
221
222         # build daemon
223         VERSION="$(cat ../../VERSION)" \
224         ./hack/make.sh dynbinary || die 'dynbinary failed'
225
226         popd || die # components/engine
227
228         pushd components/cli || die
229
230         # build cli
231         emake \
232                 LDFLAGS="$(usex hardened '-extldflags -fno-PIC' '')" \
233                 VERSION="$(cat ../../VERSION)" \
234                 GITCOMMIT="${DOCKER_GITCOMMIT}" \
235                 DISABLE_WARN_OUTSIDE_CONTAINER=1 \
236                 dynbinary || die
237
238         # build man pages
239         go build -o gen-manpages github.com/docker/cli/man || die
240         ./gen-manpages --root . --target ./man/man1 || die
241         ./man/md2man-all.sh -q || die
242         rm gen-manpages || die
243         # see "components/cli/scripts/docs/generate-man.sh" (which also does "go get" for go-md2man)
244
245         popd || die # components/cli
246 }
247
248 src_install() {
249         dosym containerd /usr/bin/docker-containerd
250         dosym containerd-shim /usr/bin/docker-containerd-shim
251         dosym runc /usr/bin/docker-runc
252         use container-init && dosym tini /usr/bin/docker-init
253
254         pushd components/engine || die
255         newbin "$(readlink -f bundles/latest/dynbinary-daemon/dockerd)" dockerd
256
257         newinitd contrib/init/openrc/docker.initd docker
258         newconfd contrib/init/openrc/docker.confd docker
259
260         systemd_dounit contrib/init/systemd/docker.{service,socket}
261
262         udev_dorules contrib/udev/*.rules
263
264         dodoc AUTHORS CONTRIBUTING.md CHANGELOG.md NOTICE README.md
265         dodoc -r docs/*
266
267         insinto /usr/share/vim/vimfiles
268         doins -r contrib/syntax/vim/ftdetect
269         doins -r contrib/syntax/vim/syntax
270
271         # note: intentionally not using "doins" so that we preserve +x bits
272         dodir /usr/share/${PN}/contrib
273         cp -R contrib/* "${ED}/usr/share/${PN}/contrib"
274         popd || die # components/engine
275
276         pushd components/cli || die
277
278         newbin build/docker-* docker
279
280         doman man/man*/*
281
282         dobashcomp contrib/completion/bash/*
283         insinto /usr/share/zsh/site-functions
284         doins contrib/completion/zsh/_*
285         popd || die # components/cli
286 }
287
288 pkg_postinst() {
289         udev_reload
290
291         elog
292         elog "To use Docker, the Docker daemon must be running as root. To automatically"
293         elog "start the Docker daemon at boot, add Docker to the default runlevel:"
294         elog "  rc-update add docker default"
295         elog "Similarly for systemd:"
296         elog "  systemctl enable docker.service"
297         elog
298         elog "To use Docker as a non-root user, add yourself to the 'docker' group:"
299         elog "  usermod -aG docker youruser"
300         elog
301 }