fix docker build

pull/30/head
kun 2018-12-26 22:03:22 +08:00
parent 477f7b3d7a
commit 043c484e5e
6 changed files with 33 additions and 13 deletions

4
.gitignore vendored
View File

@ -1,6 +1,8 @@
goproxy
go_repos/*
cacheDir/*
.idea/*
bin/*
pkg/*
!pkg/proxy
!pkg/proxy

View File

@ -1,3 +1,15 @@
FROM alpine:3.8
RUN apk add --no-cache git mercurial subversion bzr fossil
COPY bin/goproxy /usr/bin/goproxy
FROM golang:1.11 AS build
env GO111MODULE on
env GOROOT /usr/local/go
COPY ./ /goproxy
WORKDIR /goproxy
RUN go generate
RUN go build
FROM buildpack-deps:stretch-scm
COPY --from=build /goproxy/goproxy /bin/goproxy
EXPOSE 8081
CMD ["goproxy"]

View File

@ -9,15 +9,19 @@ A global proxy for go modules. see: [https://goproxy.io](https://goproxy.io)
## Started
./goproxy -listen=0.0.0.0:80 -cacheDir=/cache
./goproxy -listen=0.0.0.0:80 -cacheDir=/data
## Docker
## Docker build
docker run --name goproxy -d -p80:8081 goproxyio/goproxy
docker build . --no-cache -t goproxy/goproxy:latest
Use the -v flag to persisting the proxy module data (change ___go_repo___ to your own dir):
## Docker run
docker run --name goproxy -d -p80:8081 -v go_repo:/cache goproxyio/goproxy
docker run --name goproxy -d -p80:8081 goproxy/goproxy
Use the -v flag to persisting the proxy module data (change ___cacheDir___ to your own dir):
docker run --name goproxy -d -p80:8081 -v cacheDir:/go goproxy/goproxy
## Docker Compose

View File

View File

@ -7,4 +7,4 @@ services:
- "8081:8081"
restart: always
volumes:
- ./go_repos:/ext
- ./cacheDir:/ext

View File

@ -33,9 +33,11 @@ func main() {
if cacheDir == "" {
cacheDir = "/go"
gpEnv := os.Getenv("GOPATH")
gp := filepath.SplitList(gpEnv)
if gp[0] != "" {
cacheDir = gp[0]
if gpEnv != "" {
gp := filepath.SplitList(gpEnv)
if gp[0] != "" {
cacheDir = gp[0]
}
}
}
fullCacheDir := filepath.Join(cacheDir, "pkg", "mod", "cache", "download")