from novit.tech/direktil/dkl:v1.2.0 as dkl

# ------------------------------------------------------------------------
from golang:1.26.4-trixie as build

run apt-get update && apt-get install -y git

workdir /src

copy go.mod go.sum ./
run \
  --mount=type=cache,id=gomod,target=/go/pkg/mod \
  --mount=type=cache,id=gobuild,target=/root/.cache/go-build \
  go mod download

arg GIT_TAG

copy . ./
run \
  --mount=type=cache,id=gomod,target=/go/pkg/mod \
  --mount=type=cache,id=gobuild,target=/root/.cache/go-build \
 go test ./... && \
 hack/build ./...

# ------------------------------------------------------------------------
from debian:trixie
entrypoint ["/bin/dkl-local-server"]

env _uncache=1
run --mount=type=cache,id=debian-trixie-apt,target=/var/cache/apt \
 apt update \
 && yes |apt install -y genisoimage gdisk dosfstools util-linux udev binutils systemd \
 ca-certificates curl openssh-client qemu-utils wireguard-tools \
 erofs-utils erofsfuse cryptsetup systemd-boot-efi mtools

copy --from=dkl   /bin/dkl /bin/dls /bin/
copy --from=build /src/dist/ /bin/
