ethresearch / sharding-p2p-poc

Proof of Concept of Ethereum Serenity Peer-to-Peer Layer on libp2p PubSub System
40 stars 19 forks source link

Speed up docker build process #85

Closed ChihChengLiang closed 5 years ago

ChihChengLiang commented 5 years ago
ChihChengLiang commented 5 years ago

Here's an idea to save the painfully go get time. Run go get for the online repo first and run again after copying codebase. The second go get is fast since it only gets the newly introduced packages if any.

FROM golang:1.10.3-alpine
# ... apk add and install gx, etc. 

# Go get here first
RUN go get -v github.com/ethresearch/sharding-p2p-poc

# ...

COPY *.go ./
COPY pb ./pb
# After copy everything, run go get again.
RUN go get -d -v .

# ...
ChihChengLiang commented 5 years ago

wow, there's a go mod feature introduced in Go 1.11, which allows us to export a go.mod and a go.sum file. So in the Dockerfile, the source code change would not ruin the cache of dependencies.

# ...
COPY go.mod .
COPY go.sum .

RUN go mod download
COPY . .

example