Created
October 24, 2022 21:33
-
-
Save dakyskye/886536beaceb3aa980d2802410a1f060 to your computer and use it in GitHub Desktop.
Dockerfile I use in Go projects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM golang:1.18.4-alpine3.16 AS builder | |
ARG pkey | |
ENV SSH_PRIVATE_KEY $pkey | |
WORKDIR /service | |
ADD . . | |
RUN apk add --no-cache git openssh \ | |
&& eval "$(ssh-agent)" \ | |
&& echo "${SSH_PRIVATE_KEY}" | ssh-add - \ | |
&& mkdir /root/.ssh \ | |
&& ssh-keyscan -H gitlab.url > /root/.ssh/known_hosts \ | |
&& git config --global url."[email protected]:".insteadOf "https://gitlab.url/" \ | |
&& go env -w GOPRIVATE="gitlab.url/orgname/*" \ | |
&& CGO_ENABLED=0 GOOS=linux go build -a -o built_executable . | |
FROM scratch | |
WORKDIR /service | |
COPY --from=builder /service/built_executable ./ | |
CMD [ "./built_executable" ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
echo "${SSH_PRIVATE_KEY}"
is not a good idea, should be changed.