-
Notifications
You must be signed in to change notification settings - Fork 2
/
provision.sh
executable file
·83 lines (61 loc) · 3.88 KB
/
provision.sh
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
#!/usr/bin/env bash
set -e
set -o pipefail
set -x
GREEN='\033[0;32m'
NC='\033[0m' # No Color
if [ -z ${CONTAINER_PREFIX} ]; then
export CONTAINER_PREFIX='edx'
echo "Defaulting CONTAINER_PREFIX to edx"
fi
echo -e "${GREEN}Creating .env file...${NC}"
cat > .env << EOF
CONTAINER_PREFIX=${CONTAINER_PREFIX}
COMPOSE_PROJECT_NAME=${CONTAINER_PREFIX}
EOF
# Bring the databases online.
docker-compose up -d mysql mongo
# Ensure the MySQL server is online and usable
echo "Waiting for MySQL"
until docker exec -i ${CONTAINER_PREFIX}.mysql mysql -uroot -se "SELECT EXISTS(SELECT 1 FROM mysql.user WHERE user = 'root')" &> /dev/null
do
printf "."
sleep 1
done
# In the event of a fresh MySQL container, wait a few seconds for the server to restart
# This can be removed once https://github.com/docker-library/mysql/issues/245 is resolved.
sleep 20
echo -e "MySQL ready"
echo -e "${GREEN}Creating databases and users...${NC}"
docker exec -i ${CONTAINER_PREFIX}.mysql mysql -uroot mysql < data/provision.sql
docker exec -i ${CONTAINER_PREFIX}.mongo mongo < data/mongo-provision.js
# Load databases
echo -e "${GREEN}Loading databases...${NC}"
docker exec -i ${CONTAINER_PREFIX}.mysql mysql -uroot edxapp < data/edxapp.sql
docker exec -i ${CONTAINER_PREFIX}.mysql mysql -uroot edxapp_csmh < data/edxapp_csmh.sql
# Bring edxapp containers online
echo -e "${GREEN}Bringing containers online${NC}"
docker-compose -f docker-compose.yml -f docker-compose-host.yml up -d lms
docker-compose -f docker-compose.yml -f docker-compose-host.yml up -d studio
echo -e "${GREEN}Installing prereqs ${NC}"
docker-compose exec lms bash -c 'source /edx/app/edxapp/edxapp_env && cd /edx/app/edxapp/edx-platform && NO_PYTHON_UNINSTALL=1 paver install_prereqs'
docker-compose exec studio bash -c 'source /edx/app/edxapp/edxapp_env && cd /edx/app/edxapp/edx-platform && NO_PYTHON_UNINSTALL=1 paver install_prereqs'
# Installing prereqs crashes the process
echo -e "${GREEN}Restarting LMS Studio${NC}"
docker-compose restart lms studio
echo -e "${GREEN} Run edxapp migrations first since they are needed for the service users and OAuth clients ${NC}"
docker-compose exec lms bash -c 'source /edx/app/edxapp/edxapp_env && cd /edx/app/edxapp/edx-platform && paver update_db --settings devstack_docker'
docker-compose exec studio bash -c 'source /edx/app/edxapp/edxapp_env && cd /edx/app/edxapp/edx-platform && paver update_db --settings devstack_docker'
echo -e "${GREEN} Create a superuser for edxapp ${NC}"
docker-compose exec lms bash -c 'source /edx/app/edxapp/edxapp_env && python /edx/app/edxapp/edx-platform/manage.py lms --settings=devstack_docker manage_user edx [email protected] --superuser --staff'
docker-compose exec lms bash -c 'source /edx/app/edxapp/edxapp_env && echo "from django.contrib.auth import get_user_model; User = get_user_model(); user = User.objects.get(username=\"edx\"); user.set_password(\"edx\"); user.save()" | python /edx/app/edxapp/edx-platform/manage.py lms shell --settings=devstack_docker'
echo -e "${GREEN} Create demo course and users ${NC}"
docker-compose exec lms bash -c '/edx/app/edx_ansible/venvs/edx_ansible/bin/ansible-playbook /edx/app/edx_ansible/edx_ansible/playbooks/edx-east/demo.yml -v -c local -i "127.0.0.1," --extra-vars="COMMON_EDXAPP_SETTINGS=devstack_docker"'
docker-compose exec lms bash -c 'source /edx/app/edxapp/edxapp_env && cd /edx/app/edxapp/edx-platform && paver update_assets --settings devstack_docker'
docker-compose exec studio bash -c 'source /edx/app/edxapp/edxapp_env && cd /edx/app/edxapp/edx-platform && paver update_assets --settings devstack_docker'
echo -e "${GREEN} Installing nano ${NC}"
docker-compose exec lms bash -c 'sudo apt-get install -y nano'
docker-compose exec studio bash -c 'sudo apt-get install -y nano'
docker-compose -f docker-compose.yml -f docker-compose-host.yml up -d studio
docker-compose -f docker-compose.yml -f docker-compose-host.yml up -d forum
echo -e "${GREEN}FINISHED !!!${NC}"