From 2bf88e4a4f50c070a62041e81d5d4d2ced4cd045 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Mon, 11 Apr 2016 16:38:59 +0800 Subject: [PATCH 1/4] #10 support docker build image for production. Signed-off-by: Bo-Yi Wu --- .gitignore | 4 +++- Makefile | 10 +++++----- config/config.yml | 4 ++-- docker/Dockerfile.build | 7 ++++--- docker/Dockerfile.dist | 13 +++++++++++++ 5 files changed, 27 insertions(+), 11 deletions(-) create mode 100644 docker/Dockerfile.dist diff --git a/.gitignore b/.gitignore index 30aa775..8fb0034 100644 --- a/.gitignore +++ b/.gitignore @@ -25,8 +25,10 @@ _testmain.go gin-bin key.pem -config.yaml +config.yml bin/* .DS_Store coverage.out gopush/log/*.log +build.tar.gz +gopush.tar.gz diff --git a/Makefile b/Makefile index 01f7a66..b738c82 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,7 @@ VERSION=0.0.1 DEPS := $(wildcard *.go) BUILD_IMAGE := "appleboy/gopush-build:latest" TEST_IMAGE := "appleboy/gopush-testing:latest" +PRODUCTION_IMAGE := "appleboy/gopush" all: build @@ -15,15 +16,14 @@ test: cd gopush && go test -v -covermode=count -coverprofile=coverage.out docker_build: clean - tar -zcvf build.tar.gz gopush.go gopush script + tar -zcvf build.tar.gz gopush.go gopush docker build --rm -t $(BUILD_IMAGE) -f docker/Dockerfile.build . - docker run --rm $(BUILD_IMAGE) > bin.tar.gz - tar -zxvf bin.tar.gz - -rm -rf bin.tar.gz build.tar.gz + docker run --rm $(BUILD_IMAGE) > gopush.tar.gz + docker build --rm -t $(PRODUCTION_IMAGE) -f docker/Dockerfile.dist . docker_test: @docker build --rm -t $(TEST_IMAGE) -f docker/Dockerfile.testing . @docker run --rm -e ANDROID_TEST_TOKEN=$(ANDROID_TEST_TOKEN) -e ANDROID_API_KEY=$(ANDROID_API_KEY) $(TEST_IMAGE) sh -c "cd gopush && go test -v" clean: - rm -rf build.tar.gz bin.tar.gz bin/* + -rm -rf build.tar.gz gopush.tar.gz bin/* diff --git a/config/config.yml b/config/config.yml index 7db709a..66eeafe 100644 --- a/config/config.yml +++ b/config/config.yml @@ -11,8 +11,8 @@ api: stat_go_uri: "/api/status" android: - enabled: false - apikey: "" + enabled: true + apikey: "YOUR_API_KEY" ios: enabled: false diff --git a/docker/Dockerfile.build b/docker/Dockerfile.build index 1e318aa..d70de57 100644 --- a/docker/Dockerfile.build +++ b/docker/Dockerfile.build @@ -1,11 +1,12 @@ -FROM golang:1.6 +FROM golang:1.6-alpine MAINTAINER Bo-Yi Wu +RUN apk --update add git RUN mkdir -p /tmp/build Add build.tar.gz /tmp/build/ WORKDIR /tmp/build RUN go get -v -d -RUN sh script/build.sh +RUN GOOS=linux GOARCH=amd64 go build -ldflags="-w" -o bin/gopush gopush.go -CMD tar -czf - bin +CMD tar -C bin -czf - gopush diff --git a/docker/Dockerfile.dist b/docker/Dockerfile.dist new file mode 100644 index 0000000..d919fd8 --- /dev/null +++ b/docker/Dockerfile.dist @@ -0,0 +1,13 @@ +FROM alpine + +MAINTAINER Bo-Yi Wu + +RUN apk update && apk upgrade \ + && apk add ca-certificates \ + && rm -rf /var/cache/apk/* + +RUN mkdir /app +ADD gopush.tar.gz /app/ +WORKDIR /app +ENTRYPOINT ["./gopush", "-c", "config/config.yml"] +EXPOSE 8088 From d047841329af12f8088c279de21626066571ea37 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Mon, 11 Apr 2016 17:18:53 +0800 Subject: [PATCH 2/4] #10 support deploy production image to docker hub. Signed-off-by: Bo-Yi Wu --- Makefile | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index b738c82..449e9ac 100644 --- a/Makefile +++ b/Makefile @@ -3,9 +3,10 @@ VERSION=0.0.1 DEPS := $(wildcard *.go) -BUILD_IMAGE := "appleboy/gopush-build:latest" -TEST_IMAGE := "appleboy/gopush-testing:latest" -PRODUCTION_IMAGE := "appleboy/gopush" +BUILD_IMAGE := "gopush-build" +TEST_IMAGE := "gopush-testing" +PRODUCTION_IMAGE := "gopush" +DEPLOY_ACCOUNT := "appleboy" all: build @@ -25,5 +26,13 @@ docker_test: @docker build --rm -t $(TEST_IMAGE) -f docker/Dockerfile.testing . @docker run --rm -e ANDROID_TEST_TOKEN=$(ANDROID_TEST_TOKEN) -e ANDROID_API_KEY=$(ANDROID_API_KEY) $(TEST_IMAGE) sh -c "cd gopush && go test -v" +deploy: +ifeq ($(tag),) + @echo "Usage: make $@ tag=" + @exit 1 +endif + docker tag -f $(PRODUCTION_IMAGE):latest $(DEPLOY_ACCOUNT)/$(PRODUCTION_IMAGE):$(tag) + docker push $(DEPLOY_ACCOUNT)/$(PRODUCTION_IMAGE):$(tag) + clean: -rm -rf build.tar.gz gopush.tar.gz bin/* From ebcc9d6b363fb9458b08e60ce69f915feaeff166 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Mon, 11 Apr 2016 20:27:12 +0800 Subject: [PATCH 3/4] add default config.yml Signed-off-by: Bo-Yi Wu --- docker/Dockerfile.dist | 1 + 1 file changed, 1 insertion(+) diff --git a/docker/Dockerfile.dist b/docker/Dockerfile.dist index d919fd8..33e28d8 100644 --- a/docker/Dockerfile.dist +++ b/docker/Dockerfile.dist @@ -8,6 +8,7 @@ RUN apk update && apk upgrade \ RUN mkdir /app ADD gopush.tar.gz /app/ +ADD config /app/config WORKDIR /app ENTRYPOINT ["./gopush", "-c", "config/config.yml"] EXPOSE 8088 From 9cf4bdb85f1cb65178f3356e979fa29fe37a7ce6 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Mon, 11 Apr 2016 21:07:01 +0800 Subject: [PATCH 4/4] [ci skip] update readme. Signed-off-by: Bo-Yi Wu --- README.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3d82470..dde348e 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ The default endpoint is APNs development. Please add `-production` flag for APNs $ gopush -ios -m="your message" -i="API Key" -t="Device token" -production ``` -### Run gopush with web server +## Run gopush web server Please make sure your [config.yml](config/config.yml) exist. Default port is `8088`. @@ -97,6 +97,21 @@ $ http -v --verify=no --json GET https://localhost:8088/api/status ![statue screenshot](screenshot/status.png) +## Run gopush in Docker + +Set up `gopush` in the cloud in under 5 minutes with zero knowledge of Golang or Linux shell using our [gopush Docker image](https://hub.docker.com/r/appleboy/gopush/). + +```bash +$ docker pull appleboy/gopush +$ docker run -name gopush -p 80:8088 appleboy/gopush +``` + +Testing your gopush server. + +```bash +$ http -v --verify=no --json GET http://your.docker.host/api/status +``` + ## License Copyright 2016 Bo-Yi Wu [@appleboy](https://twitter.com/appleboy).