Skip to content

Instantly share code, notes, and snippets.

@tiborvass
Last active July 7, 2017 22:22
Show Gist options
  • Save tiborvass/20f4007d5fe736bf7ef33bbe1f642202 to your computer and use it in GitHub Desktop.
Save tiborvass/20f4007d5fe736bf7ef33bbe1f642202 to your computer and use it in GitHub Desktop.
Docker+vndr tip for Go libraries
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