-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
144 lines (126 loc) · 4.65 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#--------------------------------------------------------------
# Craft CMS Project
#--------------------------------------------------------------
CRAFT_PATH := craftcms
ETC_PATH := etc
FRONTEND_PATH := frontend
ENV_PATH := $(CRAFT_PATH)/.env
SEED_PATH := $(ETC_PATH)/docker/seed
APP_ID := $(shell grep -E '^CRAFT_APP_ID=' $(ENV_PATH) | cut -d '=' -f 2)
PROJECT_NAME := $(if $(APP_ID),$(APP_ID),$(shell basename $(realpath $(dir $(CURDIR))/..)))
COMPOSE := docker compose --project-name $(PROJECT_NAME) --env-file $(ENV_PATH)
COMPOSE_UP := $(COMPOSE) up
COMPOSE_DOWN := $(COMPOSE) down
COMPOSE_REBUILD := $(COMPOSE) up --build --force-recreate
COMPOSE_ARGS := --rm --remove-orphans
EXEC_SSH := $(COMPOSE) run $(COMPOSE_ARGS) php /bin/bash
EXEC_CRAFT := $(COMPOSE) run $(COMPOSE_ARGS) php /app/craft
EXEC_NPM := $(COMPOSE) run $(COMPOSE_ARGS) frontend npm
EXEC_COMPOSER := $(COMPOSE) run $(COMPOSE_ARGS) composer
# Actions
#--------------------------------------------------------------
.PHONY: assets backup composer craft debug dev down \
npm nuke rebuild ssh update wipe
#--------------------------------------------------------------
assets: craft-index-assets
backup: craft-export
composer:
@$(EXEC_COMPOSER) --optimize-autoloader $(CLI_ARGS) ;
craft:
@$(EXEC_CRAFT) $(CLI_ARGS) ;
debug:
@$(COMPOSE) --profile debug up ;
dev: setup
@$(COMPOSE_UP) ;
down:
@$(COMPOSE_DOWN) ;
npm:
@$(EXEC_NPM) $(CLI_ARGS) ;
nuke: composer-wipe npm-wipe
@$(COMPOSE_DOWN) -v ;
rebuild: setup
@$(COMPOSE_REBUILD) ;
restart: down rebuild
ssh:
@$(EXEC_SSH) ;
update: composer-bump restart
wipe: composer-wipe npm-wipe restart
setup:
cp -n $(CRAFT_PATH)/example.env $(ENV_PATH)
@if [ -z "$(APP_ID)" ]; then \
sed -i "s|^CRAFT_APP_ID *= *.*|CRAFT_APP_ID=\"$(PROJECT_NAME)\"|" "$(ENV_PATH)"; \
fi
@if [ -f "$(SEED_PATH).sql.gz" ]; then \
mkdir -p $(SEED_PATH) && gzip -dkc $(SEED_PATH).sql.gz > $(SEED_PATH)/craft.sql; \
fi
#--------------------------------------------------------------
# Composer Shortcuts
#--------------------------------------------------------------
composer-bump: composer-update
@$(EXEC_COMPOSER) bump ;
composer-update:
@$(EXEC_COMPOSER) --optimize-autoloader update ;
composer-wipe:
@rm -f $(CRAFT_PATH)/composer.lock
@rm -rf $(CRAFT_PATH)/vendor
#--------------------------------------------------------------
# Craft Shortcuts
#--------------------------------------------------------------
craft-index-assets:
@$(EXEC_CRAFT) index-assets/all ;
craft-export:
$(EXEC_CRAFT) db/backup ;
craft-fresh-database:
@$(EXEC_CRAFT) db/drop-all-tables --interactive=0 ;
@$(EXEC_CRAFT) install/craft \
--email='craft@example.com' \
--password='letmein' \
--site-name='Website' \
--language='en-CA' \
--site-url='http://localhost:8000' \
--interactive=0 ;
craft-reseed: craft-export
@rm -f $(SEED_PATH).sql.gz
@cp -p "`ls -dtr1 $(CRAFT_PATH)/storage/backups/* | tail -1`" $(SEED_PATH).sql
@gzip -c $(SEED_PATH).sql > $(SEED_PATH).sql.gz
# Object Storage Shortcuts
#--------------------------------------------------------------
minio-setup:
@$(COMPOSE_UP) minio -d ;
@sleep 3
@mc mb localhost/${S3_BUCKET}
@mc anonymous set download localhost/${S3_BUCKET}/public
@$(COMPOSE_DOWN) ;
minio-staging-to-dev:
@$(COMPOSE_UP) minio -d ;
@sleep 3
@mc mirror --overwrite staging/${STAGING_BUCKET}/public/content/staging localhost/${S3_BUCKET}/public/content/dev
@mc mirror --overwrite staging/${STAGING_BUCKET}/public/design localhost/${S3_BUCKET}/public/design
@mc mirror --overwrite staging/${STAGING_BUCKET}/private localhost/${S3_BUCKET}/private
@$(COMPOSE_DOWN) ;
minio-dev-to-staging:
@$(COMPOSE_UP) minio -d ;
@sleep 3
@mc mirror --overwrite localhost/${S3_BUCKET}/public/content/dev staging/${STAGING_BUCKET}/public/content/staging
@mc mirror --overwrite localhost/${S3_BUCKET}/public/design staging/${STAGING_BUCKET}/public/design
@mc mirror --overwrite localhost/${S3_BUCKET}/private staging/${STAGING_BUCKET}/private
@$(COMPOSE_DOWN) ;
# NPM Shortcuts
#--------------------------------------------------------------
npm-wipe:
@rm -f $(FRONTEND_PATH)/package-lock.json
@rm -rf $(FRONTEND_PATH)/node_modules
# Read missing variables from .env file
#--------------------------------------------------------------
ifneq (,$(wildcard $(ENV_PATH)))
include $(ENV_PATH)
export $(shell sed 's/=.*//' $(ENV_PATH))
endif
#--------------------------------------------------------------
# Allow argument to be passed into the Makefile from the CLI
# ➜ https://stackoverflow.com/questions/6273608/
#--------------------------------------------------------------
CLI_ARGS=$(filter-out $@,$(MAKECMDGOALS))
%:
@:
#--------------------------------------------------------------