Document how to use dep with Docker (#1094)

This commit is contained in:
Stephen Afam-Osemene 2017-09-19 17:49:22 +01:00 коммит произвёл Carolyn Van Slyck
Родитель 0e2928a796
Коммит 0076b937d5
1 изменённых файлов: 25 добавлений и 1 удалений

Просмотреть файл

@ -35,6 +35,7 @@ Summarize the question and quote the reply, linking back to the original comment
* [Is it OK to make backwards-incompatible changes now?](#is-it-ok-to-make-backwards-incompatible-changes-now)
* [My dependers don't use `dep` yet. What should I do?](#my-dependers-dont-use-dep-yet-what-should-i-do)
* [How do I configure a dependency that doesn't tag its releases?](#how-do-i-configure-a-dependency-that-doesnt-tag-its-releases)
* [How do I use `dep` with Docker?](#how-do-i-use-dep-with-docker)
## Concepts
### Does `dep` replace `go get`?
@ -302,7 +303,6 @@ For a refresher on Go's recommended workspace organization, see the ["How To Wri
`dep init -gopath`, which falls back to network mode when the packages are not
found in `GOPATH`. `dep ensure` doesn't work with projects in `GOPATH`.
## Best Practices
### Should I commit my vendor directory?
@ -391,3 +391,27 @@ stripping out nested `vendor` directories.
## How do I configure a dependency that doesn't tag its releases?
Add a constraint to `Gopkg.toml` that specifies `branch: "master"` (or whichever branch you need) in the `[[constraint]]` for that dependency. `dep ensure` will determine the current revision of your dependency's master branch, and place it in `Gopkg.lock` for you. See also: [What is the difference between Gopkg.toml and Gopkg.lock?](#what-is-the-difference-between-gopkgtoml-the-manifest-and-gopkglock-the-lock)
## How do I use `dep` with Docker?
`dep ensure -vendor-only` creates the vendor folder from a valid `Gopkg.toml` and `Gopkg.lock` without checking for Go code.
This is especially useful for builds inside docker utilizing cache layers.
Sample dockerfile:
FROM golang:1.9 AS builder
RUN curl -fsSL -o /usr/local/bin/dep https://github.com/golang/dep/releases/download/vX.X.X/dep-linux-amd64 && chmod +x /usr/local/bin/dep
RUN mkdir -p /go/src/github.com/***
WORKDIR /go/src/github.com/***
COPY Gopkg.toml Gopkg.lock ./
# copies the Gopkg.toml and Gopkg.lock to WORKDIR
RUN dep ensure -vendor-only
# install the dependencies without checking for go code
...