forked from bogdan-radocea/syros
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
212 lines (176 loc) · 6.99 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
SHELL:=/bin/bash
APP_VERSION?=1.2.6
# build vars
DIST:=$$(pwd)/dist
BUILD_DATE:=$(shell date -u +%Y-%m-%d_%H.%M.%S)
GIT_REPOSITORY:=github.com/stefanprodan/syros
GIT_COMMIT:=$(shell git rev-parse HEAD)
GIT_BRANCH:="master"
MAINTAINER:="Stefan Prodan"
# go tools
PACKAGES:=$(shell go list ./... | grep -v '/vendor/')
VETARGS:=-asmdecl -atomic -bool -buildtags -copylocks -methods -nilfunc -rangeloops -shift -structtags -unsafeptr
# run vars
MONGO?=192.168.1.135:27017
NATS?=nats://192.168.1.135:4222
#deploy vars
REGISTRY?=index.docker.io
REPOSITORY?=stefanprodan
TIME_START:=$(shell date +%s)
define DURATION
@time_end=`date +%s` ; time_exec=`awk -v "TS=${TIME_START}" -v "TE=$$time_end" 'BEGIN{TD=TE-TS;printf "%02dm:%02ds\n",TD/(60)%60,TD%60}'` ; echo "$@ duration $${time_exec} "
endef
bin:
@go get github.com/golang/dep/cmd/dep
@dep ensure
@mkdir dist
@go build -ldflags "-X main.version=$(APP_VERSION)" -o dist/syros-pgha github.com/stefanprodan/syros/pgha
@go build -ldflags "-X main.version=$(APP_VERSION)" -o dist/syros-deployctl github.com/stefanprodan/syros/deployctl
@ls -la dist
@dist/syros-pgha -Version
build:
@echo ">>> Building syros-ui-build image"
@docker build -t syros-ui-build:$(BUILD_DATE) -f build.node.dockerfile .
@echo ">>> Building syros-ui"
@docker run --rm -v "$(DIST)/ui:/usr/src/app/dist" syros-ui-build:$(BUILD_DATE) \
bash -c "npm run build"
@docker rmi syros-ui-build:$(BUILD_DATE)
@echo ">>> Building syros-services-build image"
@docker build -t syros-services-build:$(BUILD_DATE) -f build.golang.dockerfile .
@echo ">>> building syros-agent"
@docker run --rm -v "$(DIST):/go/dist" syros-services-build:$(BUILD_DATE) \
go build -ldflags "-X main.version=$(APP_VERSION)" -o /go/dist/syros-agent github.com/stefanprodan/syros/agent
@echo ">>> Building syros-indexer"
@docker run --rm -v "$(DIST):/go/dist" syros-services-build:$(BUILD_DATE) \
go build -ldflags "-X main.version=$(APP_VERSION)" -o /go/dist/syros-indexer github.com/stefanprodan/syros/indexer
@echo ">>> Building syros-api"
@docker run --rm -v "$(DIST):/go/dist" syros-services-build:$(BUILD_DATE) \
go build -ldflags "-X main.version=$(APP_VERSION)" -o /go/dist/syros-api github.com/stefanprodan/syros/api
@docker rmi syros-services-build:$(BUILD_DATE)
@echo ">>> Build artifacts:"
@find dist -type f -print0 | xargs -0 ls -t
$(DURATION)
pack:
@echo ">>> Building syros-app image for deploy"
@docker build -t syros-app:$(APP_VERSION) \
--build-arg APP_VERSION=$(APP_VERSION) \
--build-arg BUILD_DATE=$(BUILD_DATE) \
--build-arg GIT_REPOSITORY=$(GIT_REPOSITORY) \
--build-arg GIT_BRANCH=$(GIT_BRANCH) \
--build-arg GIT_COMMIT=$(GIT_COMMIT) \
--build-arg MAINTAINER=$(MAINTAINER) \
-f deploy.app.dockerfile .
@echo ">>> Building syros-indexer image for deploy"
@docker build -t syros-indexer:$(APP_VERSION) \
--build-arg APP_VERSION=$(APP_VERSION) \
--build-arg BUILD_DATE=$(BUILD_DATE) \
--build-arg GIT_REPOSITORY=$(GIT_REPOSITORY) \
--build-arg GIT_BRANCH=$(GIT_BRANCH) \
--build-arg GIT_COMMIT=$(GIT_COMMIT) \
--build-arg MAINTAINER=$(MAINTAINER) \
-f deploy.indexer.dockerfile .
@echo ">>> Building syros-agent image for deploy"
@docker build -t syros-agent:$(APP_VERSION) \
--build-arg APP_VERSION=$(APP_VERSION) \
--build-arg BUILD_DATE=$(BUILD_DATE) \
--build-arg GIT_REPOSITORY=$(GIT_REPOSITORY) \
--build-arg GIT_BRANCH=$(GIT_BRANCH) \
--build-arg GIT_COMMIT=$(GIT_COMMIT) \
--build-arg MAINTAINER=$(MAINTAINER) \
-f deploy.agent.dockerfile .
@echo ">>> Images ready for deploy:"
@docker images | grep syros
$(DURATION)
run:
@echo ">>> Starting syros-app container"
@docker run -dp 8888:8888 --name syros-app-$(APP_VERSION) \
--restart unless-stopped \
syros-app:$(APP_VERSION) \
-MongoDB=$(MONGO) \
-LogLevel=info
@echo ">>> Starting syros-indexer container"
@docker run -dp 8887:8887 --name syros-indexer-$(APP_VERSION) \
--restart unless-stopped \
syros-indexer:$(APP_VERSION) \
-MongoDB=$(MONGO) \
-DatabaseStale=0 \
-Nats=$(NATS) \
-LogLevel=info
@echo ">>> Starting syros-agent container"
@docker run -dp 8886:8886 --name syros-agent-$(APP_VERSION) \
--restart unless-stopped \
-v /var/run/docker.sock:/var/run/docker.sock:ro \
syros-agent:$(APP_VERSION) \
-DockerApiAddresses=unix:///var/run/docker.sock \
-Environment=dev \
-Nats=$(NATS) \
-LogLevel=info
@echo ">>> syros-app logs:"
@docker logs syros-app-$(APP_VERSION)
@echo ">>> syros-indexer logs:"
@docker logs syros-indexer-$(APP_VERSION)
@echo ">>> syros-agent logs:"
@docker logs syros-agent-$(APP_VERSION)
$(DURATION)
test:
@echo ">>> Checking syros-app status"
@curl --fail http://localhost:8888/status
@echo ">>> Checking syros-app auth endpoint"
$(eval TOKEN := $(shell curl --fail -X POST http://localhost:8888/api/auth/login \
-d '{"name":"admin","password":"admin"}' \
-H "Content-type: application/json"))
@echo ">>> JWT token acquired: $(TOKEN)"
@echo ">>> Checking syros-app hosts endpoint"
@curl --fail http://localhost:8888/api/docker/hosts \
-H "Authorization: Bearer $(TOKEN)" \
-H "Content-type: application/json"
@echo ">>> Checking syros-indexer status"
@curl --fail http://localhost:8887/status
@echo ">>> Checking syros-agent status"
@curl --fail http://localhost:8886/status
$(DURATION)
push:
@echo $(DOCKER_PASS) | docker login -u "$(DOCKER_USER)" --password-stdin
@echo ">>> Pushing syros-app to $(REGISTRY)/$(REPOSITORY)"
@docker tag syros-app:$(APP_VERSION) $(REPOSITORY)/syros-app:$(APP_VERSION)
@docker tag syros-app:$(APP_VERSION) $(REPOSITORY)/syros-app:latest
@docker push $(REPOSITORY)/syros-app:$(APP_VERSION)
@docker push $(REPOSITORY)/syros-app:latest
@echo ">>> Pushing syros-indexer to $(REGISTRY)/$(REPOSITORY)"
@docker tag syros-indexer:$(APP_VERSION) $(REPOSITORY)/syros-indexer:$(APP_VERSION)
@docker tag syros-indexer:$(APP_VERSION) $(REPOSITORY)/syros-indexer:latest
@docker push $(REPOSITORY)/syros-indexer:$(APP_VERSION)
@docker push $(REPOSITORY)/syros-indexer:latest
@echo ">>> Pushing syros-agent to $(REGISTRY)/$(REPOSITORY)"
@docker tag syros-agent:$(APP_VERSION) $(REPOSITORY)/syros-agent:$(APP_VERSION)
@docker tag syros-agent:$(APP_VERSION) $(REPOSITORY)/syros-agent:latest
@docker push $(REPOSITORY)/syros-agent:$(APP_VERSION)
@docker push $(REPOSITORY)/syros-agent:latest
$(DURATION)
fmt:
@echo ">>> Running go fmt $(PACKAGES)"
@go fmt $(PACKAGES)
$(DURATION)
vet:
@echo ">>> Running go vet $(VETARGS)"
@go list ./... \
| grep -v /vendor/ \
| cut -d '/' -f 4- \
| xargs -n1 \
go tool vet $(VETARGS) ;\
if [ $$? -ne 0 ]; then \
echo ""; \
echo "go vet failed"; \
fi
$(DURATION)
clean:
@if [ -d "$(DIST)" ]; then \
echo "output directory found at $(DIST) removing content"; \
rm -rf $(DIST); \
fi
$(DURATION)
purge:
@docker rm -f syros-app-$(APP_VERSION) syros-agent-$(APP_VERSION) syros-indexer-$(APP_VERSION) || true
@docker rmi $$(docker images | awk '$$1 ~ /syros/ { print $$3 }') || true
$(DURATION)
.PHONY: build