diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..1ef781d --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,50 @@ +# Golang CircleCI 2.0 configuration file +# +# Check https://circleci.com/docs/2.0/language-go/ for more details +version: 2 + +defaults: &defaults + docker: + # specify the version + - image: circleci/golang:1.10 + + # Specify service dependencies here if necessary + # CircleCI maintains a library of pre-built images + # documented at https://circleci.com/docs/2.0/circleci-images/ + # - image: circleci/postgres:9.4 + + working_directory: /go/src/github.com/itzg/mc-router + + +jobs: + build: + <<: *defaults + steps: + - checkout + + - run: make install-dep + - run: make test + + release: + <<: *defaults + steps: + - checkout + + - run: make install-dep + - run: docker login -u $DOCKER_USER -p $DOCKER_PASSWORD + - run: make release + +workflows: + version: 2 + incremental: + jobs: + - build: + filters: + tags: + ignore: /.*/ + tagged: + jobs: + - release: + filters: + tags: + only: /.*/ \ No newline at end of file diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..0241c48 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,43 @@ +project_name: mc-router +release: + github: + owner: itzg + name: mc-router +brew: + install: bin.install "mc-router" +builds: +- goos: + - linux + - darwin + - windows + goarch: + - amd64 + - "386" + goarm: + - "6" + main: cmd/mc-router/main.go + binary: mc-router + env: + - CGO_ENABLED=0 +archive: + format: tar.gz + name_template: '{{ .Binary }}_{{.Version}}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ + .Arm }}{{ end }}' + files: + - licence* + - LICENCE* + - license* + - LICENSE* + - readme* + - README* + - changelog* + - CHANGELOG* +snapshot: + name_template: SNAPSHOT-{{ .Commit }} +dockers: + - goos: linux + goarch: amd64 + image: itzg/mc-router + tag_templates: + - "{{.Tag}}" + - latest diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..578de54 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,3 @@ +FROM scratch +COPY mc-router / +ENTRYPOINT ["/mc-router"] \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e3d3321 --- /dev/null +++ b/Makefile @@ -0,0 +1,13 @@ +test: vendor + go test ./... + +vendor: + dep ensure -vendor-only + +.PHONY: release +release: vendor + curl -sL https://git.io/goreleaser | bash + +.PHONY: install-dep +install-dep: + curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh \ No newline at end of file diff --git a/cmd/mc-router/main.go b/cmd/mc-router/main.go index ae2d3bb..9838a93 100644 --- a/cmd/mc-router/main.go +++ b/cmd/mc-router/main.go @@ -9,6 +9,7 @@ import ( "context" "os" "os/signal" + "fmt" ) var ( @@ -18,11 +19,28 @@ var ( String() mappings = kingpin.Flag("mapping", "Mapping of external hostname to internal server host:port"). StringMap() + versionFlag = kingpin.Flag("version", "Output version and exit"). + Bool() ) +var ( + version = "dev" + commit = "none" + date = "unknown" +) + +func showVersion() { + fmt.Printf("%v, commit %v, built at %v", version, commit, date) +} + func main() { kingpin.Parse() + if *versionFlag { + showVersion() + os.Exit(0) + } + ctx, cancel := context.WithCancel(context.Background()) c := make(chan os.Signal, 1)