2019-02-13 19:18:47 +00:00
|
|
|
#! /bin/bash -e
|
|
|
|
# Provision an AWS cloud instance with tutor.
|
2019-06-23 17:56:15 +00:00
|
|
|
# Run with: curl -sSL https://raw.githubusercontent.com/overhangio/tutor/master/cloud/aws.sh | bash -e
|
2019-02-13 19:18:47 +00:00
|
|
|
|
|
|
|
export DEBIAN_FRONTEND=noninteractive
|
|
|
|
|
|
|
|
echo "=============== Installing system dependencies"
|
2019-03-10 17:13:02 +00:00
|
|
|
sudo apt update \
|
|
|
|
&& sudo apt install -y \
|
2019-02-13 19:18:47 +00:00
|
|
|
apt-transport-https \
|
|
|
|
ca-certificates \
|
|
|
|
curl \
|
|
|
|
gnupg-agent \
|
2019-03-11 17:47:33 +00:00
|
|
|
software-properties-common
|
2019-02-13 19:18:47 +00:00
|
|
|
|
|
|
|
echo "=============== Installing docker"
|
2019-03-10 17:13:02 +00:00
|
|
|
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
|
|
|
|
sudo add-apt-repository \
|
2019-02-13 19:18:47 +00:00
|
|
|
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
|
|
|
|
$(lsb_release -cs) \
|
|
|
|
stable"
|
2019-03-10 17:13:02 +00:00
|
|
|
sudo apt update
|
|
|
|
sudo apt install -y docker-ce docker-ce-cli containerd.io
|
2019-03-18 19:39:31 +00:00
|
|
|
sudo usermod -aG docker $USER
|
|
|
|
sudo su - $USER
|
2019-03-18 21:40:45 +00:00
|
|
|
|
|
|
|
echo "=============== Run local docker registry on port 5000"
|
|
|
|
docker run -d -p 5000:5000 --restart=always --name docker_registry registry:2.7.1
|
2019-02-13 19:18:47 +00:00
|
|
|
|
|
|
|
echo "=============== Installing docker-compose"
|
2019-03-10 17:13:02 +00:00
|
|
|
sudo curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
|
|
|
|
sudo chmod +x /usr/local/bin/docker-compose
|
2019-02-13 19:18:47 +00:00
|
|
|
|
|
|
|
echo "=============== Installing tutor"
|
2019-06-23 17:56:15 +00:00
|
|
|
export TUTOR_VERSION="$(curl -sSL https://api.github.com/repos/overhangio/tutor/releases/latest | grep tag_name | sed "s/.*tag_name\": \"\(.*\)\",/\1/g")"
|
|
|
|
sudo curl -L "https://github.com/overhangio/tutor/releases/download/$TUTOR_VERSION/tutor-$(uname -s)_$(uname -m)" -o /usr/local/bin/tutor
|
2019-03-10 17:13:02 +00:00
|
|
|
sudo chmod +x /usr/local/bin/tutor
|
2019-02-13 19:18:47 +00:00
|
|
|
|
2019-03-13 17:28:13 +00:00
|
|
|
echo "=============== Pulling vendor docker images"
|
2019-06-05 17:45:22 +00:00
|
|
|
tutor config save
|
2019-03-18 21:40:45 +00:00
|
|
|
tutor images pull elasticsearch
|
|
|
|
tutor images pull memcached
|
|
|
|
tutor images pull mongodb
|
|
|
|
tutor images pull mysql
|
|
|
|
tutor images pull nginx
|
|
|
|
tutor images pull rabbitmq
|
2019-03-20 17:45:09 +00:00
|
|
|
tutor images pull smtp
|
2019-03-18 21:40:45 +00:00
|
|
|
|
|
|
|
echo "=============== Tagging vendor docker images"
|
|
|
|
docker tag $(tutor config printvalue DOCKER_IMAGE_ELASTICSEARCH) localhost:5000/$(tutor config printvalue DOCKER_IMAGE_ELASTICSEARCH)
|
|
|
|
docker tag $(tutor config printvalue DOCKER_IMAGE_MEMCACHED) localhost:5000/$(tutor config printvalue DOCKER_IMAGE_MEMCACHED)
|
|
|
|
docker tag $(tutor config printvalue DOCKER_IMAGE_MONGODB) localhost:5000/$(tutor config printvalue DOCKER_IMAGE_MONGODB)
|
|
|
|
docker tag $(tutor config printvalue DOCKER_IMAGE_MYSQL) localhost:5000/$(tutor config printvalue DOCKER_IMAGE_MYSQL)
|
2019-03-20 17:45:09 +00:00
|
|
|
docker tag $(tutor config printvalue DOCKER_IMAGE_SMTP) localhost:5000/$(tutor config printvalue DOCKER_IMAGE_SMTP)
|
2019-03-18 21:40:45 +00:00
|
|
|
docker tag $(tutor config printvalue DOCKER_IMAGE_NGINX) localhost:5000/$(tutor config printvalue DOCKER_IMAGE_NGINX)
|
|
|
|
docker tag $(tutor config printvalue DOCKER_IMAGE_RABBITMQ) localhost:5000/$(tutor config printvalue DOCKER_IMAGE_RABBITMQ)
|
|
|
|
|
|
|
|
echo "=============== Pushing vendor docker images to the local registry"
|
|
|
|
docker push localhost:5000/$(tutor config printvalue DOCKER_IMAGE_ELASTICSEARCH)
|
|
|
|
docker push localhost:5000/$(tutor config printvalue DOCKER_IMAGE_MEMCACHED)
|
|
|
|
docker push localhost:5000/$(tutor config printvalue DOCKER_IMAGE_MONGODB)
|
|
|
|
docker push localhost:5000/$(tutor config printvalue DOCKER_IMAGE_MYSQL)
|
2019-03-20 17:45:09 +00:00
|
|
|
docker push localhost:5000/$(tutor config printvalue DOCKER_IMAGE_SMTP)
|
2019-03-18 21:40:45 +00:00
|
|
|
docker push localhost:5000/$(tutor config printvalue DOCKER_IMAGE_NGINX)
|
|
|
|
docker push localhost:5000/$(tutor config printvalue DOCKER_IMAGE_RABBITMQ)
|
|
|
|
|
|
|
|
echo "=============== Building openedx docker images"
|
2019-06-05 17:45:22 +00:00
|
|
|
tutor config save --set ACTIVATE_NOTES=true --set ACTIVATE_XQUEUE=true --set DOCKER_REGISTRY=localhost:5000/
|
2019-03-06 15:32:23 +00:00
|
|
|
tutor images build all
|
|
|
|
|
2019-03-10 17:53:28 +00:00
|
|
|
echo "=============== Create Web UI script"
|
|
|
|
echo '#! /bin/bash
|
|
|
|
if [ ! -f $(tutor config printroot)/env/webui/config.yml ]; then
|
2019-03-11 17:25:24 +00:00
|
|
|
mkdir -p $(tutor config printroot)/env/webui
|
2019-03-10 17:53:28 +00:00
|
|
|
tutor webui configure --user tutor --password "$(curl http://169.254.169.254/latest/meta-data/instance-id)"
|
|
|
|
fi
|
|
|
|
tutor webui start' | sudo tee /usr/local/bin/tutor-webui
|
|
|
|
sudo chmod +x /usr/local/bin/tutor-webui
|
2019-03-10 16:10:52 +00:00
|
|
|
|
2019-03-11 17:47:33 +00:00
|
|
|
echo "=============== Configuring systemd"
|
|
|
|
echo "[Unit]
|
|
|
|
Description=Tutor web UI
|
|
|
|
After=network.target
|
|
|
|
|
|
|
|
[Service]
|
2019-03-18 19:39:31 +00:00
|
|
|
User=$USER
|
|
|
|
WorkingDirectory=/home/$USER
|
2019-03-18 23:50:47 +00:00
|
|
|
Environment=HOME=/home/$USER
|
|
|
|
Environment=TUTOR_DOCKER_REGISTRY=localhost:5000/
|
2019-03-11 17:47:33 +00:00
|
|
|
ExecStart=/usr/local/bin/tutor-webui
|
|
|
|
Restart=on-failure
|
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=multi-user.target" | sudo tee /etc/systemd/system/tutor-webui.service
|
|
|
|
sudo systemctl enable tutor-webui
|
2019-03-13 17:31:52 +00:00
|
|
|
|
2019-03-18 21:40:45 +00:00
|
|
|
echo "=============== Clean tutor environment, configuration and data"
|
|
|
|
sudo rm -rf $(tutor config printroot)
|
|
|
|
|
2019-03-13 17:31:52 +00:00
|
|
|
echo "=============== Clean authorized keys"
|
|
|
|
sudo find / -name "authorized_keys" -exec rm -f {} \;
|
|
|
|
|
|
|
|
echo "=============== Clean history"
|
|
|
|
sudo find /root/.*history /home/*/.*history -exec rm -f {} \;
|