Last active
July 7, 2017 22:22
-
-
Save tiborvass/20f4007d5fe736bf7ef33bbe1f642202 to your computer and use it in GitHub Desktop.
Docker+vndr tip for Go libraries
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
FROM golang:1.8 | |
RUN go get github.com/lk4d4/vndr | |
WORKDIR /go/src/github.com/someone/someproject | |
# Make sure vendor.conf only has commit hashes to always behave correctly with build caching. | |
COPY vendor.conf . | |
RUN vndr -whitelist '.*' | |
COPY . . | |
# Rationale: | |
# Go libraries can have 3rd-party dependencies and should have tests. | |
# To run the tests, you need those dependencies either in your GOPATH or in vendor/ | |
# This is a way of using the extremely simple vndr tool to achieve that, | |
# without actually "vendoring" (aka checking in the dependencies in your tree) | |
# nor requiring to run `vndr` everytime your source code changes. | |
# | |
# Explanation: | |
# Since `vndr` by default strips all the unused dependencies from vendor/ based on | |
# your source code, you used to need to put the last `COPY . .` layer before `RUN vndr`. | |
# With the `-whitelist '.*'` flag, you can skip that phase, removing the order requirement. | |
# You only need `vendor.conf` to fetch the dependencies. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment