# t5de-importer in a container: a static build on distroless. Its data (key pair, accounts) goes in the /data volume.
#
#	docker build -t t5de-importer .
#	docker run -v importer-data:/data -e HUB_URL=... -e CATALOG_ID=... -e IMPORTER_KEY=... t5de-importer
FROM golang:1.27-alpine AS build
RUN apk add --no-cache git
# T5DE's modules (t5de-api) come straight from its Gitea.
ENV GOPRIVATE=git.t5de.dev CGO_ENABLED=0
ARG VERSION=dev
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN go build -trimpath -buildvcs=false \
	-ldflags "-s -w -buildid= -X git.t5de.dev/t5de/t5de-importer/internal/buildinfo.Version=${VERSION}" \
	-o /out/t5de-importer ./cmd/t5de-importer \
	&& mkdir /out/data

FROM gcr.io/distroless/static-debian12:nonroot
COPY --from=build /out/t5de-importer /t5de-importer
COPY --from=build --chown=nonroot:nonroot /out/data /data
ENV IMPORTER_DATA=/data
VOLUME /data
ENTRYPOINT ["/t5de-importer"]
