Skip to content

Commit

Permalink
Packaging, releasing and publishing process
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Krawczyk committed Dec 10, 2015
1 parent c951289 commit 88b84ff
Show file tree
Hide file tree
Showing 14 changed files with 175 additions and 32 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ _obj
_test
build
bin
dist

# Architecture specific extensions/prefixes
*.[568vq]
Expand All @@ -26,3 +27,6 @@ _testmain.go
*.test
*.prof
marathon-forwarder

# goxc
.goxc.local.json
23 changes: 23 additions & 0 deletions .goxc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"ArtifactsDest": "dist",
"Tasks": [
"default",
"publish-github"
],
"BuildConstraints": "linux,!arm darwin",
"PackageVersion": "0.2.1",
"TaskSettings": {
"deb": {
"other-mapped-files": {
"/etc/init/marathon-consul.conf": "debian/marathon-consul.upstart",
"/etc/marathon-consul.d/config.json": "debian/config.json"
}
},
"publish-github": {
"body": "",
"owner": "allegro",
"repository": "marathon-consul"
}
},
"ConfigVersion": "0.9"
}
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ before_install:
- if ! go get github.com/golang/tools/cmd/cover; then go get golang.org/x/tools/cmd/cover; fi
after_success:
- $HOME/gopath/bin/goveralls -service=travis-ci
- go get github.com/tcnksm/ghr
- make xcompile
- ghr -t $GITHUB_TOKEN -u allegro --replace `shell awk -F\" '/^const Version/ { print $$2 }' main.go` dist/

script: make test
37 changes: 13 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
TEST?=./...
TESTARGS?=
NAME = $(shell awk -F\" '/^const Name/ { print $$2 }' main.go)
VERSION = $(shell awk -F\" '/^const Version/ { print $$2 }' main.go)
DEPS = $(shell go list -f '{{range .TestImports}}{{.}} {{end}}' ./...)
CURRENT_DIR = $(shell pwd)
SOURCEDIR = $(CURRENT_DIR)
SOURCES := $(shell find $(SOURCEDIR) -name '*.go')

all: deps build

Expand All @@ -15,34 +18,20 @@ updatedeps:
go get -u -v ./...
echo $(DEPS) | xargs -n1 go get -d

build: deps
build: deps test
@mkdir -p bin/
go build -o bin/$(NAME)

test: deps
test: deps $(SOURCES)
PATH=$(CURRENT_DIR)/bin:$(PATH) go test $(TEST) $(TESTARGS)
go vet $(TEST)

xcompile: deps test
# go get github.com/mitchellh/gox
@rm -rf build/
@mkdir -p build
gox \
-os="darwin" \
-os="dragonfly" \
-os="freebsd" \
-os="linux" \
-os="openbsd" \
-os="solaris" \
-os="windows" \
-output="build/{{.Dir}}_$(VERSION)_{{.OS}}_{{.Arch}}/$(NAME)"
release:
@rm -rf dist
@go get github.com/laher/goxc
goxc
goxc bump
git add .goxc.json
git commit -m "Bumped version"

package: xcompile
$(eval FILES := $(shell ls build))
@mkdir -p build/tgz
for f in $(FILES); do \
(cd $(shell pwd)/build && tar -zcvf tgz/$$f.tar.gz $$f); \
echo $$f; \
done

.PHONY: all deps updatedeps build test xcompile package
.PHONY: all deps updatedeps build test xcompile package dist
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ make test

Argument | Default | Description
-----------------------|-----------------------|------------------------------------------------------
config-file | | Path to a JSON file to read configuration from. **Note:** Will override options set earlier on the command line
config-file | | Path to a JSON file to read configuration from. **Note:** Will override options set earlier on the command line. See [example](debian/config.json).
consul-auth | `false` | Use Consul with authentication
consul-auth-password | | The basic authentication password
consul-auth-username | | The basic authentication username
Expand Down
8 changes: 4 additions & 4 deletions consul/consul_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ func TestRegisterServices_shouldReturnErrorOnFailure(t *testing.T) {
err := consul.Register(service)

// then
assert.NotNil(t, err)
assert.Error(t, err)
}

func TestDeregisterServices(t *testing.T) {
t.Parallel()
server := CreateConsulTestServer("dc1", t)
server := CreateNamedConsulTestServer("localhost", "dc1", t)
defer server.Stop()

consul := ConsulClientAtServer(server)
Expand All @@ -153,7 +153,7 @@ func TestDeregisterServices(t *testing.T) {

func TestDeregisterServices_shouldReturnErrorOnFailure(t *testing.T) {
t.Parallel()
server := CreateConsulTestServer("dc1", t)
server := CreateNamedConsulTestServer("localhost", "dc1", t)
defer server.Stop()

consul := ConsulClientAtServer(server)
Expand All @@ -166,7 +166,7 @@ func TestDeregisterServices_shouldReturnErrorOnFailure(t *testing.T) {
err := consul.Deregister("serviceA", server.Config.NodeName)

// then
assert.NotNil(t, err)
assert.Error(t, err)
}

func serviceRegistration(name string, tags []string) *consulapi.AgentServiceRegistration {
Expand Down
8 changes: 7 additions & 1 deletion consul/consul_test_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ import (
func CreateConsulTestServer(dc string, t *testing.T) *testutil.TestServer {
return testutil.NewTestServerConfig(t, func(c *testutil.TestServerConfig) {
c.Datacenter = dc
c.NodeName = "localhost"
})
}

func CreateNamedConsulTestServer(hostname string, dc string, t *testing.T) *testutil.TestServer {
return testutil.NewTestServerConfig(t, func(c *testutil.TestServerConfig) {
c.Datacenter = dc
c.NodeName = hostname
})
}

Expand Down
5 changes: 5 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
marathon-consul () unreleased; urgency=low

* Initial import

-- Tomasz Janiszewski <tomasz.janiszewski@allegrogroup.com> Thu, 10 Dec 2015 09:40:43 +0100
35 changes: 35 additions & 0 deletions debian/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"Consul": {
"Auth": {
"Enabled": false,
"Username": "",
"Password": ""
},
"Port": "8500",
"SslEnabled": false,
"SslVerify": true,
"SslCert": "",
"SslCaCert": "",
"Token": ""
},
"Web": {
"Listen": ":4000"
},
"Sync": {
"Interval": 900000000000
},
"Marathon": {
"Location": "localhost:8080",
"Protocol": "http",
"Username": "",
"Password": "",
"VerifySsl": true
},
"Metrics": {
"Target": "",
"Prefix": "default",
"Interval": 30000000000,
"Addr": ""
},
"LogLevel": "info"
}
17 changes: 17 additions & 0 deletions debian/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Source: marathon-consul
Section: misc
Priority: extra
Maintainer: Allegro Group
Build-Depends: debhelper (>= 9.1.0), golang-go
Standards-Version: 3.9.4

Package: marathon-consul
Architecture: any
Description: Marathon-consul service (performs Marathon Tasks registration as Consul Services for service discovery)
Marathon-consul takes information provided by the Marathon event bus and forwards it to Consul agents. It also re-syncs all the information from Marathon to Consul on startup and repeats it with given interval.

Package: marathon-consul-dev
Architecture: all
Description: Marathon-consul service (performs Marathon Tasks registration as Consul Services for service discovery) - development package
Marathon-consul takes information provided by the Marathon event bus and forwards it to Consul agents. It also re-syncs all the information from Marathon to Consul on startup and repeats it with given interval.

3 changes: 3 additions & 0 deletions debian/copyright
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Files: *
Copyright: 2015 Allegro Group
License: Apache-2.0
10 changes: 10 additions & 0 deletions debian/marathon-consul.upstart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
description "Marathon-consul service (performs Marathon Tasks registration as Consul Services for service discovery)"

start on runlevel [2345]
stop on runlevel [!2345]

respawn

script
exec marathon-consul --config-file=/etc/marathon-consul.d/config.json
end script
46 changes: 46 additions & 0 deletions debian/rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/make -f
# -*- makefile -*-

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

export GOPATH=$(CURDIR)::/usr/share/gocode

PKGDIR=debian/marathon-consul

%:
dh $@

clean:
dh_clean
rm -rf $(CURDIR)/bin/* $(CURDIR)/pkg/*
rm -f $(CURDIR)/goinstall.log

binary-arch: clean
dh_prep
dh_installdirs
cd $(CURDIR)/src && go install ./...

mkdir -p $(PKGDIR)/usr/bin $(CURDIR)/bin/
mkdir -p $(PKGDIR)/usr/share/gopkg/ $(CURDIR)/pkg/

BINFILES=$(wildcard $(CURDIR)/bin/*)

for x in$(BINFILES); do \
cp $$x $(PKGDIR)/usr/bin/; \
done;

PKGFILES=$(wildcard $(CURDIR)/pkg/*.a)
for x in$(PKGFILES); do \
cp $$x $(PKGDIR)/usr/share/gopkg/; \
done;

dh_strip
dh_compress
dh_fixperms
dh_installdeb
dh_gencontrol
dh_md5sums
dh_builddeb

binary: binary-arch
5 changes: 3 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import (
"net/http"
)

const Name = "marathon-consul"
const Version = "0.2.1"
var VERSION string

func main() {

log.WithField("Version", VERSION).Info("Starting marathon-consul")

config, err := config.New()
if err != nil {
log.Fatal(err.Error())
Expand Down

0 comments on commit 88b84ff

Please sign in to comment.