Setup CircleCI and goreleaser

This commit is contained in:
Geoff Bourne 2018-05-09 18:37:15 -05:00
parent 17a4bd6515
commit fccf5f9eef
5 changed files with 127 additions and 0 deletions

50
.circleci/config.yml Normal file
View File

@ -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: /.*/

43
.goreleaser.yml Normal file
View File

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

3
Dockerfile Normal file
View File

@ -0,0 +1,3 @@
FROM scratch
COPY mc-router /
ENTRYPOINT ["/mc-router"]

13
Makefile Normal file
View File

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

View File

@ -9,6 +9,7 @@ import (
"context" "context"
"os" "os"
"os/signal" "os/signal"
"fmt"
) )
var ( var (
@ -18,11 +19,28 @@ var (
String() String()
mappings = kingpin.Flag("mapping", "Mapping of external hostname to internal server host:port"). mappings = kingpin.Flag("mapping", "Mapping of external hostname to internal server host:port").
StringMap() 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() { func main() {
kingpin.Parse() kingpin.Parse()
if *versionFlag {
showVersion()
os.Exit(0)
}
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
c := make(chan os.Signal, 1) c := make(chan os.Signal, 1)