diff --git a/Makefile b/Makefile index c9e120a..6076e6c 100644 --- a/Makefile +++ b/Makefile @@ -1,34 +1,64 @@ .SILENT : -.PHONY : build clean +.PHONY : volume build clean run shell test + +USERNAME:=ncarlier +APPNAME:=webhookd +IMAGE:=$(USERNAME)/$(APPNAME) TAG:=`git describe --abbrev=0 --tags` LDFLAGS:=-X main.buildVersion $(TAG) -APPNAME:=webhookd -ROOTPKG:=github.com/ncarlier +ROOTPKG:=github.com/$(USERNAME) PKGDIR:=$(GOPATH)/src/$(ROOTPKG) +define docker_run_flags +--rm \ +-v /var/run/docker.sock:/var/run/docker.sock \ +--env-file $(PWD)/etc/env.conf \ +-P \ +-i -t +endef + +ifdef DEVMODE + docker_run_flags += --volumes-from $(APPNAME)_volumes +endif all: build -prepare: +volume: + echo "Building $(APPNAME) volumes..." + sudo docker run -v $(PWD):/opt/$(APPNAME) -v ~/var/$(APPNAME):/var/opt/$(APPNAME) --name $(APPNAME)_volumes busybox true + +build: + echo "Building $(IMAGE) docker image..." + sudo docker build --rm -t $(IMAGE) . + +clean: + echo "Removing $(IMAGE) docker image..." + sudo docker rmi $(IMAGE) + +run: + echo "Running $(IMAGE) docker image..." + sudo docker run $(docker_run_flags) --name $(APPNAME) $(IMAGE) + +shell: + echo "Running $(IMAGE) docker image with shell access..." + sudo docker run $(docker_run_flags) --entrypoint="/bin/bash" $(IMAGE) -c /bin/bash + +test: + echo "Running tests..." + test.sh + +dist-prepare: rm -rf $(PKGDIR) mkdir -p $(PKGDIR) ln -s $(PWD)/src $(PKGDIR)/$(APPNAME) - -build: prepare - echo "Building $(APPNAME)..." - go build -ldflags "$(LDFLAGS)" -o bin/$(APPNAME) ./src - -clean: clean-dist - rm -f bin/$(APPNAME) - -clean-dist: rm -rf dist -dist: clean-dist +dist: dist-prepare # godep restore mkdir -p dist/linux/amd64 && GOOS=linux GOARCH=amd64 go build -o dist/linux/amd64/$(APPNAME) ./src tar -cvzf dist/$(APPNAME)-linux-amd64-$(TAG).tar.gz -C dist/linux/amd64 $(APPNAME) # mkdir -p dist/linux/i386 && GOOS=linux GOARCH=386 go build -o dist/linux/i386/$(APPNAME) ./src # tar -cvzf dist/$(APPNAME)-linux-i386-i386$(TAG).tar.gz -C dist/linux/i386 $(APPNAME) + diff --git a/bin/bash b/bin/bash deleted file mode 100755 index 7257fe4..0000000 --- a/bin/bash +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/sh - - -### -# Simple script to get a shell into the container. -### -sudo docker run \ - --name webhookd \ - --rm \ - --env-file="./etc/env.conf" \ - -v /var/run/docker.sock:/var/run/docker.sock \ - -v /home/nicolas/.ssh/deploy_rsa:/root/.ssh/id_rsa \ - -it \ - --entrypoint="/bin/bash" \ - ncarlier/webhookd \ - -c /bin/bash diff --git a/bin/start b/bin/start deleted file mode 100755 index 931db76..0000000 --- a/bin/start +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh -#-v ~/.ssh/deploy_rsa:/var/opt/webhookd/deploy_rsa \ -sudo docker run \ - --name webhookd \ - -v /var/run/docker.sock:/var/run/docker.sock \ - -v /home/nicolas/.ssh/deploy_rsa:/root/.ssh/id_rsa \ - -it --rm \ - -P \ - --env-file ./etc/env.conf \ - ncarlier/webhookd - diff --git a/bin/test b/bin/test deleted file mode 100755 index 808f737..0000000 --- a/bin/test +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh - -IP=`sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' webhookd` - -echo "Test bad URL" -curl -H "Content-Type: application/json" \ - --data @assets/bitbucket.json \ - http://$IP:8080/bad/action - -echo "Test Bitbucket hook" -curl -H "Content-Type: application/json" \ - --data @assets/bitbucket.json \ - http://$IP:8080/bitbucket/echo - -echo "Test Github hook" -curl -H "Content-Type: application/json" \ - --data @assets/github.json \ - http://$IP:8080/github/echo - -echo "Test Docker hook" -curl -H "Content-Type: application/json" \ - --data @assets/docker.json \ - http://$IP:8080/docker/echo -