From 3eec47c0b047dd6a10e54fa4a4f3f75312a6c9af Mon Sep 17 00:00:00 2001 From: Ian Molee Date: Mon, 8 Apr 2024 18:08:15 -0700 Subject: [PATCH] Add .dockerignore and adjust Dockerfile --- .dockerignore | 5 +++++ Dockerfile | 20 ++++++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..475cb0d --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +*.log +output.*.txt +.vscode +files +files.*/ diff --git a/Dockerfile b/Dockerfile index 26d7e89..c581ca9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,19 @@ +ARG bin_name=docgrouper + FROM golang:1.22 as builder -WORKDIR /go/src/docgrouper -COPY testdata testdata/ -COPY *.go go.mod go.sum ./ +ARG bin_name +WORKDIR /go/src/$bin_name +COPY . . RUN go mod download -RUN go test -v ./... && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o docgroup +RUN go test -v ./... && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $bin_name FROM gcr.io/distroless/base-nossl-debian12 -COPY --from=builder /go/src/docgrouper/docgrouper /bin/docgrouper +ARG bin_name +COPY --from=builder /go/src/${bin_name}/${bin_name} /bin/${bin_name} VOLUME [ "/files" ] -ENTRYPOINT [ "docgroup" ] \ No newline at end of file + +# ARGs are stupid and cannot be used in ENTRYPOINT, so we still have to +# hard-code the binary name here, but this is still better than having to +# hard-code it in the stages above, since it doesn't really matter much what the +# entrypoint is called. +ENTRYPOINT [ "docgrouper" ] \ No newline at end of file