Skip to content

Instantly share code, notes, and snippets.

@miguelmota
Last active July 19, 2022 10:53
Show Gist options
  • Save miguelmota/b1537520a66a7ec7ea552c0473d28652 to your computer and use it in GitHub Desktop.
Save miguelmota/b1537520a66a7ec7ea552c0473d28652 to your computer and use it in GitHub Desktop.
Dockefile golang go get private repo
FROM golang:latest
# ...
RUN mkdir -p $GOROOT/src/github.com/MY_ORG
# fetch private repo example
RUN git clone -b go https://MY_AUTH_TOKEN:x-oauth-basic@github.com/MY_ORG/MY_REPO.git $GOPATH/src/github.com/MY_ORG/MY_REPO
# go get public repo example
RUN go get github.com/lib/pq
# ...
RUN go build -o main . 
FROM golang:latest
# expose default port
EXPOSE 8000
# set environment path
ENV PATH /go/bin:$PATH
# cd into the api code directory
WORKDIR /go/src/github.com/myorg/myapp
# create ssh directory
RUN mkdir ~/.ssh
RUN touch ~/.ssh/known_hosts
RUN ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
# allow private repo pull
RUN git config --global url."https://MY_AUTH_TOKEN:x-oauth-basic@github.com/".insteadOf "https://github.com/"
# copy the local package files to the container's workspace
ADD . /go/src/github.com/myorg/myapp
# install the program
RUN go install github.com/myorg/myapp
# start application
CMD ["myapp"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment