Skip to content

Instantly share code, notes, and snippets.

@cmd-ntrf
Created June 15, 2019 18:03
Show Gist options
  • Save cmd-ntrf/95f9843a8dad1684b31a2c16e50dbef5 to your computer and use it in GitHub Desktop.
Save cmd-ntrf/95f9843a8dad1684b31a2c16e50dbef5 to your computer and use it in GitHub Desktop.
Terraform setup to test wrapspawner link_traits branch with DockerSpawner on OpenStack
provider "openstack" {}
data "openstack_networking_network_v2" "network_internal" {
external = "False"
}
data "openstack_networking_network_v2" "network_external" {
external = "True"
}
resource "openstack_networking_port_v2" "port" {
name = "port"
network_id = "${data.openstack_networking_network_v2.network_internal.id}"
}
resource "openstack_compute_instance_v2" "jupyterhub" {
name = "jupyterhub"
image_name = "CentOS-7-x64-2018-11"
flavor_name = "p2-3gb"
security_groups = ["default"]
key_pair = "Macbook"
network {
port = "${openstack_networking_port_v2.port.id}"
}
user_data = <<EOF
#cloud-config
hostname: jupyterhub_test
users:
- default
- name: jovyan
groups: users
lock_passwd: false
yum_repos:
epel:
name: Extra Packages for Enterprise Linux
baseurl: http://dl.fedoraproject.org/pub/epel/$releasever/$basearch
enabled: true
gpgcheck: false
packages:
- git
- python36
- docker
- npm
runcmd:
- sed -i s/SELINUX=enforcing/SELINUX=disabled/ /etc/selinux/config
- groupadd docker
- usermod -aG docker jovyan
- systemctl start docker
- systemctl enable docker
- bash /tmp/setup_jupyterhub.sh
- reboot -n
write_files:
- content: |
# JupyterHub config file
c.JupyterHub.spawner_class = 'wrapspawner.ProfilesSpawner'
c.ProfilesSpawner.profiles = [
('Host process', 'local', 'jupyterhub.spawner.LocalProcessSpawner', {'ip':'0.0.0.0'} ),
('Docker Python 3', 'singleuser', 'dockerspawner.SystemUserSpawner', dict(image="jupyterhub/singleuser:1.0")),
('Docker Scipy Notebook', 'scipy-notebook', 'dockerspawner.SystemUserSpawner', dict(image="jupyter/scipy-notebook:d4cbf2f80a2a")),
]
c.Spawner.start_timeout = 180
c.Spawner.http_timeout = 180
c.JupyterHub.proxy_api_ip = '${openstack_networking_port_v2.port.all_fixed_ips.0}'
c.JupyterHub.hub_connect_ip = '${openstack_networking_port_v2.port.all_fixed_ips.0}'
c.JupyterHub.hub_ip = '0.0.0.0'
c.PAMAuthenticator.open_sessions = False
c.DockerSpawner.remove = True
path: /opt/jupyterhub/etc/jupyterhub_config.py
- content: |
#!/bin/bash
python36 -m venv /opt/jupyterhub
source /opt/jupyterhub/bin/activate
pip install jupyterhub notebook dockerspawner
pip install git+https://github.com/cmd-ntrf/wrapspawner@link_traits
npm install -g configurable-http-proxy
docker pull jupyterhub/singleuser:1.0
docker pull jupyter/scipy-notebook:d4cbf2f80a2a
systemctl start jupyterhub
systemctl enable jupyterhub
path: /tmp/setup_jupyterhub.sh
- content: |
[Unit]
Description=Jupyterhub
After=network-online.target
[Service]
User=root
Group=root
Environment=PATH=/bin:/usr/bin:/opt/jupyterhub/bin
ExecStart=/opt/jupyterhub/bin/jupyterhub --config /opt/jupyterhub/etc/jupyterhub_config.py
WorkingDirectory=/opt/jupyterhub/etc
[Install]
WantedBy=multi-user.target
path: /usr/lib/systemd/system/jupyterhub.service
output: { all: "| tee -a /var/log/cloud-init-output.log" }
EOF
}
resource "openstack_networking_floatingip_v2" "jupyterhub" {
pool = "${data.openstack_networking_network_v2.network_external.name}"
}
resource "openstack_compute_floatingip_associate_v2" "jupyterhub" {
floating_ip = "${openstack_networking_floatingip_v2.jupyterhub.address}"
instance_id = "${openstack_compute_instance_v2.jupyterhub.id}"
}
output "ip_address" {
value = "${openstack_networking_floatingip_v2.jupyterhub.address}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment