# Contributor: ungleich <foss@ungleich.ch>
# Contributor: Francesco Colista <fcolista@alpinelinux.org>
# Contributor: TBK <alpine@jjtc.eu>
# Maintainer: ungleich <foss@ungleich.ch>
pkgname=cri-o
pkgver=1.30.6
pkgrel=0
pkgdesc="OCI-based implementation of Kubernetes Container Runtime Interface"
url="https://github.com/cri-o/cri-o/"
arch="all"
license="Apache-2.0"
# Most tests will fail if not ran as root
# since it tries to create network interfaces
options="net chmod-clean !check"
depends="
	cni-plugins
	conmon
	conntrack-tools
	containers-common
	iproute2
	iptables
	oci-runtime
	"
makedepends="
	bash
	btrfs-progs-dev
	eudev-dev
	glib-dev
	go
	go-md2man
	gpgme-dev
	libseccomp-dev
	libselinux-dev
	lvm2-dev
	ostree-dev
	sqlite-dev
	tzdata
	"
checkdepends="bats cri-tools jq parallel sudo conmon"
subpackages="
	$pkgname-doc
	$pkgname-bash-completion
	$pkgname-zsh-completion
	$pkgname-fish-completion
	$pkgname-openrc
	"
	#$pkgname-fish-completion

source="
	$pkgname-$pkgver.tar.gz::https://github.com/cri-o/cri-o/archive/v$pkgver/cri-o-$pkgver.tar.gz
	crio.conf
	crio.initd
	crio.logrotated
	cni-plugins-path.patch
	makefile-fix-install.patch
	fix-test.patch
	remove-systemd-files.patch
	crictl.yaml
	"

# secfixes:
#   1.23.2-r0:
#     - CVE-2022-0811
#   1.24.1-r0:
#     - CVE-2022-1708
#   1.26.2-r0:
#     - CVE-2022-4318

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"
export GOBIN="$GOPATH/bin"

build() {
	# https://github.com/cri-o/cri-o/blob/master/install.md#build-tags
	make BUILDTAGS="libsqlite3 seccomp selinux apparmor containers_image_openpgp containers_image_ostree_stub"
}

check() {
	make localintegration
}

package() {
	make \
		DESTDIR="$pkgdir" \
		PREFIX=/usr \
		CRICTL_CONFIG_DIR="/etc/crio" \
		OCIUMOUNTINSTALLDIR="/etc/crio" \
		FISHINSTALLDIR=/usr/share/fish/vendor_completions.d \
		install.bin-nobuild install.man-nobuild install.completions install.config-nobuild

	# We want it in etc so apk does not overwrite it
	mkdir -p  "$pkgdir"/usr/share/oci-umount/oci-umount.d/
	ln -sf ../../../../etc/crio/crio-umount.conf "$pkgdir"/usr/share/oci-umount/oci-umount.d/crio-umount.conf

	# The CNI plugins are recommended to be installed as examples
	install -Dm644 contrib/cni/*.conflist -t "$pkgdir"/usr/share/doc/cri-o/examples/cni/

	install -Dm755 "$srcdir"/crio.initd "$pkgdir"/etc/init.d/crio
	install -Dm644 "$srcdir"/crio.conf "$pkgdir"/etc/crio/crio.conf
	install -Dm644 "$srcdir"/crio.logrotated "$pkgdir"/etc/logrotate.d/crio

	install -Dm644 "$srcdir"/crictl.yaml "$pkgdir"/etc/crictl.yaml
}

sha512sums="
3e8e3422a0fac9b603775a9b05626134b0e8b37425ddbbf39e155283ecdc7ac50184bb578179bc25585711286320034251318c599039d3b539d0f4d7f334c341  cri-o-1.30.6.tar.gz
469eddef2e7b24f3ac7b192da3851ada7332f8f93cd4503d8c4d62cc39f669d7893e69c654bc2d86e3d89919fa6da765a393576bcdeb94f1a024bec4fa5cbe2f  crio.conf
e9149cc2ddd24328c5290d3aea895c01e2798e066897535384f615a556496acdd52a603a0f4ac3c4c70bd5c363592f23c8b4d1987bf738300112fc62e1def555  crio.initd
1115228546a696eeebeb6d4b3e5c3152af0c99a2559097fc5829d8b416d979c457b4b1789e0120054babf57f585d3f63cbe49949d40417ae7aab613184bf4516  crio.logrotated
0a567dfa431ab1e53f2a351689be8d588a60cc5fcdbda403ec4f8b6ab9b1c18ad425f6c47f9a5ab1491e3a61a269dc4efa6a59e91e7521fa2b6bb165074aa8e0  cni-plugins-path.patch
09025bff1fed5004a15696cbc7c63260ae7c206ffe2c8506e6063e8889b7aa98bd5c7df2f0c109860d8432ddf5f3b6326dbfd46589d05cf87f26c38e4bdadb9c  makefile-fix-install.patch
b0fdaf2280968a69e05ef72288bbf6fc03787616c6b6fca1e4398f9849167f4773e5e6e72bf1738d1fff2a84e97aa00f23aabcd50898ba8ed130969f50363006  fix-test.patch
ae7e4a43f18076f19f3ae37d7302bfdf7a3befadf33e46bc9b1b14d50b605e8ba0d06d479568c24e8bf68f17c80ae48798068b2a46c3bcab565a5d225779f30e  remove-systemd-files.patch
79e1a7c6183ba56f55d923e9d738be945564494042bc011d31e9195f66c268d702ee5c86711d4b46618285fc1b10b59ea55c321390feca770cfc7de334e103bd  crictl.yaml
"