Skip to content

Instantly share code, notes, and snippets.

@oyamo

oyamo/Dockerfile Secret

Last active January 20, 2023 05:20
Show Gist options
  • Save oyamo/ac4697560c40167069b542801f567599 to your computer and use it in GitHub Desktop.
Save oyamo/ac4697560c40167069b542801f567599 to your computer and use it in GitHub Desktop.
FROM golang:1.18-alpine
# Install git
RUN apk --update add git ca-certificates
# setup go compiler
RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64;
# Github credentials that will be passed as arguments
ARG GIT_USERNAME
ARG GIT_PASSWORD
# goprivate
RUN go env -w GOPRIVATE=github.com/$GIT_USERNAME/*
# update credentials
RUN git config --global url."https://$GIT_USERNAME:$GIT_PASSWORD@github.com".insteadOf "https://github.com"
RUN echo "machine github.com login $GIT_USERNAME password $GIT_PASSWORD" > /root/.netrc ;
# Make the netrc file only readable by the owner
RUN chmod 600 /root/.netrc
# pre-copy/cache go.mod for pre-downloading dependencies and
# only redownloading them in subsequent builds if they change
COPY go.mod go.sum .
COPY . .
# install dependencies
RUN go mod download
# build your application
RUN go build -o awesome-app
# Run the app
CMD ["awesome-app"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment