-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
98 lines (80 loc) · 2.87 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
# The main file for running project management scripts. This should be used
# most often instead of straight NPM scripts to make sure all the pieces
# play along nicely.
ifneq (,$(wildcard ./.env))
include .env
export $(shell sed 's/=.*//' .env)
endif
COMPOSE = docker-compose -f docker-compose.yml -f docker-compose.${ENV}.yml
# Depending on the env, customize the commands being run
ifeq ($(ENV),prod)
RUN = $(COMPOSE) up -d
else
# stag, dev
ifeq ($(ENV), dev)
RUN = $(COMPOSE) up --build
else
RUN = $(COMPOSE) up
endif
SEED = cat ./directus/seed.sql | docker-compose exec -T community_database psql -U ${DB_USER} -d ${DB_DATABASE}
WAIT = $(COMPOSE) run wait -c ${DB_HOST}:${DB_PORT}
DATABASE = $(COMPOSE) up -d community_database
endif
# Default for `make` without any args
all: run
env-test:
echo $(NEXT_PUBLIC_API_URL)
# We want to build custom Directus extensions on install, too
install:
npm install
npm run build:extensions
# This shouldn't be ran manually, instead `setup` should be used.
# Seeds the database with initial Directus data so that we don't have to start
# the CMS from scratch every time.
initial-setup:
$(DATABASE)
$(WAIT)
$(SEED)
# Run a bunch of other scripts to complete setup. Should only be run on initial
# setup of the local codebase.
setup: install initial-setup run-backend apply-migrations kill
# Builds the production version of frontend (assuming .env vars set correctly)
build: run-backend
$(COMPOSE) build community_web
# Helper for being sure CMS migrations contain only wanted changes
diff-migrations:
npm run migrate:generate
npm run migrate:diff
# Saves the current CMS state to the versioned schema file so that the changes
# can be committed to git
save-migrations:
npm run migrate:generate
npm run migrate:save
# Applies the version controlled migrations to current CMS instance. Use this
# if you need upstream changes locally.
apply-migrations:
npm run migrate:generate
npm run migrate:apply
# Used for migration restoration
swap-migrations:
mv ./directus/schema.json ./directus/schema.swap.json && \
mv ./directus/schema.previous.json ./directus/schema.json && \
mv ./directus/schema.swap.json ./directus/schema.previous.json
# An attempt to undo changes caused by a migration. This should not be relied
# upon, as changing database fields is often destructive
restore-migrations: swap-migrations diff-migrations
# Runs the project in either dev or prod mode, depending on .env variables
run:
$(RUN)
# Helper for making sure CMS (API) and database are up for static frontend
# builds et cetera
run-backend:
$(DATABASE)
$(COMPOSE) up -d community_cms community_cache
$(WAIT)
# Shut down all project containers
kill:
docker-compose kill
# This should be run on production server on each new push to the deployed
# branch. Kills the old instance, applies migrations, builds and then runs
deploy: install run-backend apply-migrations build run