From 1530ccd2952ed5d7eaa169f6a326b022de0b3212 Mon Sep 17 00:00:00 2001 From: Gustavo Cordova Date: Wed, 15 Feb 2023 13:28:57 -0800 Subject: [PATCH] Initial commit --- Dockerfile | 49 ++++++++++++++++++++++++++++++++++++++++++++++ Makefile | 48 +++++++++++++++++++++++++++++++++++++++++++++ README.md | 40 +++++++++++++++++++++++++++++++++++++ docker-compose.yml | 8 ++++++++ 4 files changed, 145 insertions(+) create mode 100644 Dockerfile create mode 100644 Makefile create mode 100644 README.md create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0cb2ace --- /dev/null +++ b/Dockerfile @@ -0,0 +1,49 @@ +# Systemd inside a Docker container, for CI only +FROM ubuntu:22.10 + +# Configure Ubuntu with SystemD +RUN export DEBIAN_FRONTEND=noninteractive TZ=America/Los_Angeles \ + && apt-get update -y \ + && apt-get upgrade -y \ + && apt-get install -y \ + systemd \ + curl \ + git \ + sudo \ + python3-pip python3-venv \ + && rm -rfv /var/lib/apt/lists/* \ + && find /etc/systemd/system /lib/systemd/system \ + -path '*.wants/*' \ + -not -name '*journald*' \ + -not -name '*systemd-tmpfiles*' \ + -not -name '*systemd-user-sessions*' \ + -exec rm -fv {} \; + +# Some required environment variables.... +ENV TLJH_BOOTSTRAP_DEV=yes \ + TLJH_BOOTSTRAP_PIP_SPEC=/srv/src \ + PATH=/opt/tljh/hub/bin:${PATH} + +# Tell SystemD to start up... +RUN systemctl set-default multi-user.target + +# Download the repository into its expected location +# and run the bootstrapper to initialize the service. +ARG TLJH_ADMIN_USERNAME="admin" +ARG TLJH_ADMIN_PASSWORD="admin" +ARG TLJH_REPO="https://github.com/jupyterhub/the-littlest-jupyterhub" +RUN git clone --depth=1 "$TLJH_REPO" /srv/src && rm -rf /srv/src/.git + +# Preinstall everything needed, this will fail when it tries to start up tljh +RUN python3 /srv/src/bootstrap/bootstrap.py --admin "$TLJH_ADMIN_USERNAME:$TLJH_ADMIN_PASSWORD" || true + +# Finish running the installer as first thing when systemd is up +RUN CRED="$TLJH_ADMIN_USERNAME:$TLJH_ADMIN_PASSWORD" \ + && echo '#!/bin/bash' > /etc/rc.local \ + && echo "/opt/tljh/hub/bin/python3 -m tljh.installer --admin '$CRED'" >> /etc/rc.local \ + && chmod 755 /etc/rc.local + +# This is what's running on container startup +CMD ["/lib/systemd/systemd", "--log-target=journal"] +EXPOSE 80/tcp +STOPSIGNAL SIGRTMIN+3 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..46dfb00 --- /dev/null +++ b/Makefile @@ -0,0 +1,48 @@ +.PHONY: help clean build start stop bootstrap enter clone + +REPO := https://github.com/jupyterhub/the-littlest-jupyterhub +PORT := -p 127.0.0.3:8080:80 +SOCK := -v /var/run/docker.sock:/var/run/docker.sock +CLIENT := -v /usr/bin/docker:/usr/bin/docker +SRCDIR := -v "$(CURDIR)/tljh:/srv/src" +NAME := tljh-dev +TAG := tljh:dev +EXISTS := $(shell docker inspect $(TAG) >/dev/null 2>&1 && echo YES || echo NO) +CONTID := $(shell docker ps -q -f 'NAME=$(NAME)' 2>/dev/null || true) + +help: ## Display this help message +ifeq ($(EXISTS),YES) + @echo "Docker image:" + @docker images $(TAG) +endif +ifneq ($(CONTID),) + @echo "Container:" + @docker ps -s -f 'ID=$(CONTID)' +endif + @echo "" + @echo "Usage:" + @sed -nE 's!^([^:]+):\s*##\s*(.+)\s*$$!\tmake \1\t- \2!p' Makefile + +clean: ## Remove the docker image and container + -docker rm -f $(NAME) + -docker rmi $(TAG) + +build: ## Build the 'hub' docker image + docker build --rm -t $(TAG) . + +start: ## Start the JupyterHub container + docker run --privileged --rm -d --name=$(NAME) $(PORT) $(SOCK) $(CLIENT) $(SRCDIR) $(TAG) + +stop: ## Stop and remove the container + docker rm -f $(NAME) + +bootstrap: ## Run the bootstrap script in the container + docker exec -ti -w /srv/src/bootstrap $(NAME) python3 ./bootstrap.py --admin dad:DadStuff + +enter: ## Open a shell in the container + docker exec -ti $(NAME) /bin/bash + +clone: ## Clone the repository + git clone --depth=1 $(REPO) tljh + +# vim:ai noet ts=8 sw=8 wm=0: diff --git a/README.md b/README.md new file mode 100644 index 0000000..34766bd --- /dev/null +++ b/README.md @@ -0,0 +1,40 @@ +# The Littlest Jupyter Hub +Run a TLJH installation in a docker container. + +## Build the image +Run: + +```sh +$ docker build -t tljh-dev . +``` + +Or, if you have `make` installed: + +```sh +$ make img +``` + +It'll download all its required dependencies during the build, it doesn't require anything from the context directory besides the `Dockerfile`. + + +## Start the container +Run the container: + +```sh +$ mkdir -p data +$ docker run -d --rm --name=tljh-dev -p 12000:80 --privileged tljh-dev +``` + +Or, again, if you have `make` installed: + +```sh +$ make start +``` + + +### TO-DO +These details still need to be worked out: + * Create a persistent mountpoint for all notebooks and custom configs + * Speed up startup, by creating the user-environment during build time instead of doing it during runtime + * Same as above for the systemd configuration (setting up services, 'daemon-reload', etc) + diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..62abb41 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,8 @@ +--- +version: '3' +services: + tljh-dev: + image: tljh-dev + ports: + - 127.0.0.1:1200:80 + restart: unless-stopped