Skip to content

Instantly share code, notes, and snippets.

@dave-burke
Last active February 2, 2022 04:04
Show Gist options
  • Save dave-burke/8e4f8fb1e0056ce7ddb21dbde0f9308c to your computer and use it in GitHub Desktop.
Save dave-burke/8e4f8fb1e0056ce7ddb21dbde0f9308c to your computer and use it in GitHub Desktop.
Userdata script to initialize an Ubuntu 20.04 instance with https://workadventu.re
set -e
DOMAIN=example.com
LETS_ENCRYPT_EMAIL=todo@example.com
WORKADVENTURE_START_ROOM='_\/global\/workadventure.github.io\/game-room\/map.json'
JITSI_TIMEZONE='UTC'
JITSI_CONFIG_DIR="\/etc\/jitsi"
function setEnv() {
sed -i "s/#\?${1}=.*/${1}=${2}/" ${3}
}
echo "Updating packages..."
apt-get -y update
apt-get -y upgrade
apt-get -y install docker.io docker-compose
echo "Setting up Jitsi Meet..."
cd /opt
git clone https://github.com/jitsi/docker-jitsi-meet
cd docker-jitsi-meet
cp env.example .env
./gen-passwords.sh # sets passwords in .env
setEnv "CONFIG" "${JITSI_CONFIG_DIR}" .env
setEnv "TZ" "${JITSI_TIMEZONE}" .env
setEnv "PUBLIC_URL" "http:\/\/meet.${DOMAIN}" .env
setEnv "ETHERPAD_PUBLIC_URL" "https:\/\/etherpad.${DOMAIN}" .env
sed -i "s/ web:/a\
labels:\n\
- 'traefik.docker.network=meet.jitsi'
- 'traefik.http.routers.jitsi.rule=Host(`meet.${DOMAIN}`)'\n\
- 'traefik.http.routers.jitsi.entryPoints=web,traefik'\n\
- 'traefik.http.services.jitsi.loadbalancer.server.port=8000'\n\
- 'traefik.http.routers.jitsi-ssl.rule=Host(`meet.${DOMAIN}`)'\n\
- 'traefik.http.routers.jitsi-ssl.entryPoints=websecure'\n\
- 'traefik.http.routers.jitsi-ssl.tls=true'\n\
- 'traefik.http.routers.jitsi-ssl.service=jitsi'\n\
- 'traefik.http.routers.jitsi-ssl.tls.certresolver=myresolver'" docker-compose.yml
sed -i "s/ etherpad:/a\
labels:\n\
- 'traefik.docker.network=meet.jitsi'
- 'traefik.http.routers.etherpad.rule=Host(`etherpad.${DOMAIN}`)'\n\
- 'traefik.http.routers.etherpad.entryPoints=web,traefik'\n\
- 'traefik.http.services.etherpad.loadbalancer.server.port=8000'\n\
- 'traefik.http.routers.etherpad-ssl.rule=Host(`etherpad.${DOMAIN}`)'\n\
- 'traefik.http.routers.etherpad-ssl.entryPoints=websecure'\n\
- 'traefik.http.routers.etherpad-ssl.tls=true'\n\
- 'traefik.http.routers.etherpad-ssl.service=jitsi'\n\
- 'traefik.http.routers.etherpad-ssl.tls.certresolver=myresolver'" etherpad.yml
mkdir -p ${JITSI_CONFIG_DIR}/{web/crontabs,web/letsencrypt,transcripts,prosody/config,prosody/prosody-plugins-custom,jicofo,jvb,jigasi,jibri}
echo "Setting up workadventure..."
git clone https://github.com/thecodingmachine/workadventure.git /opt/workadventure
cd /opt/workadventure/contrib/docker
git checkout v1.7.3 # or whatever is the latest, but 'master' won't always build successfully
cp .env.prod.template .env.prod
setEnv "DOMAIN" "workadventure.${DOMAIN}" .env.prod
setEnv "ACME_EMAIL" "${LETS_ENCRYPT_EMAIL}" .env.prod
setEnv "START_ROOM_URL" "${WORKADVENTURE_START_ROOM}" .env.prod
touch acme.json # this file needs to exist
chmod 600 acme.json # and have the proper permissions
echo "Creating start script..."
echo '#!/bin/bash
set -e
cd /opt/docker-jitsi-meet
docker-compose -f docker-compose.yml -f etherpad.yml up -d
cd /opt/workadventure/contrib/docker
docker-compose -f docker-compose.prod.yaml --env-file .env.prod up -d
' >> /root/up.sh
chmod 755 /root/up.sh
echo "User data done!"
echo "Ensure that you have a DNS wildcard record for workadventure under your domain ('*.workadventure.[DOMAIN]'),"
echo "and a DNS entry for 'meet.[DOMAIN]' and 'etherpad.[DOMAIN]'"
echo "then run '/root/up.sh' and use 'docker logs -f docker_front_1' to watch for the service to be ready (it takes a while)."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment