-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
46 lines (40 loc) · 2.86 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
hXECUTABLES = docker terraform
K := $(foreach exec,$(EXECUTABLES),\
$(if $(shell which $(exec)),some string,$(error "No $(exec) in PATH")))
LOCALPORT := $(shell cat terraform/workspaces/api3tracker-local/modules.tf | grep -A2 'name = "default"' | grep local_port | head -n1 | grep -oE '[^ ]+$$')
LOCALPORT2 := $(shell cat terraform/workspaces/api3tracker-local/modules.tf | grep -A2 'name = "traefik"' | grep local_port | head -n1 | grep -oE '[^ ]+$$')
# CONTAINER_ID := $(shell docker ps --filter='label=project=api3tracker' --filter='label=role=postgres' --format "{{.ID}}")
.PHONY: env
build:
docker build -t api3tracker .
install:
@cd terraform/workspaces/api3tracker-local && \
terraform init && \
terraform apply -auto-approve && \
echo Traefik server should be running at http://localhost:${LOCALPORT}/ && \
echo Traefik dashboard should be running at http://localhost:${LOCALPORT2}/
uninstall:
cd terraform/workspaces/api3tracker-local && \
terraform destroy -auto-approve
validate:
cd terraform/workspaces/api3tracker-local && \
terraform validate
sql:
$(eval CONTAINER_ID := $(shell docker ps --filter='label=project=api3tracker' --filter='label=role=postgres' --format "{{.ID}}"))
$(eval PG_IP := $(shell docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $(CONTAINER_ID)))
$(eval PG_DB := $(shell docker inspect -f '{{range .Config.Env}}{{println .}}{{end}}' $(CONTAINER_ID) | grep POSTGRES_DB | cut -d= -f2))
$(eval PG_USER := $(shell docker inspect -f '{{range .Config.Env}}{{println .}}{{end}}' $(CONTAINER_ID) | grep POSTGRES_USER | cut -d= -f2))
$(eval PG_PASSWORD := $(shell docker inspect -f '{{range .Config.Env}}{{println .}}{{end}}' $(CONTAINER_ID) | grep POSTGRES_PASSWORD | cut -d= -f2))
export PGPASSWORD=$(PG_PASSWORD) && psql -U $(PG_USER) -h $(PG_IP) -d $(PG_DB)
env:
$(eval CONTAINER_ID := $(shell docker ps --filter='label=project=api3tracker' --filter='label=role=postgres' --format "{{.ID}}"))
$(eval PG_IP := $(shell docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $(CONTAINER_ID)))
$(eval PG_DB := $(shell docker inspect -f '{{range .Config.Env}}{{println .}}{{end}}' $(CONTAINER_ID) | grep POSTGRES_DB | cut -d= -f2))
$(eval PG_USER := $(shell docker inspect -f '{{range .Config.Env}}{{println .}}{{end}}' $(CONTAINER_ID) | grep POSTGRES_USER | cut -d= -f2))
$(eval PG_PASSWORD := $(shell docker inspect -f '{{range .Config.Env}}{{println .}}{{end}}' $(CONTAINER_ID) | grep POSTGRES_PASSWORD | cut -d= -f2))
@echo \# Environment variables declared in this file are automatically made available to Prisma. > .env
@echo \# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema >> .env
@echo \# \(AUTOGENERATED\) >> .env
@echo \# >> .env
@echo DATABASE_URL=postgresql://$(PG_USER):$(PG_PASSWORD)@$(PG_IP):5432/$(PG_DB) >> .env
@cat .env