add docker support

pull/13/head
姜禹 2018-10-17 11:40:42 +08:00 committed by kun
parent 42316d3ead
commit 59e1de8487
5 changed files with 40 additions and 0 deletions

3
.gitignore vendored
View File

@ -1 +1,4 @@
goproxy
build/*
go_repos/*
.idea/*

8
Dockerfile Normal file
View File

@ -0,0 +1,8 @@
FROM golang:1.11
COPY ./ /goproxy
WORKDIR /goproxy
RUN go build
CMD ["/goproxy/goproxy","-listen=0.0.0.0:8080"]

View File

@ -10,3 +10,17 @@ A global proxy for go modules. see: [https://goproxy.io](https://goproxy.io)
## Started
./goproxy -listen=0.0.0.0:80
## Docker
docker run -it goproxyio/goproxy
Use the -v flag to persisting the proxy module data (change ___go_repo___ to your own dir):
docker run -it -v go_repo:/go/pkg/mod/cache/download goproxyio/goproxy
## Docker Compose
docker-compose up

10
docker-compose.yaml Normal file
View File

@ -0,0 +1,10 @@
version: "3"
services:
goproxy:
image: goproxyio/goproxy:latest
ports:
- "8080"
restart: always
volumes:
- ./go_repos:/go/pkg/mod/cache/download

View File

@ -28,8 +28,13 @@ func main() {
if gpEnv == "" {
panic("can not find $GOPATH")
}
fmt.Fprintf(os.Stdout, "goproxy: %s inited.\n", time.Now().Format("2006-01-02 15:04:05"))
gp := filepath.SplitList(gpEnv)
cacheDir = filepath.Join(gp[0], "pkg", "mod", "cache", "download")
if _, err := os.Stat(cacheDir); os.IsNotExist(err) {
fmt.Fprintf(os.Stdout, "goproxy: %s cache dir is not exist. %s\n", time.Now().Format("2006-01-02 15:04:05"), cacheDir)
os.MkdirAll(cacheDir, 0644)
}
http.Handle("/", mainHandler(http.FileServer(http.Dir(cacheDir))))
err := http.ListenAndServe(listen, nil)
if nil != err {