app-emulation/rkt: version bump to 1.27.0
[gentoo.git] / app-emulation / rkt / rkt-1.27.0.ebuild
1 # Copyright 1999-2017 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=6
5
6 inherit bash-completion-r1 autotools flag-o-matic systemd toolchain-funcs user
7
8 KEYWORDS="~amd64"
9
10 PXE_VERSION="1235.0.0"
11 PXE_SYSTEMD_VERSION="v231"
12 KVM_LINUX_VERSION="4.9.2"
13 KVMTOOL_VERSION="cfae4d64482ed745214e3c62dd84b79c2ae0f325"
14 QEMU_VERSION="v2.8.0"
15 PXE_URI="http://alpha.release.core-os.net/amd64-usr/${PXE_VERSION}/coreos_production_pxe_image.cpio.gz"
16 PXE_FILE="${PN}-pxe-${PXE_VERSION}.img"
17
18 SRC_URI_KVM="mirror://kernel/linux/kernel/v4.x/linux-${KVM_LINUX_VERSION}.tar.xz
19         ${PXE_URI} -> ${PXE_FILE}
20 "
21
22 SRC_URI="https://github.com/coreos/${PN}/archive/v${PV}.tar.gz -> ${P}.tar.gz
23 rkt_stage1_coreos? ( $PXE_URI -> $PXE_FILE )
24 rkt_stage1_kvm_lkvm? (
25         https://kernel.googlesource.com/pub/scm/linux/kernel/git/will/kvmtool/+archive/${KVMTOOL_VERSION}.tar.gz -> kvmtool-${KVMTOOL_VERSION}.tar.gz
26         ${SRC_URI_KVM}
27 )
28 rkt_stage1_kvm_qemu? (
29         http://wiki.qemu-project.org/download/qemu-${QEMU_VERSION#v}.tar.bz2
30         ${SRC_URI_KVM}
31 )
32 rkt_stage1_src? ( https://github.com/systemd/systemd/archive/${PXE_SYSTEMD_VERSION}.tar.gz -> systemd-${PXE_SYSTEMD_VERSION#v}.tar.gz )"
33
34 DESCRIPTION="rkt is an App Container runtime for Linux"
35 HOMEPAGE="https://github.com/coreos/rkt"
36
37 LICENSE="Apache-2.0"
38 SLOT="0"
39 # The rkt_stage1_kvm flag has been replaced by the rkt_stage1_kvm_lkvm and rkt_stage1_kvm_qemu flags
40 IUSE="doc examples +rkt_stage1_coreos +rkt_stage1_fly rkt_stage1_host rkt_stage1_kvm rkt_stage1_kvm_lkvm rkt_stage1_kvm_qemu rkt_stage1_src +actool systemd"
41 REQUIRED_USE="|| ( rkt_stage1_coreos rkt_stage1_fly rkt_stage1_host rkt_stage1_kvm_lkvm rkt_stage1_kvm_qemu rkt_stage1_src ) rkt_stage1_host? ( systemd ) !rkt_stage1_kvm"
42
43 # Some tests fail.
44 # rkt_stage1_src needs to copy /bin/mount, which requires root privileges during src_compile
45 RESTRICT="test rkt_stage1_src? ( userpriv )"
46
47 DEPEND=">=dev-lang/go-1.5
48         app-arch/cpio
49         app-crypt/trousers
50         sys-fs/squashfs-tools
51         dev-perl/Capture-Tiny
52         rkt_stage1_src? ( >=sys-apps/util-linux-2.27 )
53         rkt_stage1_kvm_qemu? (
54                 sys-apps/attr[static-libs(+)]
55                 sys-libs/libcap[static-libs(+)]
56                 sys-libs/zlib[static-libs(+)]
57                 >=x11-libs/pixman-0.28.0[static-libs(+)]
58         )"
59
60 RDEPEND="!app-emulation/rocket
61         rkt_stage1_host? ( systemd? (
62                 >=sys-apps/systemd-222
63                 app-shells/bash:0
64         ) )"
65
66 BUILDDIR="build-${P}"
67 STAGE1_DEFAULT_LOCATION="/usr/share/rkt/stage1.aci"
68
69 pkg_setup() {
70         enewgroup rkt-admin
71         enewgroup rkt
72 }
73
74 src_unpack() {
75         local x
76         for x in ${A}; do
77                 case ${x} in
78                         *.img|linux-*) continue ;;
79                         kvmtool-*)
80                                 mkdir kvmtool || die
81                                 pushd kvmtool >/dev/null || die
82                                 unpack ${x}
83                                 popd >/dev/null || die
84                                 ;;
85                         *)
86                                 unpack ${x}
87                 esac
88         done
89 }
90
91 src_prepare() {
92         eapply_user
93
94         # This patch breaks linux kernel cc-option checks when the
95         # compiler doesn't recognize the -no-pie option.
96         rm stage1/usr_from_kvm/kernel/patches/0002-for-debian-gcc.patch || die
97
98         # avoid sdjournal include for bug 595874
99         if ! use systemd; then
100                 sed -e "s/^\\(LOCAL_DIST_SRC_FILTER := .*\\)'$/\\1|api_service'/" \
101                         -i rkt/rkt.mk || die
102         fi
103
104         sed -e 's|^RKT_REQ_PROG(\[GIT\],.*|#\0|' -i configure.ac || die
105
106         # disable git fetch of systemd
107         sed -e 's~^include makelib/git.mk$~'\
108 'ifneq ($(wildcard $(RKT_STAGE1_SYSTEMD_SRC)),)\n\n'\
109 'get_systemd_sources: | $(UFS_SYSTEMDDIR)\n'\
110 '\tmv "$(RKT_STAGE1_SYSTEMD_SRC)" "$(UFS_SYSTEMD_SRCDIR)"\n\n'\
111 '$(UFS_SYSTEMD_CONFIGURE): get_systemd_sources\n\n'\
112 'else ifneq ($(wildcard $(UFS_SYSTEMD_SRCDIR)),)\n\n'\
113 'else\n'\
114 '\t\0\n'\
115 'endif~' -i stage1/usr_from_src/usr_from_src.mk || die
116
117         # disable git fetch of kvmtool
118         sed -e 's~^include makelib/git.mk$~'\
119 'ifneq ($(wildcard $(shell echo "$${WORKDIR}/kvmtool")),)\n\n'\
120 '$(call forward-vars, get_lkvm_sources, LKVM_SRCDIR)\n'\
121 'get_lkvm_sources: | $(LKVM_TMPDIR)\n'\
122 '\tmv "$${WORKDIR}/kvmtool" "$(LKVM_SRCDIR)"\n\n'\
123 '$(LKVM_PATCH_STAMP): get_lkvm_sources\n\n'\
124 'else ifneq ($(wildcard $(LKVM_SRCDIR)),)\n\n'\
125 'else\n'\
126 '\t\0\n'\
127 'endif~' -i stage1/usr_from_kvm/lkvm.mk || die
128
129         # disable git fetch of qemu
130         sed -e 's~^include makelib/git.mk$~'\
131 'ifneq ($(wildcard $(shell echo "$${WORKDIR}/qemu-'${QEMU_VERSION#v}'")),)\n\n'\
132 '$(call forward-vars, get_qemu_sources, QEMU_SRCDIR)\n'\
133 'get_qemu_sources: | $(QEMU_TMPDIR)\n'\
134 '\tmv "$${WORKDIR}/qemu-'${QEMU_VERSION#v}'" "$(QEMU_SRCDIR)"\n\n'\
135 '$(QEMU_CONF_STAMP): get_qemu_sources\n\n'\
136 'else ifneq ($(wildcard $(QEMU_SRCDIR)),)\n\n'\
137 'else\n'\
138 '\t\0\n'\
139 'endif~' \
140         -e 's|QEMU_CONFIGURATION_OPTS :=|\0 --disable-bzip2 --disable-libssh2 --disable-opengl|' \
141         -i stage1/usr_from_kvm/qemu.mk || die
142
143         # disable fetch of kernel sources
144         sed -e 's|wget .*|ln -s "$${DISTDIR}/linux-'${KVM_LINUX_VERSION}'.tar.xz" "$@"|' \
145                 -i stage1/usr_from_kvm/kernel.mk || die
146
147         if use rkt_stage1_host; then
148                 # Make systemdUnitsPath consistent with host
149                 sed -e 's|\(systemdUnitsPath := \).*|\1"'$(systemd_get_systemunitdir)'"|' \
150                         -i stage1/init/init.go || die
151         fi
152
153         eautoreconf
154 }
155
156 src_configure() {
157         local flavors hypervisors myeconfargs=(
158                 --with-stage1-default-images-directory="/usr/share/rkt"
159                 --with-stage1-default-location="${STAGE1_DEFAULT_LOCATION}"
160         )
161
162         use systemd || myeconfargs+=( --enable-sdjournal=no )
163
164         # enable flavors (first is default)
165         use rkt_stage1_host && flavors+=",host"
166         use rkt_stage1_src && flavors+=",src"
167         use rkt_stage1_coreos && flavors+=",coreos"
168         use rkt_stage1_fly && flavors+=",fly"
169         { use rkt_stage1_kvm_lkvm || use rkt_stage1_kvm_qemu; } && flavors+=",kvm"
170         myeconfargs+=( --with-stage1-flavors="${flavors#,}" )
171
172         if use rkt_stage1_src; then
173                 myeconfargs+=(
174                         --with-stage1-systemd-version=${PXE_SYSTEMD_VERSION}
175                         --with-stage1-systemd-src="${WORKDIR}/systemd-${PXE_SYSTEMD_VERSION#v}"
176                 )
177         fi
178
179         if use rkt_stage1_coreos || use rkt_stage1_kvm_lkvm || use rkt_stage1_kvm_qemu; then
180                 myeconfargs+=(
181                         --with-coreos-local-pxe-image-path="${DISTDIR}/${PXE_FILE}"
182                         --with-coreos-local-pxe-image-systemd-version="${PXE_SYSTEMD_VERSION}"
183                 )
184         fi
185
186         if use rkt_stage1_kvm_lkvm || use rkt_stage1_kvm_qemu; then
187                 use rkt_stage1_kvm_lkvm && hypervisors+=",lkvm"
188                 use rkt_stage1_kvm_qemu && hypervisors+=",qemu"
189                 myeconfargs+=( --with-stage1-kvm-hypervisors="${hypervisors#,}" )
190         fi
191
192         # Go's 6l linker does not support PIE, disable so cgo binaries
193         # which use 6l+gcc for linking can be built correctly.
194         if gcc-specs-pie; then
195                 append-ldflags -nopie
196         fi
197
198         export CC=$(tc-getCC)
199         export CGO_ENABLED=1
200         export CGO_CFLAGS="${CFLAGS}"
201         export CGO_CPPFLAGS="${CPPFLAGS}"
202         export CGO_CXXFLAGS="${CXXFLAGS}"
203         export CGO_LDFLAGS="${LDFLAGS}"
204         export BUILDDIR
205
206         econf "${myeconfargs[@]}"
207 }
208
209 src_compile() {
210         local arch=${ARCH}
211         case ${arch} in
212                 amd64) arch=x86_64;;
213         esac
214         ARCH=${arch} emake V=3
215         ARCH=${arch} emake V=3 bash-completion
216 }
217
218 src_install() {
219         dodoc README.md
220         use doc && dodoc -r Documentation
221         use examples && dodoc -r examples
222         use actool && dobin "${S}/${BUILDDIR}/tools/actool"
223
224         dobin "${S}/${BUILDDIR}/target/bin/rkt"
225
226         insinto /usr/share/rkt
227         doins "${S}/${BUILDDIR}/target/bin/"*.aci
228
229         # create symlink for default stage1 image path
230         if use rkt_stage1_host; then
231                 dosym stage1-host.aci "${STAGE1_DEFAULT_LOCATION}"
232         elif use rkt_stage1_src; then
233                 dosym stage1-src.aci "${STAGE1_DEFAULT_LOCATION}"
234         elif use rkt_stage1_coreos; then
235                 dosym stage1-coreos.aci "${STAGE1_DEFAULT_LOCATION}"
236         elif use rkt_stage1_fly; then
237                 dosym stage1-fly.aci "${STAGE1_DEFAULT_LOCATION}"
238         elif use rkt_stage1_kvm_lkvm; then
239                 dosym stage1-kvm-lkvm.aci "${STAGE1_DEFAULT_LOCATION}"
240         elif use rkt_stage1_kvm_qemu; then
241                 dosym stage1-kvm-qemu.aci "${STAGE1_DEFAULT_LOCATION}"
242         fi
243
244         systemd_dounit "${S}"/dist/init/systemd/*.service \
245                 "${S}"/dist/init/systemd/*.timer \
246                 "${S}"/dist/init/systemd/*.socket
247
248         insinto /usr/lib/tmpfiles.d
249         doins "${S}"/dist/init/systemd/tmpfiles.d/*
250
251         newbashcomp "${S}"/dist/bash_completion/rkt.bash rkt
252
253         keepdir /etc/${PN}
254         fowners :rkt-admin /etc/${PN}
255         fperms 2775 /etc/${PN}
256 }