-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
149 lines (118 loc) · 6.2 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
145
146
147
148
149
include .env
# Use PUBLIC_HOST if defined, otherwise set to APP_NAME + REMOTE_HOST
PUBLIC_HOST := $(if $(PUBLIC_HOST),$(PUBLIC_HOST),$(APP_NAME).$(REMOTE_HOST))
# docker-compose commands for development, production, and remote production
docker-compose := docker-compose
docker-compose-prod := PUBLIC_HOST=$(PUBLIC_HOST) docker-compose -f docker-compose.yml -f docker-compose.production.yml
docker-compose-remote := DOCKER_HOST=ssh://root@$(REMOTE_HOST) APP_HOST=$(REMOTE_HOST) PUBLIC_HOST=$(PUBLIC_HOST) docker-compose -f docker-compose.yml -f docker-compose.production.yml
# append bedrock's docker-compose file if available
ifneq ("$(wildcard bedrock)","")
docker-compose += -f docker-compose.yml -f docker-compose.override.yml -f bedrock/docker-compose.override.yml
docker-compose-prod += -f bedrock/docker-compose.override.yml
endif
all:
@echo "【 $(APP_NAME)@$(APP_HOST) --> $(REMOTE_HOST) --> $(PUBLIC_HOST) 】"
@echo " ‣ install ‣ upgrade ‣ remote"
@echo " ‣ build ‣ build! ‣ assets"
@echo " ‣ up ‣ upp ‣ up!"
@echo " ‣ down ‣ down!"
@echo " ‣ logs ‣ logs!"
@echo " ‣ pull ‣ push"
@echo " ‣ export ‣ import ‣ clean"
@echo " ‣ plugin add=WP_PLUGIN ‣ theme add=WP_THEME ‣ package add=NPM_PACKAGE"
@echo " ‣ shell ‣ shell! ‣ host!"
@echo ""
up: build update-db ; $(docker-compose) up --remove-orphans -d dev
upp: assets build update-db ; $(docker-compose-prod) up --remove-orphans -d srv
down: ; $(docker-compose) down --remove-orphans
logs: ; $(docker-compose) logs -f
remote: ; $(docker-compose) run --rm env remote_host
dotenv: tmp-dir ; $(docker-compose) run --rm env dotenv
up!: assets build! update-db! ; $(docker-compose-remote) up --remove-orphans -d srv
down!: ; $(docker-compose-remote) down --remove-orphans
logs!: ; $(docker-compose-remote) logs -f
.env:
docker run --rm -it \
-e APP_NAME=$(notdir $(shell pwd)) \
-e APP_HOST=$(shell hostname -f) \
-v $(PWD):/srv \
nonfiction/bedrock:env dotenv
assets:
# $(docker-compose-prod) run --rm dev npx ncu -um
$(docker-compose-prod) run --rm dev npm update --save-dev
$(docker-compose-prod) run --rm dev webpack --progress
build: tmp-dir ; $(docker-compose) build srv
rebuild: tmp-dir ; $(docker-compose) build --pull --no-cache srv
build!: tmp-dir! ; $(docker-compose-remote) build srv
rebuild!: tmp-dir! ; $(docker-compose-remote) build --pull --no-cache srv
upgrade: .env assets rebuild update-db
# make composer require=wpackagist-plugin/name
# make composer require=wpackagist-theme/name
# composer:
# test $(require) && $(docker-compose) run --rm srv composer require --no-update $(require)
# # test $(remove) && $(docker-compose) run --rm srv composer remove --no-update $(remove)
composer: ; test $(require) && $(docker-compose) run --rm srv composer require --no-update $(require)
# make plugin/theme/package add=name_of_package
plugin: ; test $(add) && $(docker-compose) run --rm srv composer require --no-update wpackagist-plugin/$(add)
theme: ; test $(add) && $(docker-compose) run --rm srv composer require --no-update wpackagist-theme/$(add)
package: ; test $(add) && $(docker-compose) run --rm dev npm install $(add) --save-dev --prefix
tmp-dir: ; @mkdir -p /tmp/$(APP_NAME)/uploads
tmp-dir!: ; @ssh root@$(REMOTE_HOST) mkdir -p /tmp/$(APP_NAME)/uploads
db: ; $(docker-compose) run --rm env create_db
export-db: ; $(docker-compose) run --rm -e UID=$(shell id -u) env export_db
import-db: ; $(docker-compose) run --rm env import_db
update-db: ; $(docker-compose) run --rm wp core update-db
update-db!: ; $(docker-compose-remote) run --rm wp core update-db
public-db!: ; $(docker-compose-remote) run --rm wp search-replace --report-changed-only https://$(APP_NAME).$(REMOTE_HOST) https://$(PUBLIC_HOST)
pull-db:
$(docker-compose) run --rm env pull_db
$(docker-compose) run --rm wp search-replace --report-changed-only https://$(PUBLIC_HOST) https://$(APP_NAME).$(APP_HOST)
push-db:
$(docker-compose) run --rm env push_db
$(docker-compose-remote) run --rm wp search-replace --report-changed-only https://$(APP_NAME).$(APP_HOST) https://$(PUBLIC_HOST)
pull-files: tmp-dir tmp-dir!
$(docker-compose-remote) run --rm env volume_to_host
$(docker-compose) run --rm env remote_to_volume
$(docker-compose-remote) run --rm env clean_host
push-files: tmp-dir tmp-dir!
$(docker-compose) run --rm env volume_to_remote
$(docker-compose-remote) run --rm env host_to_volume
$(docker-compose-remote) run --rm env clean_host
import-files: ; $(docker-compose) run --rm env import_files
export-files: ; $(docker-compose) run --rm -e UID=$(shell id -u) env export_files
shell: ; $(docker-compose) exec srv bash
shell!: ; $(docker-compose-remote) exec srv bash
host!: ; ssh root@$(REMOTE_HOST)
push: push-files push-db
pull: pull-files pull-db
import: import-files import-db
export: export-files export-db
clean: ; rm -rf data/* && touch data/.gitkeep
restore: ; $(docker-compose) run --rm -e UID=$(shell id -u) env restore
install: .env tmp-dir assets rebuild
$(docker-compose) run --rm wp core install \
--url=https://$(APP_NAME).$(APP_HOST) \
--title=$(APP_NAME) \
--admin_user=nf-$(APP_NAME) \
--admin_password=$(DB_PASSWORD)
$(docker-compose) run --rm wp plugin activate intervention cmb2
$(docker-compose) run --rm wp theme activate theme
$(docker-compose) run --rm wp rewrite structure /%postname%/
@echo
@echo URL: https://$(APP_NAME).$(APP_HOST)/wp/wp-login.php
@echo Username: nf-$(APP_NAME)
@echo Password: $(DB_PASSWORD)
pull-images:
docker image pull nonfiction/bedrock:env
docker image pull nonfiction/bedrock:dev
docker image pull nonfiction/bedrock:srv
pull-images!:
ssh root@$(REMOTE_HOST) docker image pull nonfiction/bedrock:env
ssh root@$(REMOTE_HOST) docker image pull nonfiction/bedrock:srv
.PHONY: bedrock
bedrock: ; cd bedrock && docker-compose build && docker-compose push
env-shell: ; $(docker-compose) run --rm --entrypoint /bin/bash env
dev-shell: ; $(docker-compose-prod) run --rm --entrypoint /bin/bash dev
srv-shell: ; $(docker-compose-prod) run --rm --entrypoint /bin/bash srv
test: ; $(docker-compose) run --rm env test && ./cmd.sh