-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
91 lines (71 loc) · 3.02 KB
/
Copy pathMakefile
File metadata and controls
91 lines (71 loc) · 3.02 KB
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
include .env.local
export
# To make sure these targets are not confused with files of the same name
.PHONY: help lint test clean deploy-dev deploy-prod stop-dev stop-prod \
connect-dev connect-prod create-migration apply-migrations rollback-migration
WARN_COLOR := $(shell tput setaf 208)
GREEN_COLOR := $(shell tput setaf 2)
RESET_COLOR := $(shell tput sgr0)
# Development
lint:
npx eslint .
test:
npm test
# EC2 instances connection
connect-dev:
@if [ -z "$(DEV_PRIVATE_KEY_LOCATION)" ] || [ -z "$(DEV_HOST)" ]; then \
echo "Error: DEV_PRIVATE_KEY_LOCATION and DEV_HOST environment variables must be set."; \
exit 1; \
fi
ssh -i $(DEV_PRIVATE_KEY_LOCATION) ec2-user@$(DEV_HOST)
connect-prod:
@if [ -z "$(PROD_PRIVATE_KEY_LOCATION)" ] || [ -z "$(PROD_HOST)" ]; then \
echo "Error: PROD_PRIVATE_KEY_LOCATION and PROD_HOST environment variables must be set."; \
exit 1; \
fi
ssh -i $(PROD_PRIVATE_KEY_LOCATION) ec2-user@$(PROD_HOST)
# Database migrations with knex
create-migration:
knex migrate:make $(name)
apply-migrations:
knex migrate:latest
rollback-migration:
knex migrate:rollback
# EC2 deployment
stop-dev:
docker-compose -f docker-compose.dev.yml down
stop-prod:
docker-compose -f docker-compose.prod.yml down
deploy-env:
@read -p "$(WARN_COLOR)You're about to deploy to the $(env) environment. Please make sure you pulled recent changes, \
installed new dependencies and verified the service starts using npm run as well as applied database migrations. \
Please refer to the /docs/how-tos/aws_ec2_deployment.md for the instructions. \
If you're sure, press Enter to continue.$(RESET_COLOR)" confirm; \
docker-compose -f docker-compose.$(env).yml build --no-cache
docker-compose -f docker-compose.$(env).yml up -d --force-recreate
deploy-dev:
@$(MAKE) deploy-env env=dev
deploy-prod:
@$(MAKE) deploy-env env=prod
help:
@echo ""
@echo "🛠 $(GREEN_COLOR)Makefile Help$(RESET_COLOR)"
@echo ""
@echo "🔧 Development:"
@echo " $(GREEN_COLOR)lint$(RESET_COLOR) Run eslint to check code quality"
@echo " $(GREEN_COLOR)test$(RESET_COLOR) Run unit tests with npm"
@echo ""
@echo "🌐 EC2 Instances:"
@echo " $(GREEN_COLOR)connect-dev$(RESET_COLOR) SSH into the dev EC2 instance"
@echo " $(GREEN_COLOR)connect-prod$(RESET_COLOR) SSH into the prod EC2 instance"
@echo ""
@echo "🛢 Database Migrations (Knex):"
@echo " $(GREEN_COLOR)create-migration$(RESET_COLOR) Create a new migration (usage: make create-migration name=xyz)"
@echo " $(GREEN_COLOR)apply-migrations$(RESET_COLOR) Apply the latest migrations"
@echo " $(GREEN_COLOR)rollback-migration$(RESET_COLOR)Rollback the last migration"
@echo ""
@echo "🚀 Deployment:"
@echo " $(GREEN_COLOR)deploy-dev$(RESET_COLOR) Deploy the dev environment"
@echo " $(GREEN_COLOR)deploy-prod$(RESET_COLOR) Deploy the prod environment"
@echo " $(GREEN_COLOR)stop-dev$(RESET_COLOR) Stop the dev Docker Compose"
@echo " $(GREEN_COLOR)stop-prod$(RESET_COLOR) Stop the prod Docker Compose"