Support docker build for production.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
parent
711a25eb6d
commit
d8835c0d4b
|
@ -37,3 +37,4 @@ Dockerfile.tmp
|
|||
.cover
|
||||
*.pid
|
||||
*.db*
|
||||
coverage.txt
|
||||
|
|
|
@ -26,7 +26,6 @@ before_install:
|
|||
- curl https://glide.sh/get | sh
|
||||
|
||||
install:
|
||||
- export GO15VENDOREXPERIMENT=1
|
||||
- go get github.com/mattn/goveralls
|
||||
- make docker_build
|
||||
- make docker_production
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
FROM centurylink/ca-certs
|
||||
EXPOSE 8088
|
||||
|
||||
ADD config/config.yml /
|
||||
ADD bin/gorush /
|
||||
|
||||
ENTRYPOINT ["/gorush"]
|
||||
CMD ["-c", "config.yml"]
|
94
Makefile
94
Makefile
|
@ -1,22 +1,36 @@
|
|||
.PHONY: all
|
||||
|
||||
DEPS := $(wildcard *.go)
|
||||
BUILD_IMAGE := "gorush-build"
|
||||
# docker hub project name.
|
||||
PRODUCTION_IMAGE := "gorush"
|
||||
DEPLOY_ACCOUNT := "appleboy"
|
||||
ifeq ($(VERSION),)
|
||||
VERSION := $(shell git describe --tags --always || git rev-parse --short HEAD)
|
||||
endif
|
||||
TARGETS_NOVENDOR := $(shell glide novendor)
|
||||
export PROJECT_PATH = /go/src/github.com/appleboy/gorush
|
||||
|
||||
DIST := dist
|
||||
EXECUTABLE := gorush
|
||||
|
||||
BUILD_IMAGE := "gorush-build"
|
||||
DEPLOY_ACCOUNT := appleboy
|
||||
DEPLOY_IMAGE := $(EXECUTABLE)
|
||||
|
||||
TARGETS ?= linux/*,darwin/*
|
||||
PACKAGES ?= $(shell go list ./... | grep -v /vendor/)
|
||||
SOURCES ?= $(shell find . -name "*.go" -type f)
|
||||
TAGS ?=
|
||||
LDFLAGS += -X 'main.Version=$(VERSION)'
|
||||
|
||||
ifneq ($(shell uname), Darwin)
|
||||
EXTLDFLAGS = -extldflags "-static" $(null)
|
||||
else
|
||||
EXTLDFLAGS =
|
||||
endif
|
||||
|
||||
ifneq ($(DRONE_TAG),)
|
||||
VERSION ?= $(DRONE_TAG)
|
||||
else
|
||||
ifneq ($(DRONE_BRANCH),)
|
||||
VERSION ?= $(DRONE_BRANCH)
|
||||
else
|
||||
VERSION ?= $(shell git describe --tags --always || git rev-parse --short HEAD)
|
||||
endif
|
||||
endif
|
||||
|
||||
all: build
|
||||
|
||||
init:
|
||||
|
@ -30,20 +44,43 @@ ifeq ($(ANDROID_TEST_TOKEN),)
|
|||
endif
|
||||
@echo "Already set ANDROID_API_KEY and ANDROID_TEST_TOKEN globale variable."
|
||||
|
||||
install:
|
||||
fmt:
|
||||
go fmt $(PACKAGES)
|
||||
|
||||
vet:
|
||||
go vet $(PACKAGES)
|
||||
|
||||
errcheck:
|
||||
@which errcheck > /dev/null; if [ $$? -ne 0 ]; then \
|
||||
go get -u github.com/kisielk/errcheck; \
|
||||
fi
|
||||
errcheck $(PACKAGES)
|
||||
|
||||
lint:
|
||||
@which golint > /dev/null; if [ $$? -ne 0 ]; then \
|
||||
go get -u github.com/golang/lint/golint; \
|
||||
fi
|
||||
for PKG in $(PACKAGES); do golint -set_exit_status $$PKG || exit 1; done;
|
||||
|
||||
dep_install:
|
||||
glide install
|
||||
|
||||
update:
|
||||
glide update
|
||||
dep_update:
|
||||
glide up
|
||||
|
||||
build_static:
|
||||
go build -ldflags='${EXTLDFLAGS}-s -w -X main.Version=${VERSION}' -o bin/gorush gorush.go
|
||||
install: $(wildcard *.go)
|
||||
go install -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)'
|
||||
|
||||
build: clean
|
||||
build: $(EXECUTABLE)
|
||||
|
||||
$(EXECUTABLE): $(SOURCES)
|
||||
go build -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o bin/$@
|
||||
|
||||
corss_build: clean
|
||||
sh script/build.sh $(VERSION)
|
||||
|
||||
test: redis_test boltdb_test memory_test buntdb_test leveldb_test config_test
|
||||
go test -v -cover ./gorush/...
|
||||
test:
|
||||
for PKG in $(PACKAGES); do go test -v -cover -coverprofile $$GOPATH/src/$$PKG/coverage.txt $$PKG || exit 1; done;
|
||||
|
||||
redis_test: init
|
||||
go test -v -cover ./storage/redis/...
|
||||
|
@ -66,6 +103,14 @@ config_test: init
|
|||
html:
|
||||
go tool cover -html=.cover/coverage.txt
|
||||
|
||||
docker_binary_build:
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o bin/$@
|
||||
|
||||
docker_image:
|
||||
docker build -t $(DEPLOY_ACCOUNT)/$(DEPLOY_IMAGE) -f Dockerfile .
|
||||
|
||||
docker_release: docker_binary_build docker_image
|
||||
|
||||
docker_build:
|
||||
tar -zcvf build.tar.gz gorush.go gorush config storage Makefile glide.lock glide.yaml
|
||||
sed -e "s/#VERSION#/$(VERSION)/g" docker/Dockerfile.build > docker/Dockerfile.tmp
|
||||
|
@ -73,24 +118,23 @@ docker_build:
|
|||
docker run --rm $(BUILD_IMAGE) > gorush.tar.gz
|
||||
|
||||
docker_production:
|
||||
docker build -t $(PRODUCTION_IMAGE) -f docker/Dockerfile.dist .
|
||||
docker build -t $(EXECUTABLE) -f docker/Dockerfile.dist .
|
||||
|
||||
docker_deploy:
|
||||
ifeq ($(tag),)
|
||||
@echo "Usage: make $@ tag=<tag>"
|
||||
@exit 1
|
||||
endif
|
||||
docker tag $(PRODUCTION_IMAGE):latest $(DEPLOY_ACCOUNT)/$(PRODUCTION_IMAGE):$(tag)
|
||||
docker push $(DEPLOY_ACCOUNT)/$(PRODUCTION_IMAGE):$(tag)
|
||||
docker tag $(EXECUTABLE):latest $(DEPLOY_ACCOUNT)/$(EXECUTABLE):$(tag)
|
||||
docker push $(DEPLOY_ACCOUNT)/$(EXECUTABLE):$(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
|
||||
docker-compose -p ${EXECUTABLE} -f docker/docker-compose.testing.yml run gorush
|
||||
docker-compose -p ${EXECUTABLE} -f docker/docker-compose.testing.yml down
|
||||
|
||||
clean:
|
||||
go clean -x -i ./...
|
||||
find . -name coverage.txt -delete
|
||||
-rm -rf build.tar.gz \
|
||||
gorush.tar.gz bin/* \
|
||||
gorush.tar.gz \
|
||||
|
|
Loading…
Reference in New Issue