Skip to content

Instantly share code, notes, and snippets.

@orvyl
Last active December 9, 2017 03:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save orvyl/7000f973abe88d40c8c91d4e28e139a7 to your computer and use it in GitHub Desktop.
Save orvyl/7000f973abe88d40c8c91d4e28e139a7 to your computer and use it in GitHub Desktop.
Compile Golang project with sub packages and vendor folder. Golang + golang:alpine + Package Oriented Design
FROM golang:1.9-alpine
RUN mkdir /app
WORKDIR /app
RUN mkdir -p /go/src/github.com/your_user_name/your_app # Mimics your Golang workspace. Take note that $GOPATH = /go
ADD . /go/src/github.com/your_user_name/your_app # Copies all the source code of the package(your_app) including the vendor/
RUN go build github.com/your_user_name/your_app/cmd/serviced # here's where my main() resides
RUN mv /go/src/github.com/your_user_name/your_app/cmd/serviced/config.yml /app && \
rm -rf /go/src # Deletes all source code after compilation. In this case, I moved first the config file into the WORKDIR where the binary resides
ENV CONFIG_PATH /app # Assuming that the binary(app) will read the config file in this path
CMD ["./serviced"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment