-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
255 lines (201 loc) · 7.84 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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
include .env-api
BIN := $(shell pwd)/bin
VERSION ?= $(shell git rev-parse --short HEAD)
GO?=$(shell which go)
export GOBIN := $(BIN)
export PATH := $(BIN):$(PATH)
BUILD_CMD := $(GO) install -ldflags "-X main.build=${VERSION}"
LOCAL_DEV_PATH = $(shell pwd)/infrastructure/local
DOCKER_COMPOSE_FILE := $(LOCAL_DEV_PATH)/docker-compose.yml
DOCKER_COMPOSE_FILE_INFRA := $(LOCAL_DEV_PATH)/docker-compose-infra.yml
DOCKER_COMPOSE_CMD := docker compose -p issuer -f $(DOCKER_COMPOSE_FILE)
DOCKER_COMPOSE_INFRA_CMD := docker compose -p issuer -f $(DOCKER_COMPOSE_FILE_INFRA)
ENVIRONMENT := ${ISSUER_API_ENVIRONMENT}
# Local environment overrides via godotenv
DOTENV_CMD = $(BIN)/godotenv
ENV = $(DOTENV_CMD) -f .env-issuer
.PHONY: build-local
build-local:
$(BUILD_CMD) ./cmd/...
.PHONY: build/docker
build/docker: ## Build the docker image.
DOCKER_BUILDKIT=1 \
docker build \
-f ./Dockerfile \
-t issuer/api:$(VERSION) \
--build-arg VERSION=$(VERSION) \
--build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
.
.PHONY: clean
clean: ## Go clean
$(GO) clean ./...
.PHONY: tests
tests:
$(GO) test -v ./... --count=1
.PHONY: test-race
test-race:
$(GO) test -v --race ./...
$(BIN)/oapi-codegen: tools.go go.mod go.sum ## install code generator for API files.
go get github.com/deepmap/oapi-codegen/cmd/oapi-codegen
$(GO) install github.com/deepmap/oapi-codegen/cmd/oapi-codegen
.PHONY: api
api: $(BIN)/oapi-codegen
$(BIN)/oapi-codegen -config ./api/config-oapi-codegen.yaml ./api/api.yaml > ./internal/api/api.gen.go
.PHONY: api-ui
api-ui: $(BIN)/oapi-codegen
$(BIN)/oapi-codegen -config ./api_ui/config-oapi-codegen.yaml ./api_ui/api.yaml > ./internal/api_ui/api.gen.go
.PHONY: up
up:
$(DOCKER_COMPOSE_INFRA_CMD) up -d redis postgres vault
.PHONY: run
run:
$(eval DELETE_FILE = $(shell if [ -f ./.env-ui ]; then echo "false"; else echo "true"; fi))
@if [ -f ./.env-ui ]; then echo "false"; else touch ./.env-ui; fi
COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_FILE="Dockerfile" $(DOCKER_COMPOSE_CMD) up -d api pending_publisher
@if [ $(DELETE_FILE) = "true" ] ; then rm ./.env-ui; fi
.PHONY: run-arm
run-arm:
@echo "WARN: Running ARM version is deprecated. 'make run' will be executed instead."
@make run
.PHONY: run-ui
run-ui: add-host-url-swagger
COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_FILE="Dockerfile" $(DOCKER_COMPOSE_CMD) up -d api-ui ui notifications pending_publisher
.PHONY: run-ui-arm
run-ui-arm: add-host-url-swagger
@echo "WARN: Running ARM version is deprecated. 'make run-ui' will be executed instead."
@make run-ui
.PHONY: build
build:
COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_FILE="Dockerfile" $(DOCKER_COMPOSE_CMD) build api pending_publisher initializer
.PHONY: build-arm
build-arm:
@echo "WARN: Running ARM version is deprecated. 'make build' will be executed instead."
@make build
.PHONY: build-ui
build-ui:
COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_FILE="Dockerfile" $(DOCKER_COMPOSE_CMD) build api-ui ui notifications pending_publisher
.PHONY: build-ui-arm
build-ui-arm:
@echo "WARN: Running ARM version is deprecated. 'make build-ui' will be executed instead."
@make build-ui
.PHONY: down
down:
$(DOCKER_COMPOSE_INFRA_CMD) down --remove-orphans
$(DOCKER_COMPOSE_CMD) down --remove-orphans
.PHONY: stop
stop:
$(DOCKER_COMPOSE_INFRA_CMD) stop
$(DOCKER_COMPOSE_CMD) stop
.PHONY: up-test
up-test:
$(DOCKER_COMPOSE_INFRA_CMD) up -d test_postgres vault test_local_files_apache
.PHONY: clean-vault
clean-vault:
rm -R infrastructure/local/.vault/data/init.out || true
rm -R infrastructure/local/.vault/file/core/ || true
rm -R infrastructure/local/.vault/file/logical/ || true
rm -R infrastructure/local/.vault/file/sys/ || true
rm -R infrastructure/local/.vault/policies || true
$(BIN)/platformid-migrate:
$(BUILD_CMD) ./cmd/migrate
$(BIN)/install-goose: go.mod go.sum
$(GO) install github.com/pressly/goose/v3
$(BIN)/golangci-lint: go.mod go.sum
$(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint
$(BIN)/godotenv: tools.go go.mod go.sum
$(GO) install github.com/joho/godotenv/cmd/godotenv
.PHONY: db/migrate
db/migrate: $(BIN)/install-goose $(BIN)/godotenv $(BIN)/platformid-migrate ## Install goose and apply migrations.
$(ENV) sh -c '$(BIN)/migrate'
.PHONY: lint
lint: $(BIN)/golangci-lint
$(BIN)/golangci-lint run
# usage: make private_key=xxx add-private-key
.PHONY: add-private-key
add-private-key:
docker exec issuer-vault-1 \
vault write iden3/import/pbkey key_type=ethereum private_key=$(private_key)
.PHONY: print-vault-token
print-vault-token:
$(eval TOKEN = $(shell docker logs issuer-vault-1 2>&1 | grep " .hvs" | awk '{print $$2}' | tail -1 ))
@echo $(TOKEN)
.PHONY: add-vault-token
add-vault-token:
$(eval TOKEN = $(shell docker logs issuer-vault-1 2>&1 | grep " .hvs" | awk '{print $$2}' | tail -1 ))
sed '/ISSUER_KEY_STORE_TOKEN/d' .env-issuer > .env-issuer.tmp
@echo ISSUER_KEY_STORE_TOKEN=$(TOKEN) >> .env-issuer.tmp
mv .env-issuer.tmp .env-issuer
.PHONY: run-initializer
run-initializer:
COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_FILE="Dockerfile" $(DOCKER_COMPOSE_CMD) up -d initializer
sleep 5
.PHONY: generate-issuer-did
generate-issuer-did: run-initializer
docker logs issuer-initializer-1
$(eval DID = $(shell docker logs -f --tail 1 issuer-initializer-1 | grep "did"))
@echo $(DID)
sed '/ISSUER_API_UI_ISSUER_DID/d' .env-api > .env-api.tmp
@echo ISSUER_API_UI_ISSUER_DID=$(DID) >> .env-api.tmp
mv .env-api.tmp .env-api
docker stop issuer-initializer-1
docker rm issuer-initializer-1
.PHONY: generate-issuer-did-arm
generate-issuer-did-arm:
@echo "WARN: Running ARM version is deprecated. 'make generate-issuer-did' will be executed instead."
@make generate-issuer-did
.PHONY: add-host-url-swagger
add-host-url-swagger:
@if [ $(ENVIRONMENT) != "" ] && [ $(ENVIRONMENT) != "local" ]; then \
sed -i -e "s#server-url = [^ ]*#server-url = \""${ISSUER_API_UI_SERVER_URL}"\"#g" api_ui/spec.html; \
fi
.PHONY: rm-issuer-imgs
rm-issuer-imgs: stop
$(DOCKER_COMPOSE_CMD) rm -f
docker rmi -f issuer-api issuer-ui issuer-api-ui issuer-pending_publisher
.PHONY: restart-ui
restart-ui: rm-issuer-imgs up run run-ui
.PHONY: restart-ui-arm
restart-ui-arm:
@echo "WARN: Running ARM version is deprecated. 'make restart-ui' will be executed instead."
@make restart-ui
.PHONY: print-did
print-did:
docker exec issuer-vault-1 \
vault kv get -mount=kv did
# use this to delete the did from vault. It will not be deleted from the database
.PHONY: delete-did
delete-did:
docker exec issuer-vault-1 \
vault kv delete kv/did
# use this to add the did to vault. It will not be added to the database
# usage: make did=xxx add-did
.PHONY: add-did
add-did:
docker exec issuer-vault-1 \
vault kv put kv/did did=$(did)
# usage: make vault_token=xxx vault-export-keys
.PHONY: vault-export-keys
vault-export-keys:
docker build -t issuer-vault-export-keys .
docker run --rm -it --network=issuer-network -v $(shell pwd):/keys issuer-vault-export-keys ./vault-migrator -operation=export -output-file=keys.json -vault-token=$(vault_token) -vault-addr=http://vault:8200
# usage: make vault_token=xxx vault-import-keys
.PHONY: vault-import-keys
vault-import-keys:
docker build -t issuer-vault-import-keys .
docker run --rm -it --network=issuer-network -v $(shell pwd)/keys.json:/keys.json issuer-vault-import-keys ./vault-migrator -operation=import -input-file=keys.json -vault-token=$(vault_token) -vault-addr=http://vault:8200
# usage: make new_password=xxx change-vault-password
.PHONY: change-vault-password
change-vault-password:
docker exec issuer-vault-1 \
vault write auth/userpass/users/issuernode password=$(new_password)
.PHONY: sleep-10
sleep-10:
sleep 10
# usage: make private_key=xxx run-all
.PHONY: run-all
run-all: clean-vault up sleep-10 clean-vault add-private-key add-vault-token generate-issuer-did run run-ui
# usage: make private_key=xxx run-all-arm
.PHONY: run-all-arm
run-all-arm:
@echo "WARN: Running ARM version is deprecated. 'make run-all' will be executed instead."
@make run-all