-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
127 lines (95 loc) · 4.76 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
##
# Demo Portal Sandbox
#
# @file
# @version 0.1
SHELL = /bin/sh
VERSION ?= $(shell git describe --tags 2>/dev/null | cut -c 2-)
COMMIT ?= $(shell git rev-parse HEAD 2>/dev/null)
DATE ?= $(shell date -u)
export CGO_ENABLED=0
build: sandbox-list sandbox-metrics sandbox-api sandbox-issue-jwt sandbox-rotate-vault
test:
@echo "Running tests..."
@echo "VERSION: $(VERSION)"
@go test -v ./...
@echo "Validating swagger.yaml..."
@go run github.com/daveshanley/vacuum@latest lint -d docs/api-reference/swagger.yaml
run-api: cmd/sandbox-api/assets/swagger.yaml .dev.pgenv .dev.jwtauth_env #migrate
. ./.dev.pgenv && . ./.dev.jwtauth_env && cd cmd/sandbox-api && go run .
run-air: cmd/sandbox-api/assets/swagger.yaml .dev.pgenv .dev.jwtauth_env
. ./.dev.pgenv && . ./.dev.jwtauth_env && cd cmd/sandbox-api && air
rm-local-pg:
@podman kill localpg || true
@podman rm localpg || true
@rm -f .dev.pg_password .dev.pgenv .dev.tokens_env .dev.admin_token .dev.app_token || true
run-local-pg: rm-local-pg .dev.pg_password
@echo "Running local postgres..."
@podman run -p 5432:5432 --name localpg -e POSTGRES_PASSWORD=$(shell cat .dev.pg_password) -d postgres:16-bullseye
# See full list of parameters here:
# https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-PARAMKEYWORDS
issue-jwt: .dev.jwtauth_env
@. ./.dev.pgenv && . ./.dev.jwtauth_env && go run ./cmd/sandbox-issue-jwt
tokens: .dev.tokens_env
@cat .dev.tokens_env
migrate: .dev.pgenv
# Print a message with the database URL and ask for confirmation
# Remove password from the URL before printing
@. ./.dev.pgenv && echo "Database URL: $$(echo $${DATABASE_URL} | sed -E 's/:[^@]+@/:<password>@/g')"
@read -p "Are you sure [y/n]? " -n 1 -r; \
if [[ ! $$REPLY =~ ^[Yy]$$ ]]; then \
echo "Aborting."; \
exit 1; \
fi
@echo "Running migrations..."
@. ./.dev.pgenv && migrate -database "$${DATABASE_URL}" -path db/migrations up
fixtures: migrate .dev.pgenv
@echo "Loading fixtures..."
@. ./.dev.pgenv && psql "$${DATABASE_URL}" < ./db/fixtures/0001.sql
sandbox-list:
go build -ldflags="-X 'main.Version=$(VERSION)' -X 'main.buildTime=$(DATE)' -X 'main.buildCommit=$(COMMIT)'" -o build/sandbox-list ./cmd/sandbox-list
sandbox-api: cmd/sandbox-api/assets/swagger.yaml
go build -ldflags="-X 'main.Version=$(VERSION)' -X 'main.buildTime=$(DATE)' -X 'main.buildCommit=$(COMMIT)'" -o build/sandbox-api ./cmd/sandbox-api
sandbox-metrics:
go build -ldflags="-X 'main.Version=$(VERSION)' -X 'main.buildTime=$(DATE)' -X 'main.buildCommit=$(COMMIT)'" -o build/sandbox-metrics ./cmd/sandbox-metrics
sandbox-issue-jwt:
go build -o build/sandbox-issue-jwt ./cmd/sandbox-issue-jwt
sandbox-replicate:
go build -o build/sandbox-replicate ./cmd/sandbox-replicate
sandbox-rotate-vault:
go build -ldflags="-X 'main.Version=$(VERSION)' -X 'main.buildTime=$(DATE)' -X 'main.buildCommit=$(COMMIT)'" -o build/sandbox-rotate-vault ./cmd/sandbox-rotate-vault
push-lambda: deploy/lambda/sandbox-replicate.zip
python ./deploy/lambda/sandbox-replicate.py
fmt:
@go fmt ./...
.PHONY: sandbox-api sandbox-issue-jwt issue-jwt tokens sandbox-list sandbox-metrics sandbox-rotate-vault run-api run-air sandbox-replicate migrate fixtures test run-local-pg push-lambda clean fmt
clean: rm-local-pg
rm -f build/sandbox-*
rm -f deploy/lambda/sandbox-replicate.zip
rm -f cmd/sandbox-api/assets/swagger.yaml
rm -f .dev.*
# Regular file targets
deploy/lambda/sandbox-replicate.zip: sandbox-replicate
zip deploy/lambda/sandbox-replicate.zip build/sandbox-replicate
cmd/sandbox-api/assets/swagger.yaml: docs/api-reference/swagger.yaml
@mkdir -p cmd/sandbox-api/assets
cp docs/api-reference/swagger.yaml cmd/sandbox-api/assets/swagger.yaml
.dev.pg_password:
@uuidgen -r > .dev.pg_password
.dev.pgenv: .dev.pg_password
@echo "export DATABASE_URL=\"postgres://postgres:$(shell cat .dev.pg_password)@127.0.0.1:5432/postgres?sslmode=disable\"" > .dev.pgenv
.dev.jwtauth_secret:
@uuidgen -r > .dev.jwtauth_secret
@chmod 600 .dev.jwtauth_secret
.dev.jwtauth_env: .dev.jwtauth_secret
@echo "export JWT_AUTH_SECRET=$(shell cat .dev.jwtauth_secret)" > .dev.jwtauth_env
@chmod 600 .dev.jwtauth_env
.dev.admin_token: .dev.pgenv .dev.jwtauth_env
@echo '{"kind": "login", "name": "dev-$(shell hostname)-$(shell date +%Y%m%d)", "role": "admin"}' | (. ./.dev.pgenv && . ./.dev.jwtauth_env && go run ./cmd/sandbox-issue-jwt) > .dev.admin_token
.dev.app_token: .dev.pgenv .dev.jwtauth_env
@echo '{"kind": "login", "name": "dev-$(shell hostname)-$(shell date +%Y%m%d)", "role": "app"}' | (. ./.dev.pgenv && . ./.dev.jwtauth_env && go run ./cmd/sandbox-issue-jwt) > .dev.app_token
.dev.tokens_env: .dev.admin_token .dev.app_token
@echo "export admintoken=$(shell cat .dev.admin_token)" > .dev.tokens_env
@echo "export apptoken=$(shell cat .dev.app_token)" >> .dev.tokens_env
@chmod 600 .dev.tokens_env
# end