From ae59088d9057a73cc10b01d446fd2f0ac52d1ca3 Mon Sep 17 00:00:00 2001 From: Christoph Barbian Date: Mon, 16 Oct 2023 08:54:17 +0200 Subject: [PATCH] make envtest work in docker build --- Dockerfile | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3cbeb6e..96feda7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,24 +1,24 @@ ### build go executable FROM --platform=$BUILDPLATFORM golang:1.21.3 as build +ARG TARGETOS TARGETARCH -WORKDIR /go/src +WORKDIR /workspace -COPY go.mod go.sum /go/src/ +COPY go.mod go.mod +COPY go.sum go.sum RUN go mod download -COPY cmd /go/src/cmd -COPY internal /go/src/internal - -RUN go test ./... +COPY cmd/ cmd/ +COPY internal/ internal/ +COPY Makefile Makefile -WORKDIR /go/src/cmd/webhook - -ARG TARGETOS TARGETARCH -RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -a -o /go/bin/webhook . +RUN make envtest \ + && CGO_ENABLED=0 KUBEBUILDER_ASSETS="/workspace/bin/k8s/current" go test ./... \ + && CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o ./bin/webhook ./cmd/webhook ### final image FROM scratch ENTRYPOINT ["/app/bin/webhook"] -COPY --from=build /go/bin/webhook /app/bin/webhook +COPY --from=build /workspace/bin/webhook /app/bin/webhook