From 085d19832a49fd2ba2ce7e1ce363a817f5b7342e Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Mon, 15 Aug 2016 20:43:34 +0800 Subject: [PATCH] update makefile. Signed-off-by: Bo-Yi Wu --- .travis.yml | 2 -- Makefile | 21 +++++++++++++++------ docker/Dockerfile.build | 2 +- docker/Dockerfile.dist | 21 ++++++++------------- script/build.sh | 2 +- 5 files changed, 25 insertions(+), 23 deletions(-) diff --git a/.travis.yml b/.travis.yml index ee0cd1b..0d646f6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -39,8 +39,6 @@ script: after_success: - test "$TRAVIS_BRANCH" == "master" && test "$TRAVIS_GO_VERSION" == "1.6.3" && test "$TRAVIS_PULL_REQUEST" == "false" && docker login -e="$DOCKER_EMAIL" -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD" - - test "$TRAVIS_BRANCH" == "master" && test "$TRAVIS_GO_VERSION" == "1.6.3" - && test "$TRAVIS_PULL_REQUEST" == "false" && cd $TRAVIS_BUILD_DIR && make docker_build - test "$TRAVIS_BRANCH" == "master" && test "$TRAVIS_GO_VERSION" == "1.6.3" && test "$TRAVIS_PULL_REQUEST" == "false" && cd $TRAVIS_BUILD_DIR && make deploy tag=latest - bash <(curl -s https://codecov.io/bash) -f .cover/coverage.txt diff --git a/Makefile b/Makefile index 12bfe69..393ab21 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,12 @@ VERSION := $(shell git describe --tags) TARGETS_NOVENDOR := $(shell glide novendor) export PROJECT_PATH = /go/src/github.com/appleboy/gorush +ifneq ($(shell uname), Darwin) + EXTLDFLAGS = -extldflags "-static" $(null) +else + EXTLDFLAGS = +endif + all: build init: @@ -28,6 +34,9 @@ install: update: glide update +build_static: + go build -ldflags="${EXTLDFLAGS}-s -w -X main.Version=${VERSION}" -o bin/gorush gorush.go + build: clean sh script/build.sh $(VERSION) @@ -58,14 +67,10 @@ docker_build: clean docker build --rm -t $(BUILD_IMAGE) -f docker/Dockerfile.tmp . docker run --rm $(BUILD_IMAGE) > gorush.tar.gz -docker_test: init clean - docker-compose -p ${PRODUCTION_IMAGE} -f docker/docker-compose.testing.yml run gorush - docker-compose -p ${PRODUCTION_IMAGE} -f docker/docker-compose.testing.yml down - -docker_production: docker_build +docker_production: docker build --rm -t $(PRODUCTION_IMAGE) -f docker/Dockerfile.dist . -deploy: docker_production +deploy: docker_build docker_production ifeq ($(tag),) @echo "Usage: make $@ tag=" @exit 1 @@ -73,6 +78,10 @@ endif docker tag $(PRODUCTION_IMAGE):latest $(DEPLOY_ACCOUNT)/$(PRODUCTION_IMAGE):$(tag) docker push $(DEPLOY_ACCOUNT)/$(PRODUCTION_IMAGE):$(tag) +docker_test: init clean + docker-compose -p ${PRODUCTION_IMAGE} -f docker/docker-compose.testing.yml run gorush + docker-compose -p ${PRODUCTION_IMAGE} -f docker/docker-compose.testing.yml down + fmt: @echo $(TARGETS_NOVENDOR) | xargs go fmt diff --git a/docker/Dockerfile.build b/docker/Dockerfile.build index f8ad4b5..6b48613 100644 --- a/docker/Dockerfile.build +++ b/docker/Dockerfile.build @@ -7,6 +7,6 @@ RUN mkdir -p $GOPATH/src/github.com/appleboy/gorush Add build.tar.gz $GOPATH/src/github.com/appleboy/gorush/ WORKDIR $GOPATH/src/github.com/appleboy/gorush RUN make install -RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags="-s -w -X main.Version=${VERSION}" -o bin/gorush gorush.go +RUN CGO_ENABLED=0 make build_static CMD tar -C bin -czf - gorush diff --git a/docker/Dockerfile.dist b/docker/Dockerfile.dist index e8b9386..47462d5 100644 --- a/docker/Dockerfile.dist +++ b/docker/Dockerfile.dist @@ -1,14 +1,9 @@ -FROM alpine - -MAINTAINER Bo-Yi Wu - -RUN apk update && apk upgrade \ - && apk add ca-certificates \ - && rm -rf /var/cache/apk/* - -RUN mkdir /app -ADD gorush.tar.gz /app/ -ADD config/config.yml /app/config/ -WORKDIR /app -ENTRYPOINT ["./gorush", "-c", "config/config.yml"] +FROM centurylink/ca-certs EXPOSE 8088 + +ADD config/config.yml / + +ADD gorush.tar.gz / + +ENTRYPOINT ["/gorush"] +CMD ["-c", "config.yml"] diff --git a/script/build.sh b/script/build.sh index 4824484..639ec6c 100755 --- a/script/build.sh +++ b/script/build.sh @@ -10,7 +10,7 @@ for GOOS in $OS; do (test "$GOOS" = "windows") && EXE="gorush.exe" echo "Build: ${GOOS}, Arch: ${GOARCH}, EXE: ${EXE}" - GOOS=$GOOS GOARCH=$GOARCH go build -ldflags="-s -w -X main.Version=${VERSION}" -o bin/$GOOS/$GOARCH/${EXE} gorush.go; + GOOS=$GOOS GOARCH=$GOARCH CGO_ENABLED=0 go build -ldflags="-s -w -X main.Version=${VERSION}" -o bin/$GOOS/$GOARCH/${EXE} gorush.go; tar -C bin/$GOOS/$GOARCH -czf bin/gorush-$VERSION-$GOOS-$GOARCH.tar.gz gorush done done