config initial

This commit is contained in:
Thomas Briffard 2020-01-25 11:53:33 -05:00
commit edbc602232
5 changed files with 133 additions and 0 deletions

12
Dockerfile Normal file
View File

@ -0,0 +1,12 @@
# docker build -t theia-vpn .
FROM theiaide/theia:next
USER root
RUN apk add openconnect shadow --no-cache --repository http://dl-3.alpinelinux.org/alpine/edge/testing/ --allow-untrusted
COPY docker-entrypoint.sh /docker-entrypoint.sh
HEALTHCHECK --interval=10s --timeout=10s --start-period=10s \
CMD /sbin/ifconfig tun0
ENTRYPOINT ["/docker-entrypoint.sh"]

37
docker-compose.yml Normal file
View File

@ -0,0 +1,37 @@
version: '3.7'
services:
nginx:
image: nginx:alpine-perl
container_name: theia_nginx
environment:
- GIREF_HOSTNAME=${GIREF_HOSTNAME}
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
ports:
- 80:80
theia:
build:
context: .
dockerfile: Dockerfile
container_name: theia
image: theia-vpn
expose:
- "3000"
volumes:
- "$VOLUME:/home/project:cached"
- ~/.ssh:/home/.ssh:ro
init: true
environment:
- ANYCONNECT_SERVER=${ANYCONNECT_SERVER}
- ANYCONNECT_USER=${ANYCONNECT_USER}
- ANYCONNECT_PASSWORD=${ANYCONNECT_SERVER}
- USER_ID=${USER_ID}
networks:
- default
cap_add:
- NET_ADMIN
devices:
- /dev/net/tun:/dev/net/tun
restart: unless-stopped

29
docker-entrypoint.sh Executable file
View File

@ -0,0 +1,29 @@
#!/bin/bash
# Connection au VPN de l'Université Laval
( echo $ANYCONNECT_PASSWORD ) | openconnect $ANYCONNECT_SERVER --user=$ANYCONNECT_USER --timestamp &
id_node=$(id -u node)
if [ $id_node != ${USER_ID} ]; then
echo "Création de l'utilisateur giref avec uid=${USER_ID}"
uname=giref
uid=${USER_ID}
adduser -u $uid -h /home/giref/ -s /bin/bash -D giref;
user=giref
else
user=node
echo "Votre USER_ID correspond à celui de l'utilisateur node, on utilise donc l'utilisateur node"
fi
# Si l'utilisateur monte son répertoire .ssh dans le répertoire /home/.ssh du conteneur, alors on
# copie automatiquement les clefs pour l'utilisateur crée auparavant
if [ -d /home/.ssh ]; then
echo "Copie des clefs SSH et ajout des bonnes permissions..."
cp -r /home/.ssh /home/$user/.ssh
chown -R $user:$user /home/$user/.ssh
fi
# Enfin, reprend le entrypoint donné ici : https://github.com/theia-ide/theia-apps/blob/master/theia-docker/Dockerfile
echo "Lancement de theia..."
su $user bash -c "/usr/local/bin/node /home/theia/src-gen/backend/main.js /home/project --hostname=0.0.0.0"

29
nginx.conf Normal file
View File

@ -0,0 +1,29 @@
load_module "modules/ngx_http_perl_module.so";
env GIREF_HOSTNAME;
events {
}
http {
error_log /etc/nginx/error_log.log warn;
client_max_body_size 20m;
perl_set $giref_hostname 'sub { return $ENV{"GIREF_HOSTNAME"}; }';
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
server_name $giref_hostname;
location /theia {
proxy_pass http://theia:3000/;
rewrite ^/theia(/.*)$ $1 break;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
#rewrite ^/theia(.*)$ $1 break;
}
}
}

26
wrapper.sh Executable file
View File

@ -0,0 +1,26 @@
#!/bin/bash
command -v docker-compose >/dev/null 2>&1 || { echo >&2 "L'outil docker-compose n'est pas présent, cf https://docs.docker.com/compose/install/"; exit 1;}
###### Seules variables à modifier ######
export GIREF_HOSTNAME=votre_machine
export VOLUME=le_dossier_a_monter
export ANYCONNECT_USER=votre_idul
##########################################
# Ne pas éditer le reste
export USER_ID=$(id -u)
export ANYCONNECT_SERVER=vpn.ulaval.ca
if [ "$1" == "up" ]; then
echo -n "Veuillez rentrer votre mot de passe pour ${ANYCONNECT_SERVER} :"
read -s $password
echo
export ANYCONNECT_PASSWORD=$password
docker-compose up -d
echo "Vous pouvez vous connecter à http://${GIREF_HOSTNAME}/theia/"
elif [ "$1" == "down" ]; then
echo "Arrêt de theia..."
docker-compose down
fi