-
-
Notifications
You must be signed in to change notification settings - Fork 38
/
Makefile
175 lines (165 loc) · 7.51 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
ifndef APP_NAME
APP_NAME = blog
endif
ifndef WORDPRESS_VERSION
WORDPRESS_VERSION = 4.9.6
endif
ifndef BUILDPACK_VERSION
BUILDPACK_VERSION = v180
endif
ifndef DOKKU_USER
DOKKU_USER = dokku
endif
ifdef UNATTENDED_CREATION
DOKKU_CMD = ssh $(DOKKU_USER)@$(SERVER_NAME)
else
DOKKU_CMD = dokku
endif
CURL_INSTALLED := $(shell command -v curl 2> /dev/null)
WGET_INSTALLED := $(shell command -v wget 2> /dev/null)
.PHONY: all
all: help ## outputs the help message
.PHONY: help
help: ## this help.
@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-36s\033[0m %s\n", $$1, $$2}'
.PHONY: build
build: ## builds a wordpress blog installation and outputs deploy instructions
ifndef APP_NAME
$(error "Missing APP_NAME environment variable, this should be the name of your blog app")
endif
ifndef SERVER_NAME
$(error "Missing SERVER_NAME environment variable, this should be something like 'dokku.me'")
endif
ifndef CURL_INSTALLED
ifndef WGET_INSTALLED
$(error "Neither curl nor wget are installed, and at least one is necessary for retrieving salts")
endif
endif
# creating the wordpress repo
@test -d $(APP_NAME) || (git -c advice.detachedHead=false clone --branch=$(WORDPRESS_VERSION) --single-branch https://github.com/WordPress/WordPress.git $(APP_NAME) && cd $(APP_NAME) && git checkout -qb master)
# adding wp-config.php from gist
@test -f $(APP_NAME)/wp-config.php || (cp config/wp-config.php $(APP_NAME)/wp-config.php && cd $(APP_NAME) && git add wp-config.php && git commit -qm "Adding environment-variable based wp-config.php")
# adding .env file to configure buildpack
@test -f $(APP_NAME)/.buildpacks || (echo "https://github.com/heroku/heroku-buildpack-php.git#$(BUILDPACK_VERSION)" > $(APP_NAME)/.buildpacks && cd $(APP_NAME) && git add .buildpacks && git commit -qm "Forcing php buildpack usage")
# ensuring our composer.json loads with php 5.6 and loads the mysql extension
@test -f $(APP_NAME)/composer.json || (cp config/composer.json $(APP_NAME)/composer.json && cp config/composer.lock $(APP_NAME)/composer.lock && cd $(APP_NAME) && git add composer.json composer.lock && git commit -qm "Use PHP 5.6 and the mysql extension")
# setting the correct dokku remote for your app and server combination
@cd $(APP_NAME) && (git remote rm dokku 2> /dev/null || true) && git remote add dokku "dokku@$(SERVER_NAME):$(APP_NAME)"
# retrieving potential salts and writing them to /tmp/wp-salts
ifdef CURL_INSTALLED
@curl -so /tmp/wp-salts https://api.wordpress.org/secret-key/1.1/salt/
else
ifdef WGET_INSTALLED
@wget -qO /tmp/wp-salts https://api.wordpress.org/secret-key/1.1/salt/
endif
endif
@sed -i.bak -e 's/ //g' -e "s/);//g" -e "s/define('/$(DOKKU_CMD) config:set $(APP_NAME) /g" -e "s/SALT',/SALT=/g" -e "s/KEY',[ ]*/KEY=/g" /tmp/wp-salts && rm /tmp/wp-salts.bak
ifndef UNATTENDED_CREATION
# run the following commands on the server to setup the app:
@echo ""
@echo "dokku apps:create $(APP_NAME)"
@echo ""
# setup plugins persistent storage
@echo ""
@echo "mkdir -p /var/lib/dokku/data/storage/$(APP_NAME)-plugins"
@echo "chown 32767:32767 /var/lib/dokku/data/storage/$(APP_NAME)-plugins"
@echo "dokku storage:mount $(APP_NAME) /var/lib/dokku/data/storage/$(APP_NAME)-plugins:/app/wp-content/plugins"
@echo ""
# setup upload persistent storage
@echo ""
@echo "mkdir -p /var/lib/dokku/data/storage/$(APP_NAME)-uploads"
@echo "chown 32767:32767 /var/lib/dokku/data/storage/$(APP_NAME)-uploads"
@echo "dokku storage:mount $(APP_NAME) /var/lib/dokku/data/storage/$(APP_NAME)-uploads:/app/wp-content/uploads"
@echo ""
# setup languages persistent storage
@echo ""
@echo "mkdir -p /var/lib/dokku/data/storage/$(APP_NAME)-languages"
@echo "chown 32767:32767 /var/lib/dokku/data/storage/$(APP_NAME)-languages"
@echo "dokku storage:mount $(APP_NAME) /var/lib/dokku/data/storage/$(APP_NAME)-languages:/app/wp-content/languages"
@echo ""
# setup your mysql database and link it to your app
# if you're using MariaDB, replace mysql with mariadb
@echo ""
@echo "export MYSQL_IMAGE_VERSION=\"5.6\""
@echo "dokku mysql:create $(APP_NAME)-database"
@echo "dokku mysql:link $(APP_NAME)-database $(APP_NAME)"
@echo ""
# you will also need to set the proper environment variables for keys and salts
# the following were generated using the wordpress salt api: https://api.wordpress.org/secret-key/1.1/salt/
# and use the following commands to set them up:
@echo ""
@cat /tmp/wp-salts
@echo ""
# now, on your local machine, change directory to your new wordpress app, and push it up
@echo ""
@echo "cd $(APP_NAME)"
@echo "git push dokku master"
else
@chmod +x /tmp/wp-salts
$(DOKKU_CMD) apps:create $(APP_NAME)
$(DOKKU_CMD) storage:mount $(APP_NAME) /var/lib/dokku/data/storage/$(APP_NAME)-plugins:/app/wp-content/plugins
$(DOKKU_CMD) storage:mount $(APP_NAME) /var/lib/dokku/data/storage/$(APP_NAME)-uploads:/app/wp-content/uploads
$(DOKKU_CMD) storage:mount $(APP_NAME) /var/lib/dokku/data/storage/$(APP_NAME)-languages:/app/wp-content/languages
$(DOKKU_CMD) mysql:create $(APP_NAME)-database
$(DOKKU_CMD) mysql:link $(APP_NAME)-database $(APP_NAME)
@/tmp/wp-salts
@echo ""
# run the following commands on the server to ensure data is stored properly on disk
@echo ""
@echo "mkdir -p /var/lib/dokku/data/storage/$(APP_NAME)-plugins"
@echo "chown 32767:32767 /var/lib/dokku/data/storage/$(APP_NAME)-plugins"
@echo "mkdir -p /var/lib/dokku/data/storage/$(APP_NAME)-uploads"
@echo "chown 32767:32767 /var/lib/dokku/data/storage/$(APP_NAME)-uploads"
@echo "mkdir -p /var/lib/dokku/data/storage/$(APP_NAME)-languages"
@echo "chown 32767:32767 /var/lib/dokku/data/storage/$(APP_NAME)-languages"
@echo ""
# now, on your local machine, change directory to your new wordpress app, and push it up
@echo ""
@echo "cd $(APP_NAME)"
@echo "git push dokku master"
endif
.PHONY: destroy
destroy: ## destroys an existing wordpress blog installation and outputs undeploy instructions
ifndef APP_NAME
$(error "Missing APP_NAME environment variable, this should be the name of your blog app")
endif
ifndef SERVER_NAME
$(error "Missing SERVER_NAME environment variable, this should be something like 'dokku.me'")
endif
ifndef UNATTENDED_CREATION
# destroy the mysql database
# if you're using MariaDB, replace mysql with mariadb
@echo ""
@echo "dokku mysql:unlink $(APP_NAME)-database $(APP_NAME)"
@echo "dokku mysql:destroy $(APP_NAME)-database"
@echo ""
# destroy the app
@echo ""
@echo "dokku -- --force apps:destroy $(APP_NAME)"
@echo ""
# run the following commands on the server to remove storage directories on disk
@echo ""
@echo "rm -rf /var/lib/dokku/data/storage/$(APP_NAME)-plugins"
@echo "rm -rf /var/lib/dokku/data/storage/$(APP_NAME)-uploads"
@echo "rm -rf /var/lib/dokku/data/storage/$(APP_NAME)-languages"
@echo ""
# now, on your local machine, cd into your app's parent directory and remove the app
@echo ""
@echo "rm -rf $(APP_NAME)"
else
# destroy the mysql database
# if you're using MariaDB, replace mysql with mariadb
$(DOKKU_CMD) mysql:unlink $(APP_NAME)-database $(APP_NAME)
$(DOKKU_CMD) mysql:destroy $(APP_NAME)-database
# destroy the app
$(DOKKU_CMD) -- --force apps:destroy $(APP_NAME)
# run the following commands on the server to remove storage directories on disk
@echo ""
@echo "rm -rf /var/lib/dokku/data/storage/$(APP_NAME)-plugins"
@echo "rm -rf /var/lib/dokku/data/storage/$(APP_NAME)-uploads"
@echo "rm -rf /var/lib/dokku/data/storage/$(APP_NAME)-languages"
@echo ""
# now, on your local machine, cd into your app's parent directory and remove the app
@echo ""
@echo "rm -rf $(APP_NAME)"
endif