Last active
July 7, 2024 13:41
-
-
Save spyzhov/19c55486698aaf27849d563341cfad24 to your computer and use it in GitHub Desktop.
Build Golang application in Dockerfile, with private repositories in dependencies, without experimental features.
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
# NB! not for production! | |
# https://docs.docker.com/engine/reference/builder/#arg | |
# Warning: It is not recommended to use build-time variables for passing secrets like github keys, user credentials etc. Build-time variable values are visible to any user of the image with the docker history command. | |
FROM golang:1.13 as builder | |
# This argument should be defined as your personal access tokens, from: https://github.com/settings/tokens | |
ARG GITHUB_ACCESS_TOKEN | |
# Any kind of configurations: | |
ENV GO111MODULE=on | |
ENV GOFLAGS=" -ldflags '-w'" | |
ENV GOPROXY=direct | |
ENV GOSUMDB=off | |
# Setup your repo | |
WORKDIR /go/src/repo | |
# Caching layers for dependencies | |
COPY ./go.mod ./go.sum ./ | |
RUN git config --global url."https://${GITHUB_ACCESS_TOKEN}:@github.com/".insteadOf "https://github.com/" && \ | |
go mod download && \ | |
git config --global --unset url."https://${GITHUB_ACCESS_TOKEN}:@github.com/".insteadOf | |
# Build stage | |
COPY . . | |
RUN go build -o /go/bin/application . | |
# Result container: | |
# Use debian if your binary depends on some shared libraries. | |
# FROM debian:10-slim | |
FROM busybox:latest | |
WORKDIR /root | |
COPY --from=builder /go/bin/application ./application | |
CMD ["./application"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
NB! Not for production!
Documentation