diff --git a/.travis.yml b/.travis.yml index d407e98a..23461177 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,11 +12,7 @@ env: - BINDIR=bin script: - go test - - GOARCH=amd64 GOOS=linux go build -o $BINDIR/$NAME-linux - - GOARCH=amd64 GOOS=darwin go build -o $BINDIR/$NAME-macos - - chmod +x $BINDIR/$NAME-* - - gzip $BINDIR/$NAME-linux - - gzip $BINDIR/$NAME-macos +before_deploy: make -j releases deploy: provider: releases prerelease: true diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..a82a556f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +FROM golang:latest as builder +RUN wget http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.tar.gz -O /tmp/GeoLite2-Country.tar.gz && \ + cd /tmp && \ + tar zxvf GeoLite2-Country.tar.gz && \ + cd GeoLite2-Country_* && \ + cp GeoLite2-Country.mmdb /Country.mmdb +RUN curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh && \ + mkdir -p /go/src/github.com/Dreamacro/clash +WORKDIR /go/src/github.com/Dreamacro/clash +COPY . /go/src/github.com/Dreamacro/clash +RUN dep ensure && \ + GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags '-w -s' -o /clash && \ + chmod +x /clash + +FROM alpine:latest +RUN apk --no-cache add ca-certificates && \ + mkdir -p /root/.config/clash +COPY --from=builder /clash . +COPY --from=builder /Country.mmdb /root/.config/clash/ +EXPOSE 7890 7891 +ENTRYPOINT ["/clash"] diff --git a/Gopkg.lock b/Gopkg.lock index 84d82854..947f49bd 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -49,10 +49,11 @@ "chacha20poly1305", "hkdf", "internal/chacha20", + "internal/subtle", "poly1305", "ssh/terminal" ] - revision = "8ac0e0d97ce45cd83d1d7243c060cb8461dda5e9" + revision = "a8fb68e7206f8c78be19b432c58eb52a6aa34462" [[projects]] branch = "master" @@ -62,7 +63,7 @@ "unix", "windows" ] - revision = "9527bec2660bd847c050fda93a0f0c6dee0800bb" + revision = "6c888cc515d3ed83fc103cf1d84468aad274b0a7" [[projects]] name = "gopkg.in/eapache/channels.v1" diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..d13d692d --- /dev/null +++ b/Makefile @@ -0,0 +1,19 @@ +NAME=clash +BINDIR=bin +GOBUILD=CGO_ENABLED=0 go build -ldflags '-w -s' + +all: linux macos + +linux: + GOARCH=amd64 GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ + +macos: + GOARCH=amd64 GOOS=darwin $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ + +releases: linux macos + chmod +x $(BINDIR)/$(NAME)-* + gzip $(BINDIR)/$(NAME)-linux + gzip $(BINDIR)/$(NAME)-macos + +clean: + rm $(BINDIR)/* diff --git a/constant/config.go b/constant/config.go index caa8c2d4..63c87859 100644 --- a/constant/config.go +++ b/constant/config.go @@ -29,9 +29,14 @@ var ( func init() { currentUser, err := user.Current() if err != nil { - log.Fatalf("Can't get current user: %s", err.Error()) + dir := os.Getenv("HOME") + if dir == "" { + log.Fatalf("Can't get current user: %s", err.Error()) + } + HomeDir = dir + } else { + HomeDir = currentUser.HomeDir } - HomeDir = currentUser.HomeDir dirPath := path.Join(HomeDir, ".config", Name) if _, err := os.Stat(dirPath); os.IsNotExist(err) {