Dockerfiles: download modules in advance

This should speed up Dockerfile builds, particularly when building after
updating the code since the modules will not be to be re-downloaded.
This commit is contained in:
Hector Sanjuan 2019-10-28 10:23:18 +01:00
parent 7b499263af
commit 073a0dfa58
7 changed files with 26 additions and 15 deletions

View File

@ -6,12 +6,9 @@ MAINTAINER Hector Sanjuan <hector@protocol.ai>
ENV GOPATH /go
ENV SRC_PATH $GOPATH/src/github.com/ipfs/ipfs-cluster
ENV GO111MODULE on
# ENV CGO_ENABLED 0
ENV GOPROXY=https://proxy.golang.org
COPY . $SRC_PATH
WORKDIR $SRC_PATH
RUN make install
ENV SUEXEC_VERSION v0.2
ENV TINI_VERSION v0.16.1
RUN set -x \
@ -27,6 +24,14 @@ RUN set -x \
# Get the TLS CA certificates, they're not provided by busybox.
RUN apt-get update && apt-get install -y ca-certificates
COPY go.* go.* $SRC_PATH/
WORKDIR $SRC_PATH
RUN go mod download
COPY . $SRC_PATH
RUN make install
#------------------------------------------------------
FROM busybox:1-glibc
MAINTAINER Hector Sanjuan <hector@protocol.ai>

View File

@ -7,9 +7,15 @@ MAINTAINER Hector Sanjuan <hector@protocol.ai>
# This builder just builds the cluster binaries
ENV GOPATH /go
ENV SRC_PATH $GOPATH/src/github.com/ipfs/ipfs-cluster
ENV GO111MODULE on
# ENV CGO_ENABLED 0
ENV GOPROXY=https://proxy.golang.org
COPY go.* go.* $SRC_PATH/
WORKDIR $SRC_PATH
RUN go mod download
COPY . $SRC_PATH
WORKDIR $SRC_PATH
RUN make install
#------------------------------------------------------

View File

@ -6,16 +6,19 @@ MAINTAINER Hector Sanjuan <hector@protocol.ai>
ENV GOPATH /go
ENV SRC_PATH $GOPATH/src/github.com/ipfs/ipfs-cluster
ENV GO111MODULE on
# ENV CGO_ENABLED 0
ENV GOPROXY=https://proxy.golang.org
COPY . $SRC_PATH
WORKDIR $SRC_PATH
RUN make install
RUN cd /tmp && \
wget https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64 && \
chmod +x jq-linux64
COPY go.* go.* $SRC_PATH/
WORKDIR $SRC_PATH
RUN go mod download
COPY . $SRC_PATH
RUN make install
#------------------------------------------------------
FROM ipfs/go-ipfs:master

View File

@ -14,7 +14,6 @@ install:
$(MAKE) -C cmd/ipfs-cluster-ctl install
build:
go build -ldflags "-X ipfscluster.Commit=$(shell git rev-parse HEAD)"
$(MAKE) -C cmd/ipfs-cluster-service build
$(MAKE) -C cmd/ipfs-cluster-ctl build

View File

@ -4,7 +4,7 @@ SRC := $(shell find .. -type f -name '*.go')
all: ipfs-cluster-ctl
ipfs-cluster-ctl: $(SRC)
go build
go build -mod=readonly
build: ipfs-cluster-ctl

View File

@ -4,7 +4,7 @@ SRC := $(shell find .. -type f -name '*.go')
all: ipfs-cluster-service
ipfs-cluster-service: $(SRC)
go build -ldflags "-X main.commit=$(shell git rev-parse HEAD)"
go build -mod=readonly -ldflags "-X main.commit=$(shell git rev-parse HEAD)"
build: ipfs-cluster-service

2
go.mod
View File

@ -55,8 +55,6 @@ require (
github.com/libp2p/go-libp2p-pubsub v0.1.1
github.com/libp2p/go-libp2p-raft v0.1.3
github.com/libp2p/go-ws-transport v0.1.2
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/multiformats/go-multiaddr v0.1.1
github.com/multiformats/go-multiaddr-dns v0.1.1
github.com/multiformats/go-multiaddr-net v0.1.0