-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
83 lines (70 loc) · 2.11 KB
/
Makefile
File metadata and controls
83 lines (70 loc) · 2.11 KB
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
VERSION := 0.4.1
USERNAME := unblee
BINNAME := mirror
REPONAME := $(BINNAME)
REVISION := $(shell git rev-parse --short HEAD)
GO_VERSION := 1.8.0
LDFLAGS := -w -s \
-X main.Version=$(VERSION) \
-X main.Revision=$(REVISION) \
-X main.GoVersion=$(GO_VERSION) \
-extldflags '-static'
BUILD_REPO_ROOT := /go/src/$(REPONAME)
RELEASE_BIN_DIR := $(BUILD_REPO_ROOT)/release/bin
RELEASE_ARCHIVE_DIR := $(BUILD_REPO_ROOT)/release/archive
DOCKER_ENV := -e VERSION=$(VERSION) \
-e USERNAME=$(USERNAME) \
-e BINNAME=$(BINNAME) \
-e REPONAME=$(REPONAME) \
-e LDFLAGS='$(LDFLAGS)' \
-e BUILD_REPO_ROOT='$(BUILD_REPO_ROOT)' \
-e RELEASE_BIN_DIR='$(RELEASE_BIN_DIR)' \
-e RELEASE_ARCHIVE_DIR='$(RELEASE_ARCHIVE_DIR)' \
-e GITHUB_TOKEN='$(GITHUB_TOKEN)'
DOCKER_RUN_OPT := -v $(PWD):$(BUILD_REPO_ROOT) \
-w /go/src/$(BINNAME) \
$(DOCKER_ENV)
DOCKER_RUN := docker run -it --rm $(DOCKER_RUN_OPT) golang:$(GO_VERSION)-alpine
.PHONY: gh-release
gh-release: archive
git push
$(DOCKER_RUN) sh scripts/gh_release.sh
.PHONY: archive
archive: bin-build
$(DOCKER_RUN) sh scripts/archive.sh
.PHONY: dh-release
dh-release: docker-build
docker push $(USERNAME)/$(BINNAME):$(VERSION)
docker push $(USERNAME)/$(BINNAME):latest
.PHONY: docker-build
docker-build: bin-build
cp -f release/bin/$(BINNAME)-$(VERSION)-linux-amd64/$(BINNAME) $(BINNAME)
docker build -t $(USERNAME)/$(BINNAME):$(VERSION) .
docker tag $(USERNAME)/$(BINNAME):$(VERSION) $(USERNAME)/$(BINNAME):latest
rm -f $(BINNAME)
.PHONY: bin-build
bin-build: deps
$(DOCKER_RUN) sh scripts/build.sh
.PHONY: deps
deps:
glide install
.PHONY: example-up
example-up: example-stop docker-build
{ \
cd example; \
docker-compose up -d; \
}
.PHONY: example-stop
example-stop:
{ \
cd example; \
docker-compose stop; \
docker-compose rm -f; \
}
.PHONY: test
test:
go test -v `glide novendor | grep -v example`
.PHONY: clean
clean:
rm -fr release/archive
rm -fr release/bin