-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
97 lines (83 loc) · 4.14 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
.PHONY: dev rmi prod rmip migrate baseline testconnect prepareprod startprod help
SHELL := /bin/bash
MYPATH := $(shell pwd)
SSH_KEY = $(HOME)/.ssh/id_rsa
# Start the local development environment with hot-reloading. Usage: 'make dev'.
dev:
docker compose -f docker/docker-compose.dev.yml up --force-recreate
# Remove local development images and volumes. Usage: 'make rmi'.
rmi:
docker compose -f docker/docker-compose.dev.yml down --rmi=local
# Start a production-like environment locally. Usage: 'make prod'.
prod:
docker compose -f docker/docker-compose.prod.yml up --force-recreate
# Start production environment locally using images from the container registry. Usage: 'make regprod'.
regprod:
docker compose -f docker/docker-compose.prod.from-registry.yml up
# Remove local production-like images and volumes. Usage: 'make rmip'.
rmip:
docker compose -f docker/docker-compose.prod.yml down --rmi=local
# Create a databse migration. Use when making changes to the prisma/schema.prisma file. Usage: 'make migrate'.
migrate:
docker build -f docker/Dockerfile.dbsync --platform linux/amd64 -t hytky-dbsync .
docker run --env-file ./.env --network docker_default -v $(MYPATH)/prisma:/app/prisma --platform linux/amd64 -it --entrypoint "pnpx" hytky-dbsync prisma migrate dev
# Create a baseline migration. You should probably never use this. Usage: 'make baseline'.
baseline:
mkdir -p prisma/migrations/0_init
docker build -f docker/Dockerfile.dbsync --platform linux/amd64 -t hytky-dbsync .
docker run --network docker_default -v $(MYPATH)/prisma:/app/prisma --platform linux/amd64 --env-file ./.env -it --entrypoint /bin/sh hytky-dbsync -c "pnpx prisma db pull && \
pnpx prisma migrate diff \
--from-empty \
--to-schema-datamodel prisma/schema.prisma \
--script > prisma/migrations/0_init/migration.sql && \
pnpx prisma migrate resolve --applied 0_init"
# Seed the (production) database. This should only be required after 'make prod'. Usage: 'make seed'.
seed:
docker build -f docker/Dockerfile.dbsync --platform linux/amd64 -t hytky-dbsync .
docker run --network hytky-prod_default --platform linux/amd64 --env-file ./.env -it --entrypoint "pnpx" hytky-dbsync prisma db seed
# Test connection to the server at the address given. Usage: 'make testconnect IP=123.123.123.123'.
testconnect:
ansible -i $(IP), -u root --private-key=$(SSH_KEY) all -m ping
# Prepare production environment at the address given. Usage: 'make prepareprod IP=123.123.123.123 DOMAIN=example.com [email protected]'.
prepareprod:
ifeq ($(MAKECMDGOALS),prepareprod)
ifndef IP
ifndef DOMAIN
$(error DOMAIN is not defined. Usage: make prepareprod DOMAIN=yourdomain.com [email protected])
endif
ifndef CERTBOT_EMAIL
$(error CERTBOT_EMAIL is not defined. Usage: make prepareprod DOMAIN=yourdomain.com [email protected])
endif
endif
ifdef IP
ansible-playbook -i $(IP), --user=root --private-key=$(SSH_KEY) ansible/install-docker-compose.yml -e @ansible/vars.yml
ansible-playbook -i $(IP), --user=root --private-key=$(SSH_KEY) ansible/copy-files-to-production.yml
endif
ifdef DOMAIN
ifdef CERTBOT_EMAIL
ansible-playbook -i $(DOMAIN), --user=root --private-key=$(SSH_KEY) ansible/install-docker-compose.yml -e @ansible/vars.yml
ansible-playbook -i $(DOMAIN), --user=root --private-key=$(SSH_KEY) ansible/copy-files-to-production.yml -e "domain=$(DOMAIN) certbot_email=$(CERTBOT_EMAIL)"
endif
endif
endif
# Start production environment at the address given. Usage: 'make startprod IP=123.123.123.123'.
startprod:
ifeq ($(MAKECMDGOALS),startprod)
ifndef IP
ifndef DOMAIN
$(error DOMAIN is not defined. Usage: make prepareprod DOMAIN=yourdomain.com or make startprod IP=)
endif
ansible-playbook -i $(DOMAIN), --user=root --private-key=$(SSH_KEY) ansible/start-production-https.yml
endif
ifdef IP
ansible-playbook -i $(IP), --user=root --private-key=$(SSH_KEY) ansible/start-production-http.yml
endif
endif
# Show this help. Usage: 'make help'.
help:
@echo "Usage: make <target>"
@echo ""
@echo "Targets:"
@grep -E '^[a-zA-Z]+:' Makefile | grep -v '^\.PHONY:' | sed -e 's/:.*//' -e 's/^/ /' -e 's/^/ /'
@echo ""
@grep -E '^#.*' Makefile | sed -e 's/^# //' -e 's/^/ /' -e 's/^/ /'