Skip to content

Instantly share code, notes, and snippets.

@dakyskye
Created October 24, 2022 21:33
Show Gist options
  • Save dakyskye/886536beaceb3aa980d2802410a1f060 to your computer and use it in GitHub Desktop.
Save dakyskye/886536beaceb3aa980d2802410a1f060 to your computer and use it in GitHub Desktop.
Dockerfile I use in Go projects
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" ]
@dakyskye
Copy link
Author

echo "${SSH_PRIVATE_KEY}" is not a good idea, should be changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment