support go mod cache for dockerfile

This commit is contained in:
c9s 2020-12-17 14:44:19 +08:00
parent bee06ea192
commit 3fa74164fc
2 changed files with 6 additions and 3 deletions

View File

@ -5,8 +5,11 @@ RUN apk add --no-cache git ca-certificates gcc libc-dev pkgconfig
RUN go get -u github.com/c9s/goose/cmd/goose RUN go get -u github.com/c9s/goose/cmd/goose
ADD . $GOPATH/src/github.com/c9s/bbgo ADD . $GOPATH/src/github.com/c9s/bbgo
WORKDIR $GOPATH/src/github.com/c9s/bbgo WORKDIR $GOPATH/src/github.com/c9s/bbgo
# RUN GOPATH=$PWD/.mod go install ./cmd/bbgo ARG GO_MOD_CACHE
RUN go install ./cmd/bbgo ENV GOPATH_ORIG=$GOPATH
ENV GOPATH=${GO_MOD_CACHE:+$PWD/$GO_MOD_CACHE}
ENV GOPATH=${GOPATH:-$GOPATH_ORIG}
RUN go build -o $GOPATH_ORIG/bin/bbgo ./cmd/bbgo
# Second stage container # Second stage container
FROM alpine:3.12 FROM alpine:3.12

View File

@ -29,6 +29,6 @@ dist: bin-dir bbgo-linux bbgo-darwin
docker: docker:
GOPATH=$(PWD)/.mod go mod download GOPATH=$(PWD)/.mod go mod download
docker build --tag yoanlin/bbgo . docker build --build-arg GO_MOD_CACHE=.mod --tag yoanlin/bbgo .
.PHONY: dist .PHONY: dist