Add: Dockerfile and Makefile

This commit is contained in:
Dreamacro 2018-06-17 08:18:39 +08:00
parent ef301af04f
commit cd9f496fc9
5 changed files with 51 additions and 9 deletions

View File

@ -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

21
Dockerfile Normal file
View File

@ -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"]

5
Gopkg.lock generated
View File

@ -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"

19
Makefile Normal file
View File

@ -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)/*

View File

@ -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) {