# Copyright (C) 2023 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the CC0 1.0 License.
# Maintainer: Parabola Hackers <dev@lists.parabola.nu>

pkgname=docker-registry
pkgver=2.8.1
pkgrel=2
pkgdesc="Docker registry server and associated tools"
arch=('armv7h' 'i686' 'x86_64')
url='https://github.com/docker/distribution.git'
license=('Apache')
makedepends=('go')
source=("https://github.com/distribution/distribution/archive/refs/tags/v${pkgver}.tar.gz")
sha512sums=('b9c8525051458ff4bf4592ca3ddba83c4325e88c6812ddb28c1567e331c1571f112e3b646ca970f0fe420f3b1d61d00f7151450d7b9948a08733606255731266')

prepare(){
  mkdir -p src/github.com/docker

  mv "distribution-${pkgver}" src/github.com/docker/distribution

  cd src/github.com/docker/distribution

  sed "s/^VERSION=\$(.*)/VERSION=${pkgver}/" -i Makefile
  sed "s/^REVISION=\$(.*)/REVISION=${pkgrel}/" -i Makefile
}

build(){
  export GOPATH="$GOPATH:${PWD}"
  cd src/github.com/docker/distribution

  make binaries
}

package(){
  cd src/github.com/docker/distribution

  install -d "${pkgdir}/usr/bin/"
  binaries="digest registry registry-api-descriptor-template"
  for binary in ${binaries} ; do
      install -m 755 "bin/${binary}" -t "${pkgdir}/usr/bin/"
  done

  install -d "${pkgdir}/usr/share/doc/${pkgname}/"
  files="BUILDING.md CONTRIBUTING.md LICENSE MAINTAINERS README.md ROADMAP.md"
  for file in ${files} ; do
      install -m 644 "${file}" -t "${pkgdir}/usr/share/doc/${pkgname}/"
  done

  cp -r docs "${pkgdir}/usr/share/doc/${pkgname}/"

  install -d "${pkgdir}/usr/share/doc/${pkgname}/registry-example-configs"
  files="config-cache.yml config-example.yml config-dev.yml"
  for file in ${files} ; do
      install -m 644 \
	      "cmd/registry/${file}" \
	      -t "${pkgdir}/usr/share/doc/${pkgname}/registry-example-configs"
  done
}
