Skip to content

Instantly share code, notes, and snippets.

@montanaflynn
Created June 30, 2020 03:29
Show Gist options
  • Save montanaflynn/2d8a5532077e501ec86b4ad643cd1075 to your computer and use it in GitHub Desktop.
Save montanaflynn/2d8a5532077e501ec86b4ad643cd1075 to your computer and use it in GitHub Desktop.
Docker build example using go mod graph | ... | xargs go get
Sending build context to Docker daemon 86.02kB
Step 1/11 : FROM golang:1.14-alpine AS build
---> 3289bf11c284
Step 2/11 : WORKDIR /go/src/app
---> Using cache
---> e3b027c2ddb0
Step 3/11 : ENV CGO_ENABLED=0
---> Using cache
---> 3e3b91c43862
Step 4/11 : RUN apk add --no-cache jq
---> Using cache
---> dd27f7a8401e
Step 5/11 : COPY go.mod go.sum ./
---> Using cache
---> 37c5dbb965b4
Step 6/11 : RUN go mod graph | cut -d '@' -f 1 | cut -d ' ' -f 2 | sort | uniq | tr '\n' ' ' | xargs go get -v
---> Running in 55b723dfaeca
go: github.com/spf13/cast upgrade => v1.3.1
go: github.com/kr/pretty upgrade => v0.2.0
go: github.com/dgraph-io/ristretto upgrade => v0.0.2
go: github.com/spf13/viper upgrade => v1.7.0
go: github.com/kr/text upgrade => v0.2.0
go: github.com/spf13/cobra upgrade => v1.0.0
go: golang.org/x/crypto upgrade => v0.0.0-20200622213623-75b288015ac9
go: gopkg.in/yaml.v2 upgrade => v2.3.0
go: github.com/stretchr/testify upgrade => v1.6.1
go: golang.org/x/net upgrade => v0.0.0-20200625001655-4c5254603344
go: downloading gopkg.in/yaml.v2 v2.3.0
go: downloading github.com/kr/text v0.2.0
go: downloading github.com/hashicorp/hcl v1.0.0
go: downloading github.com/spf13/cast v1.3.1
go: downloading github.com/dgraph-io/ristretto v0.0.2
go: downloading github.com/spf13/cobra v1.0.0
go: downloading github.com/stretchr/testify v1.6.1
go: downloading golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
go: downloading github.com/spf13/viper v1.7.0
go: downloading github.com/kr/pretty v0.2.0
go: downloading github.com/cespare/xxhash v1.1.0
go: downloading golang.org/x/net v0.0.0-20200625001655-4c5254603344
go: downloading github.com/cpuguy83/go-md2man v1.0.10
go: downloading github.com/dgraph-io/badger/v2 v2.0.3
go: downloading github.com/davecgh/go-spew v1.1.1
go: downloading github.com/stretchr/objx v0.1.1
go: downloading github.com/spf13/jwalterweatherman v1.0.0
go: downloading github.com/fsnotify/fsnotify v1.4.7
go: downloading golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd
go: downloading github.com/pelletier/go-toml v1.2.0
go: downloading github.com/spf13/pflag v1.0.3
go: downloading github.com/magiconair/properties v1.8.1
go: downloading github.com/golang/protobuf v1.3.2
go: downloading github.com/pmezard/go-difflib v1.0.0
go: downloading github.com/russross/blackfriday v1.5.2
go: downloading github.com/mitchellh/mapstructure v1.1.2
go: downloading github.com/subosito/gotenv v1.2.0
go: downloading github.com/spf13/afero v1.1.2
go: downloading github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2
go: downloading github.com/inconshreveable/mousetrap v1.0.0
go: downloading github.com/golang/snappy v0.0.1
go: downloading github.com/pkg/errors v0.8.1
go: downloading gopkg.in/ini.v1 v1.51.0
go: downloading github.com/dustin/go-humanize v1.0.0
go: downloading github.com/DataDog/zstd v1.4.1
go: downloading gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c
go: downloading golang.org/x/text v0.3.2
github.com/dgraph-io/badger/v2/options
github.com/dgraph-io/badger/v2/trie
github.com/cespare/xxhash
github.com/russross/blackfriday
net
github.com/golang/protobuf/proto
github.com/pkg/errors
golang.org/x/net/internal/timeseries
golang.org/x/sys/unix
github.com/cpuguy83/go-md2man/md2man
github.com/cpuguy83/go-md2man
github.com/dgraph-io/ristretto/z
github.com/dgraph-io/ristretto
github.com/dgryski/go-farm
crypto/x509
net/textproto
vendor/golang.org/x/net/http/httpproxy
github.com/dgraph-io/badger/v2/pb
github.com/golang/snappy
vendor/golang.org/x/net/http/httpguts
github.com/dustin/go-humanize
github.com/hashicorp/hcl/hcl/strconv
github.com/hashicorp/hcl/hcl/token
github.com/kr/text
github.com/spf13/cast
github.com/hashicorp/hcl/hcl/ast
github.com/hashicorp/hcl/hcl/scanner
crypto/tls
github.com/hashicorp/hcl/json/token
github.com/hashicorp/hcl/hcl/parser
github.com/hashicorp/hcl/json/scanner
github.com/hashicorp/hcl/json/parser
github.com/kr/pretty
github.com/spf13/pflag
github.com/hashicorp/hcl
github.com/fsnotify/fsnotify
github.com/hashicorp/hcl/hcl/printer
github.com/mitchellh/mapstructure
github.com/pelletier/go-toml
github.com/spf13/afero/mem
golang.org/x/text/transform
github.com/spf13/cobra
golang.org/x/text/unicode/norm
github.com/spf13/jwalterweatherman
github.com/subosito/gotenv
gopkg.in/ini.v1
net/http/httptrace
net/http
gopkg.in/yaml.v2
github.com/davecgh/go-spew/spew
github.com/pmezard/go-difflib/difflib
gopkg.in/yaml.v3
github.com/stretchr/objx
golang.org/x/net/trace
net/http/httptest
github.com/spf13/afero
github.com/magiconair/properties
github.com/stretchr/testify/assert
github.com/dgraph-io/badger/v2/y
github.com/dgraph-io/badger/v2/table
github.com/dgraph-io/badger/v2/skl
github.com/spf13/viper
github.com/stretchr/testify/mock
github.com/dgraph-io/badger/v2
github.com/stretchr/testify/http
github.com/stretchr/testify
Removing intermediate container 55b723dfaeca
---> 3b68a78f2292
Step 7/11 : COPY . .
---> 399c6f9220c2
Step 8/11 : RUN go build -o /go/bin/app
---> Running in 97722c17cc36
go: downloading github.com/golang/protobuf v1.3.1
go: downloading github.com/dgraph-io/ristretto v0.0.2-0.20200115201040-8f368f2f2ab3
go: downloading golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb
go: downloading golang.org/x/net v0.0.0-20190620200207-3b0461eec859
Removing intermediate container 97722c17cc36
---> 83eae666feaf
Step 9/11 : FROM gcr.io/distroless/base
---> c4c70323b0c2
Step 10/11 : COPY --from=build /go/bin/app /
---> Using cache
---> d632291102d5
Step 11/11 : ENTRYPOINT ["/app"]
---> Using cache
---> 59dfa7e0f55f
Successfully built 59dfa7e0f55f
Successfully tagged golang-docker-cache:latest
FROM golang:1.14-alpine AS build
WORKDIR /go/src/app
ENV CGO_ENABLED=0
RUN apk add --no-cache jq
COPY go.mod go.sum ./
RUN go mod graph | cut -d '@' -f 1 | cut -d ' ' -f 2 | sort | uniq | tr '\n' ' ' | xargs go get -v
COPY . .
RUN go build -o /go/bin/app
FROM gcr.io/distroless/base
COPY --from=build /go/bin/app /
ENTRYPOINT ["/app"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment