forked from bepress/camo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
127 lines (104 loc) · 4.63 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# Copyright 2017 Berkeley Electronic Press.
# All rights reserved.
#
.SILENT: ; # no need for @
PROJECT =camo
PROJECT_DIR =$(shell pwd)
GOFILES :=$(shell find . -name '*.go' -not -path './vendor/*')
GOPACKAGES :=$(shell go list ./... | grep -v /vendor/| grep -v /checkers)
OS := $(shell go env GOOS)
ARCH := $(shell go env GOARCH)
GITHASH :=$(shell git rev-parse --short HEAD)
GITBRANCH :=$(shell git rev-parse --abbrev-ref HEAD)
GITTAGORBRANCH :=$(shell sh -c 'git describe --always --dirty 2>/dev/null')
BUILDDATE :=$(shell date -u +%Y%m%d%H%M)
GO_LDFLAGS ?= -s -w
GO_BUILD_FLAGS :=-ldflags "${GOLDFLAGS} -X main.BuildVersion=${GITTAGORBRANCH} -X main.GitHash=${GITHASH} -X main.GitBranch=${GITBRANCH} -X main.BuildDate=${BUILDDATE}"
## What if there's no CIRCLE_BUILD_NUM
ifeq ($$CIRCLE_BUILD_NUM, "")
BUILD_NUM:=""
else
CB:=$$CIRCLE_BUILD_NUM
BUILD_NUM:=$(CB)/
endif
ARTIFACT_BUCKET :="artifacts.production.bepress.com"
ARTIFACT_NAME :=$(PROJECT)-$(GITTAGORBRANCH)-$(GITHASH).tar.gz
ARTIFACT_DIR :=$(PROJECT_DIR)/_artifacts
WORKDIR :=$(PROJECT_DIR)/_workdir
default: build-linux
build-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $(WORKDIR)/$(PROJECT)_linux_amd64 $(GO_BUILD_FLAGS)
build:
CGO_ENABLED=0 go build -o $(WORKDIR)/$(PROJECT)_$(OS)_$(ARCH) $(GO_BUILD_FLAGS)
clean:
rm -f $(WORKDIR)/*
rm -f $(ARTIFACT_DIR)/*
rm -rf .cover
go clean -r
coverage:
./_misc/coverage.sh
coverage-html:
./_misc/coverage.sh --html
dependencies:
go get honnef.co/go/tools/cmd/megacheck
go get github.com/alecthomas/gometalinter
go get github.com/golang/dep/cmd/dep
dep ensure
gometalinter --install
develop: dependencies
(cd .git/hooks && ln -sf ../../_misc/pre-push.bash pre-push )
git flow init -d
lint:
# TODO(ro) 2017-09-18 See also
# https://github.com/360EntSecGroup-Skylar/goreporter
# metalinter runs the degault linters
# https://github.com/alecthomas/gometalinter#supported-linters and the enabled
# ones here.
# At the time of this writing megacheck runs gosimple, staticcheck, and
# unused. All production honnef tools.
# gometalinter --enable=goimports --enable=unparam --enable=unused --disable=golint --disable=govet .
echo "metalinter..."
gometalinter --enable=goimports --enable=unparam --enable=unused --disable=golint --disable=govet $(GOPACKAGES)
echo "megacheck..."
megacheck $(GOPACKAGES)
echo "golint..."
golint -set_exit_status $(GOPACKAGES)
echo "go vet..."
go vet --all $(GOPACKAGES)
master: build-linux
# NB: This target is intended for CircleCI.
# Copy the systemd unit into _workdir and make a tarball. Then copy to master
# prefix, copy latest to previous, next to latest and this build to next.
cp _misc/$(PROJECT).service _misc/awslogs.conf _misc/go_expvar.yaml $(WORKDIR)
mkdir -p $(PROJECT_DIR)/_artifacts
(cd $(PROJECT_DIR)/_artifacts && tar -czvf $(ARTIFACT_NAME) -C $(WORKDIR) .)
aws s3 cp $(ARTIFACT_DIR)/$(ARTIFACT_NAME) s3://$(ARTIFACT_BUCKET)/$(PROJECT)/master/$(GITHASH)/$(BUILD_NUM)$(PROJECT).tar.gz
release: build-linux
# NB: This target is intended for CircleCI.
# Copy the systemd unit into _workdir and make a tarball. Then copy to release
# prefix, copy latest to previous, next to latest and this release to next.
cp _misc/$(PROJECT).service _misc/awslogs.conf _misc/go_expvar.yaml $(WORKDIR)
mkdir -p $(PROJECT_DIR)/_artifacts
(cd $(PROJECT_DIR)/_artifacts && tar -czvf $(ARTIFACT_NAME) -C $(WORKDIR) .)
aws s3 cp $(ARTIFACT_DIR)/$(ARTIFACT_NAME) s3://$(ARTIFACT_BUCKET)/$(PROJECT)/release/$(GITTAGORBRANCH)-$(GITHASH)/$(BUILD_NUM)$(PROJECT).tar.gz
aws s3 cp $(ARTIFACT_DIR)/$(ARTIFACT_NAME) s3://$(ARTIFACT_BUCKET)/$(PROJECT)/staging/$(PROJECT).tar.gz || true
promote_production:
# NB: This target is intended for CircleCI.
aws s3 cp s3://$(ARTIFACT_BUCKET)/$(PROJECT)/production/$(PROJECT).tar.gz s3://$(ARTIFACT_BUCKET)/$(PROJECT)/previous/$(PROJECT).tar.gz || true
aws s3 cp s3://$(ARTIFACT_BUCKET)/$(PROJECT)/staging/$(PROJECT).tar.gz s3://$(ARTIFACT_BUCKET)/$(PROJECT)/production/$(PROJECT).tar.gz || true
deploy_staging:
# NB: This target is intended for CircleCI.
deploy --environment=staging --tags=Name=camo --tags=app=camo --account-id=628855009903
deploy_production:
# NB: This target is intended for CircleCI.
deploy --environment=production --tags=Name=camo --tags=app=camo --account-id=596234948724
download_e2e_tests:
mkdir -p $(WORKDIR)
aws s3 cp s3://$(ARTIFACT_BUCKET)/e2e_tests/production/e2e_tests_camo_$(OS)_$(ARCH) $(WORKDIR)/
chmod 755 $(WORKDIR)/e2e_tests_camo_$(OS)_$(ARCH)
e2e_tests:
$(WORKDIR)/e2e_tests_camo_$(OS)_$(ARCH)
test:
CGO_ENABLED=0 go test $(GOPACKAGES)
test-race:
CGO_ENABLED=1 go test -race $(GOPACKAGES)