-
Notifications
You must be signed in to change notification settings - Fork 18
/
Makefile
99 lines (77 loc) · 2.6 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
.PHONY: all release-dirs release-build release-copy release-check release
DEPS := $(wildcard *.go)
BUILD_IMAGE := "hello-world-build"
PRODUCTION_IMAGE := "hello-world"
PRODUCTION_NAME := "hello-production"
DEPLOY_ACCOUNT := "appleboy"
export PROJECT_PATH = /go/src/github.com/appleboy/go-hello
DIST := dist
EXECUTABLE := go-hello
TARGETS ?= linux darwin windows
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
VERSION ?= $(shell git describe --tags --always || git rev-parse --short HEAD)
endif
all: build server
install:
glide install
update:
glide update
build:
docker build -t $(BUILD_IMAGE) -f Dockerfile.build .
docker run $(BUILD_IMAGE) > build.tar.gz
docker build -t $(PRODUCTION_IMAGE) -f Dockerfile.dist .
server:
-docker rm -f hello-production
-docker run -d -p 8088:8000 --name $(PRODUCTION_NAME) $(PRODUCTION_IMAGE)
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)
hello: ${DEPS}
GO15VENDOREXPERIMENT=1 go build
test:
go test -v -cover
docker_compose_test: dist-clean
docker-compose -f docker/docker-compose.yml config
docker-compose -f docker/docker-compose.yml run golang-hello-testing
docker-compose -f docker/docker-compose.yml down
docker_test: dist-clean
docker run --rm \
-v $(PWD):$(PROJECT_PATH) \
-w=$(PROJECT_PATH) \
appleboy/golang-testing \
sh -c "make install && coverage all"
release: release-dirs release-build release-copy release-check
release-dirs:
mkdir -p $(DIST)/binaries $(DIST)/release
release-build:
@which gox > /dev/null; if [ $$? -ne 0 ]; then \
go get -u github.com/mitchellh/gox; \
fi
gox -os="$(TARGETS)" -arch="amd64 386" -tags="$(TAGS)" -ldflags="$(EXTLDFLAGS)-s -w $(LDFLAGS)" -output="$(DIST)/binaries/$(EXECUTABLE)-$(VERSION)-{{.OS}}-{{.Arch}}"
release-copy:
$(foreach file,$(wildcard $(DIST)/binaries/$(EXECUTABLE)-*),cp $(file) $(DIST)/release/$(notdir $(file));)
release-check:
cd $(DIST)/release; $(foreach file,$(wildcard $(DIST)/release/$(EXECUTABLE)-*),sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;)
clean:
-rm -rf .cover
-rm -rf build.tar.gz
dist-clean: clean
-docker rmi -f $(BUILD_IMAGE)
-docker rm -f $(PRODUCTION_NAME)
-docker rmi -f $(PRODUCTION_IMAGE)
-docker-compose -f docker/docker-compose.yml down