-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathMakefile
172 lines (132 loc) · 3.94 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
SHELL=/bin/bash
SHA1 := $(shell git rev-parse --short HEAD)
DOCKER_IMAGE ?= conductor
DOCKER_REGISTRY ?= hub.docker.com
DOCKER_NAMESPACE ?= nextdoor
TARGET_DOCKER_NAME := $(DOCKER_REGISTRY)/$(DOCKER_NAMESPACE)/$(DOCKER_IMAGE):$(DOCKER_TAG)
GO_DIRS=core cmd services shared
.PHONY: all imports test glide
all: imports docker-build docker-run
imports:
@goimports -local github.com/Nextdoor/conductor -w $(GO_DIRS)
test:
@./test.sh
glide:
@echo "Installing Go Dependencies"
@which glide || curl https://glide.sh/get | sh
glide install
define ARGS
--env LOGLEVEL=DEBUG \
--env-file envfile \
--volume $(shell pwd)/resources/frontend:/app/frontend \
--volume $(HOME)/.aws:/root/.aws \
--link conductor-postgres
endef
define NETWORK_ARGS
--publish 80:80 \
--publish 443:443 \
--hostname conductor-dev
endef
# Check if interactive shell.
INTERACTIVE = $(shell [ "`tty`" != "not a tty" ] && echo true || echo false)
ifeq ($(INTERACTIVE),true)
INTERACTIVE_ARGS = -it
else
INTERACTIVE_ARGS =
endif
define TEST_ARGS
--env-file testenv
endef
export ARGS
export NETWORK_ARGS
export INTERACTIVE_ARGS
export TEST_ARGS
TEST_CMD ?= "./..."
.PHONY: docker-build docker-run docker-test docker-stop docker-logs docker-tag docker-push docker-login docker-populate-cache
docker-build:
rm -rf .build && mkdir .build && cp -rf cmd core services shared go.mod go.sum .build
echo "Building Conductor Docker image..."
docker build -t $(DOCKER_IMAGE) .; result=$$?; rm -rf .build; exit $$result
docker-run: docker-stop
@echo "Running $(DOCKER_IMAGE)"
@[ -e envfile ] || touch envfile
docker run $$ARGS $$NETWORK_ARGS $$INTERACTIVE_ARGS --name $(DOCKER_IMAGE) $(DOCKER_IMAGE)
docker-test:
@[ -e testenv ] || touch testenv
@[ -e envfile ] || touch envfile
docker run $$ARGS $$INTERACTIVE_ARGS $$TEST_ARGS $(DOCKER_IMAGE) $(TEST_CMD)
docker-stop:
@echo "Stopping $(DOCKER_IMAGE)"
@docker rm -f $(DOCKER_IMAGE) \
|| echo "No existing container running."
docker-logs:
@echo "Running $(DOCKER_IMAGE)"
docker logs -f $(DOCKER_IMAGE)
docker-tag:
@echo "Tagging $(DOCKER_IMAGE) as $(TARGET_DOCKER_NAME)"
docker tag $(DOCKER_IMAGE) $(TARGET_DOCKER_NAME)
docker-push: docker-tag
@echo "Pushing $(DOCKER_IMAGE) to $(TARGET_DOCKER_NAME)"
docker push $(TARGET_DOCKER_NAME)
docker-login:
@echo "Logging into $(DOCKER_REGISTRY)"
@docker login \
-u $(DOCKER_USER) \
-p "$(value DOCKER_PASS)" $(DOCKER_REGISTRY)
docker-populate-cache:
@echo "Attempting to download $(DOCKER_IMAGE)"
@docker pull "$(DOCKER_REGISTRY)/$(DOCKER_NAMESPACE)/$(DOCKER_IMAGE)" && \
docker images -a || exit 0
.PHONY: frontend
frontend:
$(MAKE) -C frontend
PGDB=conductor
PGHOST=localhost
PGPORT=5432
PGUSER=conductor
PGPASS=conductor
PGDATA=/var/lib/postgresql/data/conductor
define PG_ARGS
--name conductor-postgres \
--publish 5432:5432 \
--env POSTGRES_USER=$(PGUSER) \
--env POSTGRES_PASSWORD=$(PGPASS) \
--env POSTGRES_DB=$(PGDB) \
--env PGDATA=$(PGDATA) \
--detach
endef
export PG_ARGS
.PHONY: postgres postgres-perm psql postgres-wipe test-data
postgres:
docker rm -f conductor-postgres || true
docker run $$PG_ARGS postgres
postgres-perm:
docker rm -f conductor-postgres || true
docker run $$PG_ARGS -v $$HOME/data/conductor:$(PGDATA) postgres
postgres-wipe:
docker exec conductor-postgres dropdb -h localhost -U conductor conductor || true
docker exec conductor-postgres createdb -h localhost -U conductor conductor || true
psql:
PGPASSWORD=$(PGPASS) \
psql \
-h $(PGHOST) \
-p $(PGPORT) \
-d $(PGDB) \
-U $(PGUSER)
test-data: postgres-wipe
export POSTGRES_HOST=localhost; \
export POSTGRES_PORT=5432; \
export ENABLE_DATADOG=false; \
set -a; \
if [[ -e testenv ]]; then \
source testenv; \
fi; \
go run cmd/test_data.go
# README.md manipulation
.PHONY: gravizool readme edit-readme
gravizool:
which gravizool || go get github.com/swaggy/gravizool && go get github.com/swaggy/gravizool
readme: gravizool
gravizool -b=false -e README.md
edit-readme: gravizool
gravizool -b=false -d README.md