diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..f2a5cef --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,22 @@ +version: 2 +jobs: + build: + docker: + - image: circleci/golang:1.11.4 + steps: + - checkout # check out the code in the project directory + - setup_remote_docker # install docker in docker + - run: + name: build linux binary + command: | + make build + mv sower sower.linux + - run: + name: build macOS binary + command: | + GOOS=darwin GOARCH=amd64 make build + mv sower sower.darwin + - run: + name: build docker image + command: | + make image \ No newline at end of file diff --git a/Makefile b/Makefile index d879c3d..cf1597c 100644 --- a/Makefile +++ b/Makefile @@ -6,20 +6,24 @@ generate: go generate ./... build: - GOBIN=$(PWD) go install -v + go build -v -ldflags \ + "-X main.version=$(shell git describe --tags) \ + -X main.date=$(shell date +%Y-%m-%d)" +image: + docker build -t sower -f deploy/Dockerfile . kill: sudo pkill -9 sower || true client: build kill - sudo $(PWD)/sower -f conf/sower.toml -logtostderr + sudo $(PWD)/sower -f conf/sower.toml server: build kill - $(PWD)/sower -n TCP -logtostderr -v 1 + $(PWD)/sower -n TCP -v 1 run: build kill - $(PWD)/sower -n TCP -logtostderr -v 1 & - sudo $(PWD)/sower -f conf/sower.toml -logtostderr & + $(PWD)/sower -n TCP -v 1 & + sudo $(PWD)/sower -f conf/sower.toml & @sleep 1 curl 127.0.0.1 @sleep 1 diff --git a/README.md b/README.md index f18e3e4..aed43e0 100644 --- a/README.md +++ b/README.md @@ -45,4 +45,7 @@ http(s) proxy | +----------+ | | ## todo - [x] authenticate -- [ ] broker \ No newline at end of file +- [ ] broker +- [ ] CI/CD +- [ ] relay optimization +- [ ] deploy script for all normal platform \ No newline at end of file diff --git a/conf/conf.go b/conf/conf.go index 9ba883a..47457d7 100644 --- a/conf/conf.go +++ b/conf/conf.go @@ -36,7 +36,7 @@ var Conf = struct { func init() { flag.StringVar(&Conf.ConfigFile, "f", "", "config file location") - flag.StringVar(&Conf.NetType, "n", "QUIC", "proxy net type (QUIC|KCP|TCP)") + flag.StringVar(&Conf.NetType, "n", "TCP", "proxy net type (QUIC|KCP|TCP)") flag.StringVar(&Conf.Cipher, "C", "AES_128_GCM", "cipher type (AES_128_GCM|AES_192_GCM|AES_256_GCM|CHACHA20_IETF_POLY1305|XCHACHA20_IETF_POLY1305)") flag.StringVar(&Conf.Password, "p", "12345678", "password") flag.StringVar(&Conf.ServerPort, "P", "5533", "server mode listen port") @@ -46,6 +46,7 @@ func init() { flag.StringVar(&Conf.ClientIP, "c", "127.0.0.1", "client dns service redirect IP") if !flag.Parsed() { + flag.Set("logtostderr", "true") flag.Parse() } diff --git a/deploy/Dockerfile b/deploy/Dockerfile new file mode 100644 index 0000000..8eb6655 --- /dev/null +++ b/deploy/Dockerfile @@ -0,0 +1,18 @@ +# Compile +FROM golang:1.11-alpine AS compiler + +RUN apk add --no-cache git make + +# enable go modules +WORKDIR /go-mod +COPY . . + +# do not worry about downloading dependency, sower will fix this. +RUN CGO_ENABLED=0 make build + + +# Build image +FROM scratch + +COPY --from=compiler /go-mod/sower /sower +ENTRYPOINT [ "/sower" ] \ No newline at end of file diff --git a/main.go b/main.go index e378f4f..91abc4a 100644 --- a/main.go +++ b/main.go @@ -7,9 +7,11 @@ import ( "github.com/wweir/sower/proxy" ) +var version, date string + func main() { conf := conf.Conf - glog.Infoln("Starting:", conf) + glog.Infof("Starting sower(%s %s): %v", version, date, conf) if conf.ServerAddr == "" { proxy.StartServer(conf.NetType, conf.ServerPort, conf.Cipher, conf.Password)