Skip to content

Instantly share code, notes, and snippets.

@montanaflynn
Created June 30, 2020 03:38
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 montanaflynn/9c7365f0b74635f18268f12897b0b6eb to your computer and use it in GitHub Desktop.
Save montanaflynn/9c7365f0b74635f18268f12897b0b6eb to your computer and use it in GitHub Desktop.
Docker build example using go mod download --json | jq ... | xargs go get
Sending build context to Docker daemon 86.02kB
Step 1/10 : FROM golang:1.14-alpine AS build
---> 3289bf11c284
Step 2/10 : WORKDIR /go/src/app
---> Using cache
---> e3b027c2ddb0
Step 3/10 : ENV CGO_ENABLED=0
---> Using cache
---> 3e3b91c43862
Step 4/10 : RUN apk add --no-cache jq
---> Using cache
---> dd27f7a8401e
Step 5/10 : COPY go.mod go.sum ./
---> Using cache
---> 37c5dbb965b4
Step 6/10 : COPY . .
---> a330f38199fe
Step 7/10 : RUN go build -o /go/bin/app
---> Running in 65198e9d4600
go: downloading github.com/dgraph-io/badger/v2 v2.0.3
go: downloading github.com/golang/protobuf v1.3.1
go: downloading github.com/pkg/errors v0.8.1
go: downloading golang.org/x/net v0.0.0-20190620200207-3b0461eec859
go: downloading github.com/dgraph-io/ristretto v0.0.2-0.20200115201040-8f368f2f2ab3
go: downloading github.com/dustin/go-humanize v1.0.0
go: downloading github.com/golang/snappy v0.0.1
go: downloading github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2
go: downloading github.com/cespare/xxhash v1.1.0
go: downloading golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb
Removing intermediate container 65198e9d4600
---> bd3cfdd5d009
Step 8/10 : FROM gcr.io/distroless/base
---> c4c70323b0c2
Step 9/10 : COPY --from=build /go/bin/app /
---> Using cache
---> d632291102d5
Step 10/10 : 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 download --json | jq -r '"\(.Path)@\(.Version)"' | 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