# Contributor: Christian Kampka <christian@kampka.net>
# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: fossdd <fossdd@pwned.life>
pkgname=docker-registry
pkgver=2.8.3
pkgrel=7
pkgdesc="An implementation of the Docker Registry HTTP API V2 for use with docker 1.6+"
url="https://distribution.github.io/distribution"
# riscv64: undefined syscall
arch="all !riscv64"
license="Apache-2.0"
makedepends="git go"
install="$pkgname.pre-install"
pkgusers="docker-registry"
pkggroups="docker-registry"
subpackages="$pkgname-openrc"
source="$pkgname-$pkgver.tar.gz::https://github.com/distribution/distribution/archive/v$pkgver.tar.gz
	log-hook-syslog.patch
	config-example.patch
	bugsnag-panicwrap.patch
	$pkgname.initd
	$pkgname.confd
	$pkgname.logrotate
	"
builddir="$srcdir/src/github.com/docker/distribution"
options="net"

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

prepare() {
	mkdir -p "${builddir%/*}"
	mv "$srcdir"/distribution-$pkgver "$builddir"

	default_prepare
}

build() {
	export GO111MODULE=off

	make binaries \
		DISTRIBUTION_DIR="$builddir" \
		VERSION="$pkgver" \
		REVISION=""
}

check() {
	make test
}

package() {
	install -D -m755 bin/registry "$pkgdir"/usr/bin/$pkgname
	install -D -m755 bin/digest "$pkgdir"/usr/bin/$pkgname-digest
	install -D -m755 bin/registry-api-descriptor-template "$pkgdir"/usr/bin/$pkgname-api-descriptor-template

	install -D -m640 -o $pkgusers -g $pkggroups \
		cmd/registry/config-example.yml "$pkgdir"/etc/$pkgname/config.yml

	install -D -m755 "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	install -D -m644 "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname
	install -D -m644 "$srcdir"/$pkgname.logrotate "$pkgdir"/etc/logrotate.d/$pkgname

	install -d -m750 -o $pkgusers -g $pkggroups "$pkgdir"/var/lib/$pkgname
}

sha512sums="
7c2be028f5beb7fd89509250564924e22d2726540a9df4f32c80518f23742680e5f59bec8480a99ff3cade4f10391f94c50e9f31a4f3fac4af9b0b06adc474f6  docker-registry-2.8.3.tar.gz
834257d45bc83eef5fe65955b215c450db0c9849fc9d5ddbaef731589f05e82cc8c0dd8a315623e45c4b4b8d463c8c12b53d99ade9029fd42b6d6afdf7f5ca48  log-hook-syslog.patch
9c3a8afd855bb161166fdc38e931a2ad4aaf9a8e97c67d15ea8a098f6f6f800b4c8ef037dbbd0ac954289dbae7b208116751a3c97aa682fa50887ccc7a68a9d7  config-example.patch
49ed24e520d3f29df1b3367e74b1b5e8e898c8e64a2c3e09c3397131da0adeac87bc1fe4577a20840e2f379b794495b8b170ea5aedfa1e4430ed353d6260af2e  bugsnag-panicwrap.patch
7962b2660ee8147b66fc38b7e4c1d7b37ba0b7d64fbddefb970c182bd55e2a841cec885a9459dfa1db7f1a8fcaa0bd9c7eea0b22c9e37854a3081415381c14d4  docker-registry.initd
34d9158cf4b0e04ba9198235629ebe23eb5a7a3dcc70d26cf7f4fd045a7cd8e055476e7e30255f711160aa23af505ca38a8a76302aae7ec24701b3887b874276  docker-registry.confd
979643f6b9a3e12f692dc37f964fddff66f4e08cd74a1094a4be1230e67f83e703207e5420135cebb29aa13ff20a984395168046fd902392ad45d8e3eadcaa0e  docker-registry.logrotate
"
