-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathMakefile
179 lines (157 loc) · 4.57 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
NAMESPACE ?= hashbangctl
## Primary Targets
.PHONY: build
build: fetch docker-build
.PHONY: build-native
build-native:
GOBIN=$(PWD)/bin \
GOPATH=$(PWD)/go \
CGO_ENABLED=0 \
GOOS=linux \
GOARCH=amd64 \
go install ./...
.PHONY: serve
serve: docker-start docker-logs docker-stop
.PHONY: serve-native
serve-native:
API_URL="https://userdb.hashbang.sh/v1" \
API_TOKEN="eyJhbGciOiJIUzI1NiJ9.eyJyb2xlIjoiYXBpLXVzZXItY3JlYXRlIn0.iOcRzRAjPsT9DOhu5OSeRuQ38D3KL5NppsfyuZYiDeI" \
HOST_KEY_SEED="This is an insecure seed" \
bin/server
.PHONY: connect
connect:
SSH_AUTH_SOCK="" \
ssh \
-i test/keys/id_ed25519 \
-o UserKnownHostsFile=/dev/null \
-o StrictHostKeyChecking=no \
-p2222 localhost
.PHONY: test
test: \
docker-build-test \
docker-restart \
docker-test \
docker-stop
.PHONY: test-shell
test-shell: \
docker-build-test \
docker-restart \
docker-test-shell \
docker-stop
.PHONY: clean
clean: docker-clean
rm -rf ./go ./bin
.PHONY: fetch
fetch:
git submodule update --init --recursive
.PHONY: fetch-latest
fetch-latest:
git submodule foreach 'git checkout master && git pull'
## Secondary Targets
.PHONY: docker-build
docker-build:
docker build -t local/$(NAMESPACE) .
docker build -t local/$(NAMESPACE)-userdb test/modules/userdb/
docker build \
--build-arg=POSTGREST_VERSION=v6.0.2 \
-t local/$(NAMESPACE)-postgrest \
test/postgrest/
.PHONY: docker-restart
docker-restart: docker-stop docker-start
.PHONY: docker-start
docker-start:
docker network inspect $(NAMESPACE) \
|| docker network create $(NAMESPACE)
docker inspect -f '{{.State.Running}}' $(NAMESPACE) 2>/dev/null \
|| docker run \
--detach=true \
--name $(NAMESPACE) \
--network=$(NAMESPACE) \
--env API_URL="http://hashbangctl-postgrest:3000" \
--env API_TOKEN="eyJhbGciOiJIUzI1NiJ9.eyJyb2xlIjoiYXBpLXVzZXItY3JlYXRlIn0.iOcRzRAjPsT9DOhu5OSeRuQ38D3KL5NppsfyuZYiDeI" \
--env HOST_KEY_SEED="Replace me with something actually random" \
--expose="2222" \
-p "2222:2222" \
local/$(NAMESPACE)
docker inspect -f '{{.State.Running}}' $(NAMESPACE)-userdb 2>/dev/null \
|| docker run \
--rm \
--detach=true \
--name $(NAMESPACE)-userdb \
--network=$(NAMESPACE) \
--volume $(PWD)/test/test_data.sql:/docker-entrypoint-initdb.d/99-init.sql \
local/$(NAMESPACE)-userdb
docker inspect -f '{{.State.Running}}' $(NAMESPACE)-postgrest 2>/dev/null \
|| docker run \
--rm \
--detach=true \
--name $(NAMESPACE)-postgrest \
--network=$(NAMESPACE) \
--env PGRST_DB_URI="postgres://postgres@$(NAMESPACE)-userdb/userdb" \
--env PGRST_JWT_SECRET="a_test_only_postgrest_jwt_secret" \
--env PGRST_DB_ANON_ROLE="api-anon" \
--env PGRST_DB_SCHEMA="v1" \
local/$(NAMESPACE)-postgrest
.PHONY: docker-start-prod
docker-start-prod:
docker network inspect $(NAMESPACE) \
|| docker network create $(NAMESPACE)
docker inspect -f '{{.State.Running}}' $(NAMESPACE) 2>/dev/null \
|| docker run \
--detach=true \
--name $(NAMESPACE) \
--network=$(NAMESPACE) \
--env API_URL="https://userdb.hashbang.sh/v1" \
--expose="2222" \
-p "2222:2222" \
local/$(NAMESPACE)
.PHONY: docker-stop
docker-stop:
docker inspect -f '{{.State.Running}}' $(NAMESPACE) 2>/dev/null \
&& docker rm -f $(NAMESPACE) || true
docker inspect -f '{{.State.Running}}' $(NAMESPACE)-userdb 2>/dev/null \
&& docker rm -f $(NAMESPACE)-userdb || true
docker inspect -f '{{.State.Running}}' $(NAMESPACE)-postgrest 2>/dev/null \
&& docker rm -f $(NAMESPACE)-postgrest || true
.PHONY: docker-logs
docker-logs:
scripts/docker-logs $(NAMESPACE) $(NAMESPACE)-userdb $(NAMESPACE)-postgrest
.PHONY: docker-clean
docker-clean: docker-stop
docker image rm local/$(NAMESPACE)
docker image rm local/$(NAMESPACE)-test
docker image rm local/$(NAMESPACE)-postgrest
docker image rm local/$(NAMESPACE)-userdb
.PHONY: docker-test
docker-test:
docker run \
-it \
--rm \
--hostname=$(NAMESPACE)-test \
--name $(NAMESPACE)-test \
--network=$(NAMESPACE) \
--env CONTAINER=$(NAMESPACE) \
--env PGPASSWORD=test_password \
--env PGHOST=$(NAMESPACE)-userdb \
--env PGDATABASE=userdb \
--env PGUSER=postgres \
local/$(NAMESPACE)-test
.PHONY: docker-test-shell
docker-test-shell: \
docker-build docker-stop docker-start docker-build-test docker-stop
docker run \
--rm \
-it \
--hostname=$(NAMESPACE)-test \
--name $(NAMESPACE)-test \
--network=$(NAMESPACE) \
--env CONTAINER=$(NAMESPACE) \
--env PGPASSWORD=test_password \
--env PGHOST=$(NAMESPACE)-userdb \
--env PGDATABASE=userdb \
--env PGUSER=postgres \
local/$(NAMESPACE)-test \
bash
.PHONY: docker-build-test
docker-build-test:
docker build -t local/$(NAMESPACE)-test test/