forked from overhangio/tutor
/
Makefile
320 lines (263 loc) · 14.3 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
.PHONY: all android configure build update migrate run
.DEFAULT_GOAL := help
PWD ?= $$(pwd)
USERID ?= $$(id -u)
EDX_PLATFORM_SETTINGS ?= universal.production
DOCKER_COMPOSE = docker-compose -f docker-compose.yml
-include $(PWD)/config/Makefile.env
post_configure_targets =
ifneq ($(DISABLE_STATS), 1)
post_configure_targets += stats
endif
ifeq ($(ACTIVATE_HTTPS), 1)
post_configure_targets += https-certificate
endif
extra_migrate_targets =
ifeq ($(ACTIVATE_XQUEUE), 1)
extra_migrate_targets += migrate-xqueue
DOCKER_COMPOSE += -f docker-compose-xqueue.yml
endif
ifeq ($(ACTIVATE_NOTES), 1)
extra_migrate_targets += migrate-notes
DOCKER_COMPOSE += -f docker-compose-notes.yml
endif
ifeq ($(ACTIVATE_PORTAINER), 1)
DOCKER_COMPOSE += -f docker-compose-portainer.yml
endif
DOCKER_COMPOSE_RUN = $(DOCKER_COMPOSE) run --rm
DOCKER_COMPOSE_RUN_OPENEDX = $(DOCKER_COMPOSE_RUN) -e SETTINGS=$(EDX_PLATFORM_SETTINGS)
ifneq ($(EDX_PLATFORM_PATH),)
DOCKER_COMPOSE_RUN_OPENEDX += -e USERID=$(USERID) --volume="$(EDX_PLATFORM_PATH):/openedx/edx-platform"
endif
DOCKER_COMPOSE_RUN_LMS = $(DOCKER_COMPOSE_RUN_OPENEDX) -p 8000:8000 lms
DOCKER_COMPOSE_RUN_CMS = $(DOCKER_COMPOSE_RUN_OPENEDX) -p 8001:8001 cms
##################### Running Open edX
# other targets are not listed as requirements in order to reload the env file
all: configure ## Configure and run a full-featured platform
@$(MAKE) post_configure
@$(MAKE) update
@$(MAKE) databases
@$(MAKE) assets
@$(MAKE) daemonize
@echo "All set \o/ You can access the LMS at http://localhost and the CMS at http://studio.localhost"
run: ## Run the complete platform
$(DOCKER_COMPOSE) up
up: run
daemonize: ## Run the complete platform, with daemonization
$(DOCKER_COMPOSE) up -d
@echo "Daemon is up and running"
daemon: daemonize
stop: ## Stop all services
$(DOCKER_COMPOSE) rm --stop --force
##################### Configuration
configure: build-configurator ## Configure the environment prior to running the platform
docker run --rm -it --volume="$(PWD)/config:/openedx/config" \
-e USERID=$(USERID) -e SILENT=$(SILENT) $(CONFIGURE_OPTS) \
regis/openedx-configurator:hawthorn
post_configure: $(post_configure_targets)
##################### Database
DOCKERIZEWAIT = dockerize -wait tcp://mysql:3306 -timeout 20s
databases: provision-databases migrate provision-oauth2 ## Bootstrap databases
provision-databases: ## Create necessary databases and users
$(DOCKER_COMPOSE_RUN) lms /openedx/config/provision.sh
provision-oauth2: ## Create users for SSO between services
$(DOCKER_COMPOSE_RUN) lms /openedx/config/oauth2.sh
migrate: migrate-openedx migrate-forum $(extra_migrate_targets) ## Perform all database migrations
migrate-openedx: ## Perform database migrations on LMS/CMS
$(DOCKER_COMPOSE_RUN) lms bash -c "$(DOCKERIZEWAIT) && ./manage.py lms migrate"
$(DOCKER_COMPOSE_RUN) cms bash -c "$(DOCKERIZEWAIT) && ./manage.py cms migrate"
$(MAKE) reindex-courses
migrate-forum: ## Perform database migrations on discussion forums
$(DOCKER_COMPOSE_RUN) forum bash -c "bundle exec rake search:initialize && \
bundle exec rake search:rebuild_index"
migrate-notes: ## Perform database migrations for the Notes service
$(DOCKER_COMPOSE_RUN) notes ./manage.py migrate
migrate-xqueue: ## Perform database migrations for the XQueue service
$(DOCKER_COMPOSE_RUN) xqueue ./manage.py migrate
reindex-courses: ## Refresh course index so they can be found in the LMS search engine
$(DOCKER_COMPOSE_RUN) cms ./manage.py cms reindex_course --all --setup
##################### Backup Utilities
ISO_NOW=$(shell date -u "+%Y-%m-%dT%H:%M:%S%z")
backup-lms: ## Backup the mysql database used for the lms.
@echo "Exporting mysql database..."
@$(DOCKER_COMPOSE_RUN) lms bash -c "export $(shell cat ${PWD}/config/mysql/auth.env); \
$(DOCKERIZEWAIT) && mysqldump -u root -p\$$MYSQL_ROOT_PASSWORD --host mysql openedx > \
/openedx/backups/lms$(ISO_NOW).sql 2>/dev/null || true"
@echo "Backup Complete!"
@echo "Created file: lms$(ISO_NOW).sql"
# We need this conditional to see if mongodb is running.
# When the mongodb container is not running, we need to run it to backup.
# When the mongodb container is running we can use the running container.
backup-cms: ## Backup the MongoDB database used for Studio.
@echo "Exporting MongoDB database..."
@if [ -z `docker ps -q --no-trunc | grep $$(docker-compose ps -q mongodb)` ]; \
then echo "mongodb container not running, starting container..."; \
docker-compose run --rm mongodb bash -c " \
mongod --smallfiles --nojournal --storageEngine wiredTiger --fork --logpath=/var/log/mongodb/mongod.log && \
mongodump --out=/openedx/backups/cms$(ISO_NOW)/dump"; \
echo "Terminated container"; \
else docker-compose exec mongodb bash -c "mongodump --out=/openedx/backups/cms$(ISO_NOW)/dump"; fi
@echo "Backup Complete!"
@echo "Created backup: cms$(ISO_NOW)"
restore-lms: backup-lms restore-lms-dangerous## Restor the lms mysql db from a dump on the disk. Specify DUMP. A backup will be made first.
restore-lms-dangerous:
@echo "Restoring from file ${DUMP}"
@$(DOCKER_COMPOSE_RUN) lms bash -c "export $(shell cat ${PWD}/config/mysql/auth.env); \
if [ -f /openedx/backups/${DUMP} ]; \
then echo 'Importing dump file ${DUMP}...'; $(DOCKERIZEWAIT) && mysql --user=root --host=mysql --password-p\$$MYSQL_ROOT_PASSWORD openedx < /openedx/backups/${DUMP} 2>/dev/null || true; \
echo 'Restore Complete! Used backup ${DUMP}'; \
else echo 'File \`${DUMP}\` does not exist! Nothing imported.'; fi"
# The conditional is the same used in the backup mongodb command. See backup-cms
restore-cms: backup-cms restore-cms-dangerous ## Restor the cms mongo db from a dump on the disk. Specify DUMP. A backup will be made first.
restore-cms-dangerous:
@echo "Restoring from file ${DUMP}"
@if [ -z `docker ps -q --no-trunc | grep $$(docker-compose ps -q mongodb)` ]; \
then echo "mongodb container not running, starting container..."; \
docker-compose run --rm mongodb bash -c " \
mongod --smallfiles --nojournal --storageEngine wiredTiger --fork --logpath=/var/log/mongodb/mongod.log && \
mongorestore /openedx/backups/${DUMP}/dump"; \
echo "Terminated container"; \
else docker-compose exec mongodb bash -c "mongorestore /openedx/backups/${DUMP}/dump"; fi
@echo "Restore Complete!"
@echo "Used backup: ${DUMP}"
##################### Static assets
# To collect assets we don't rely on the "paver update_assets" command because
# webpack collection incorrectly sets the NODE_ENV variable when using custom
# settings. Thus, each step must be performed separately. This should be fixed
# in the next edx-platform release thanks to https://github.com/edx/edx-platform/pull/18430/
#assets-lms: ## Collect static assets for the LMS
# $(DOCKER_COMPOSE_RUN_OPENEDX) lms -e NO_PREREQ_INSTALL=True lms paver update_assets lms --settings=$(EDX_PLATFORM_SETTINGS)
#assets-cms: ## Collect static assets for the CMS
# $(DOCKER_COMPOSE_RUN_OPENEDX) cms -e NO_PREREQ_INSTALL=True cms paver update_assets cms --settings=$(EDX_PLATFORM_SETTINGS)
assets: assets-lms assets-cms ## Generate production-ready static assets
assets-development: assets-development-lms assets-development-cms ## Generate static assets for local development
assets-lms:
$(DOCKER_COMPOSE_RUN_OPENEDX) --no-deps lms bash -c \
"NODE_ENV=production ./node_modules/.bin/webpack --config=webpack.prod.config.js \
&& ./manage.py lms --settings=$(EDX_PLATFORM_SETTINGS) compile_sass lms \
&& python -c \"import pavelib.assets; pavelib.assets.collect_assets(['lms'], '$(EDX_PLATFORM_SETTINGS)')\""
assets-cms:
$(DOCKER_COMPOSE_RUN_OPENEDX) --no-deps cms bash -c \
"NODE_ENV=production ./node_modules/.bin/webpack --config=webpack.prod.config.js \
&& ./manage.py cms --settings=$(EDX_PLATFORM_SETTINGS) compile_sass studio \
&& python -c \"import pavelib.assets; pavelib.assets.collect_assets(['studio'], '$(EDX_PLATFORM_SETTINGS)')\""
assets-development-lms:
$(DOCKER_COMPOSE_RUN_OPENEDX) --no-deps lms bash -c \
"xmodule_assets common/static/xmodule \
&& python -c \"import pavelib.assets; pavelib.assets.process_npm_assets()\" \
&& NODE_ENV=development ./node_modules/.bin/webpack --config=webpack.dev.config.js \
&& ./manage.py lms --settings=$(EDX_PLATFORM_SETTINGS) compile_sass lms \
&& python -c \"import pavelib.assets; pavelib.assets.collect_assets(['lms'], '$(EDX_PLATFORM_SETTINGS)')\""
assets-development-cms:
$(DOCKER_COMPOSE_RUN_OPENEDX) --no-deps cms bash -c \
"xmodule_assets common/static/xmodule \
&& python -c \"import pavelib.assets; pavelib.assets.process_npm_assets()\" \
&& NODE_ENV=development ./node_modules/.bin/webpack --config=webpack.dev.config.js \
&& ./manage.py cms --settings=$(EDX_PLATFORM_SETTINGS) compile_sass studio \
&& python -c \"import pavelib.assets; pavelib.assets.collect_assets(['studio'], '$(EDX_PLATFORM_SETTINGS)')\""
##################### Information
# Obtained by running "echo '\033' in a shell
ESCAPE =
help: ## Print this help
@grep -E '^([a-zA-Z_-]+:.*?## .*|######* .+)$$' Makefile \
| sed 's/######* \(.*\)/\n $(ESCAPE)[1;31m\1$(ESCAPE)[0m/g' \
| awk 'BEGIN {FS = ":.*?## "}; {printf "\033[33m%-30s\033[0m %s\n", $$1, $$2}'
info: ## Print some information about the current install, for debugging
uname -a
@echo "-------------------------"
git rev-parse HEAD
@echo "-------------------------"
docker version
@echo "-------------------------"
docker-compose --version
@echo "-------------------------"
echo $$EDX_PLATFORM_PATH
echo $$EDX_PLATFORM_SETTINGS
#################### Logging
logs: ## Print all logs from a service since it started. E.g: "make logs service=lms", "make logs service=nginx"
$(DOCKER_COMPOSE) logs $(service)
tail: ## Similar to "tail" on the logs of a service. E.g: "make tail service=lms", "make tail service=nginx"
$(DOCKER_COMPOSE) logs --tail=10 $(service)
tail-follow: ## Similar to "tail -f" on the logs of a service. E.g: "make tail-follow service=lms", "make tail-follow service=nginx"
$(DOCKER_COMPOSE) logs --tail=10 -f $(service)
#################### Docker image building & updating
update: ## Download most recent images
$(DOCKER_COMPOSE) pull
build: build-openedx build-configurator build-forum build-notes build-xqueue build-android ## Build all docker images
openedx_build_args =
ifdef EDX_PLATFORM_REPOSITORY
openedx_build_args += --build-arg="EDX_PLATFORM_REPOSITORY=$(EDX_PLATFORM_REPOSITORY)"
endif
ifdef EDX_PLATFORM_VERSION
openedx_build_args += --build-arg="EDX_PLATFORM_VERSION=$(EDX_PLATFORM_VERSION)"
endif
build-openedx: ## Build the Open edX docker image
docker build -t regis/openedx:latest -t regis/openedx:hawthorn $(openedx_build_args) openedx/
build-configurator: ## Build the configurator docker image
docker build -t regis/openedx-configurator:latest -t regis/openedx-configurator:hawthorn configurator/
build-forum: ## Build the forum docker image
docker build -t regis/openedx-forum:latest -t regis/openedx-forum:hawthorn forum/
build-notes: ## Build the Notes docker image
docker build -t regis/openedx-notes:latest -t regis/openedx-notes:hawthorn notes/
build-xqueue: ## Build the Xqueue docker image
docker build -t regis/openedx-xqueue:latest -t regis/openedx-xqueue:hawthorn xqueue/
build-android: ## Build the docker image for Android
docker build -t regis/openedx-android:latest android/
################### Pushing images to docker hub
push: push-openedx push-configurator push-forum push-notes push-xqueue push-android ## Push all images to dockerhub
push-openedx: ## Push Open edX images to dockerhub
docker push regis/openedx:hawthorn
docker push regis/openedx:latest
push-configurator: ## Push configurator image to dockerhub
docker push regis/openedx-configurator:hawthorn
docker push regis/openedx-configurator:latest
push-forum: ## Push forum image to dockerhub
docker push regis/openedx-forum:hawthorn
docker push regis/openedx-forum:latest
push-notes: ## Push notes image to dockerhub
docker push regis/openedx-notes:hawthorn
docker push regis/openedx-notes:latest
push-xqueue: ## Push Xqueue image to dockerhub
docker push regis/openedx-xqueue:hawthorn
docker push regis/openedx-xqueue:latest
push-android: ## Push the Android image to dockerhub
docker push regis/openedx-android:latest
dockerhub: build push ## Build and push all images to dockerhub
##################### Development
lms: ## Open a bash shell in the LMS
$(DOCKER_COMPOSE_RUN_LMS) bash
cms: ## Open a bash shell in the CMS
$(DOCKER_COMPOSE_RUN_CMS) bash
lms-python: ## Open a python shell in the LMS
$(DOCKER_COMPOSE_RUN_OPENEDX) lms ./manage.py lms shell
lms-shell: lms-python
cms-python: ## Open a python shell in the CMS
$(DOCKER_COMPOSE_RUN_OPENEDX) cms ./manage.py cms shell
cms-shell: cms-python
restart-openedx: ## Restart lms, cms, and workers
docker-compose restart lms lms_worker cms cms_worker
##################### SSL/TLS (HTTPS certificates)
https_command = docker run --rm -it \
--volume="$(PWD)/config/letsencrypt/:/openedx/letsencrypt/config/" \
--volume="$(PWD)/data/letsencrypt/:/etc/letsencrypt/" \
-p "80:80"
certbot_image = certbot/certbot:latest
https-certificate: ## Generate https certificates
$(https_command) --entrypoint "/openedx/letsencrypt/config/certonly.sh" $(certbot_image)
https-certificate-renew: ## Renew https certificates
$(https_command) $(certbot_image) renew
#################### Android application
android: ## Build the Android app, for development
@docker-compose -f docker-compose-android.yml run --rm android
@echo "Your APK file is ready: ./data/android/$(shell ls data/android/*.apk)"
android-release: ## Build the final Android app (beta)
# Note that this requires that you edit ./config/android/gradle.properties
docker-compose -f docker-compose-android.yml run --rm android ./gradlew assembleProdRelease
##################### Additional commands
stats: ## Collect anonymous information about the platform
@docker run --rm -it --volume="$(PWD)/config:/openedx/config" \
regis/openedx-configurator:hawthorn /openedx/config/openedx/stats 2> /dev/null|| true
import-demo-course: ## Import the demo course from edX
$(DOCKER_COMPOSE_RUN_OPENEDX) cms /bin/bash -c "git clone https://github.com/edx/edx-demo-course ../edx-demo-course && git -C ../edx-demo-course checkout open-release/hawthorn.beta1 && python ./manage.py cms import ../data ../edx-demo-course"
create-staff-user: ## Create a user with admin rights
$(DOCKER_COMPOSE_RUN_OPENEDX) lms /bin/bash -c "./manage.py lms manage_user --superuser --staff ${USERNAME} ${EMAIL} && ./manage.py lms changepassword ${USERNAME}"