# Contributor: Jake Buchholz Göktürk <tomalok@gmail.com>
# Maintainer: Jake Buchholz Göktürk <tomalok@gmail.com>
pkgname=docker-cli-buildx
pkgver=0.16.2
pkgrel=0
_commit=34c195271a3f6dc64814db71438dc50dd41d7e3e
pkgdesc="A Docker CLI plugin for extended build capabilities"
url="https://docs.docker.com/engine/reference/commandline/buildx_build"
arch="all"
license="Apache-2.0"
makedepends="go"
options="net"
source="buildx-$pkgver.tar.gz::https://github.com/docker/buildx/archive/v$pkgver.tar.gz"

_buildx_installdir="/usr/libexec/docker/cli-plugins"

builddir="$srcdir"/buildx-"$pkgver"

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

build() {
	PKG=github.com/docker/buildx
	local ldflags="-X $PKG/version.Version=v$pkgver -X $PKG/version.Revision=$_commit -X $PKG/version.Package=$PKG"
	go build -v -modcacherw -ldflags "$ldflags" -o docker-buildx ./cmd/buildx
}

check() {
	# bake and gitutil tests do not succeed inside abuild environment
	local pkgs="$(go list -modcacherw ./... | grep -Ev '(bake|gitutil)')"
	go test -modcacherw -short $pkgs
	./docker-buildx version
}

package() {
	# this is circular to have top-level, so depend on it in package itself
	depends="docker-cli"
	install -Dm755 docker-buildx "$pkgdir$_buildx_installdir"/docker-buildx
}

sha512sums="
8ed9b918cb314ab76a0a92b55eb8289f6a20c71c85be592132a8de40b6e527b68a72f1a605484214f31c36ef20b5a4945e0cc4da09c724dc18553b243cbcee63  buildx-0.16.2.tar.gz
"
