Skip to content
This repository has been archived by the owner on Apr 29, 2021. It is now read-only.

Commit

Permalink
Merge pull request #69 from NERSC/19-09
Browse files Browse the repository at this point in the history
19 09
  • Loading branch information
rcthomas authored Sep 28, 2019
2 parents ffb1549 + 1718110 commit d0046ad
Show file tree
Hide file tree
Showing 25 changed files with 499 additions and 18 deletions.
3 changes: 1 addition & 2 deletions jupyter-compose/app-notebooks/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ RUN \
jupyter nbextension enable --sys-prefix --py widgetsnbextension

RUN \
jupyter labextension install @jupyterlab/hub-extension && \
conda install jupyterhub
jupyter labextension install @jupyterlab/hub-extension

# Some dummy users

Expand Down
8 changes: 8 additions & 0 deletions jupyter-compose/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@ services:
image: web-jupyterhub:latest
environment:
- CONFIGPROXY_AUTH_TOKEN=the-sign-pointed-this-way
- ANNOUNCEMENT_JUPYTERHUB_API_TOKEN=the-hands-of-fate-have-doomed-this-man
volumes:
- ./config:/config
ports:
- 8081:8081
app:
image: app-notebooks:latest
volumes:
- ./config:/config
announcement:
image: web-announcement:latest
environment:
- JUPYTERHUB_API_TOKEN=the-hands-of-fate-have-doomed-this-man
- JUPYTERHUB_API_URL=http://web:8081/hub/api
proxy:
image: jupyterhub/configurable-http-proxy:latest
environment:
Expand Down
14 changes: 14 additions & 0 deletions jupyter-compose/web-announcement/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ARG branch=unknown

FROM registry.spin.nersc.gov/das/jupyter-base-${branch}:latest
LABEL maintainer="Rollin Thomas <rcthomas@lbl.gov>"

RUN \
pip install git+https://github.com/rcthomas/jupyterhub-announcement.git@persist-announcements

WORKDIR /srv

ADD docker-entrypoint.sh announcement_config.py ./
RUN chmod +x docker-entrypoint.sh
ENTRYPOINT ["./docker-entrypoint.sh"]
CMD ["python", "-m", "jupyterhub_announcement"]
72 changes: 72 additions & 0 deletions jupyter-compose/web-announcement/announcement_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Configuration file for application.

#------------------------------------------------------------------------------
# Application(SingletonConfigurable) configuration
#------------------------------------------------------------------------------

## This is an application.

## The date format used by logging formatters for %(asctime)s
#c.Application.log_datefmt = '%Y-%m-%d %H:%M:%S'

## The Logging format template
#c.Application.log_format = '[%(name)s]%(highlevel)s %(message)s'

## Set the log level by value or name.
#c.Application.log_level = 30
c.Application.log_level = 0

#------------------------------------------------------------------------------
# AnnouncementService(Application) configuration
#------------------------------------------------------------------------------

## This is an application.

## Config file to load
#c.AnnouncementService.config_file = 'announcement_config.py'

## Fixed message to show at the top of the page.
#
# A good use for this parameter would be a link to a more general live system
# status page or MOTD.
#c.AnnouncementService.fixed_message = ''

## Generate default config file
#c.AnnouncementService.generate_config = False

## Logo path, can be used to override JupyterHub one
#c.AnnouncementService.logo_file = ''

## Port this service will listen on
#c.AnnouncementService.port = 8888

## Announcement service prefix
#c.AnnouncementService.service_prefix = '/services/announcement/'

## Search paths for jinja templates, coming before default ones
#c.AnnouncementService.template_paths = []

#------------------------------------------------------------------------------
# AnnouncementQueue(LoggingConfigurable) configuration
#------------------------------------------------------------------------------

## File path where announcements persist as JSON.
#
# For a persistent announcement queue, this parameter must be set to a non-empty
# value and correspond to a read+write-accessible path. The announcement queue
# is stored as a list of JSON objects. If this parameter is set to a non-empty
# value:
#
# * The persistence file is used to initialize the announcement queue
# at start-up. This is the only time the persistence file is read.
# * If the persistence file does not exist at start-up, it is
# created when an announcement is added to the queue.
# * The persistence file is over-written with the contents of the
# announcement queue each time a new announcement is added.
#
# If this parameter is set to an empty value (the default) then the queue is
# just empty at initialization and the queue is ephemeral; announcements will
# not be persisted on updates to the queue.
#c.AnnouncementQueue.persist_path = ''
c.AnnouncementQueue.persist_path = 'announcements.json'

8 changes: 8 additions & 0 deletions jupyter-compose/web-announcement/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

branch=$(git symbolic-ref --short HEAD)

docker build \
--build-arg branch=$branch \
"$@" \
--tag web-announcement:latest .
28 changes: 28 additions & 0 deletions jupyter-compose/web-announcement/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

# file_env VAR [DEFAULT]
# ----------------------
# Treat the value of VAR_FILE as the path to a secrets file and initialize VAR
# with the contents of that file. From postgres docker-entrypoint.sh.

file_env() {
local var="$1"
local fileVar="${var}_FILE"
local def="${2:-}"
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
exit 1
fi
local val="$def"
if [ "${!var:-}" ]; then
val="${!var}"
elif [ "${!fileVar:-}" ]; then
val="$(< "${!fileVar}")"
fi
export "$var"="$val"
unset "$fileVar"
}

file_env 'JUPYTERHUB_API_TOKEN'

exec "$@"
1 change: 1 addition & 0 deletions jupyter-compose/web-jupyterhub/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ RUN \
WORKDIR /srv
ADD docker-entrypoint.sh .
ADD jupyterhub_config.py .
ADD templates templates
RUN chmod +x docker-entrypoint.sh
RUN echo "StrictHostKeyChecking no" >> /etc/ssh/ssh_config

Expand Down
9 changes: 9 additions & 0 deletions jupyter-compose/web-jupyterhub/jupyterhub_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,14 @@
# }
# ]
#c.JupyterHub.services = []
import os
c.JupyterHub.services = [
{
'name': 'announcement',
'url': 'http://announcement:8888',
'api_token': os.environ["ANNOUNCEMENT_JUPYTERHUB_API_TOKEN"]
}
]

## Shuts down all user servers on logout
#c.JupyterHub.shutdown_on_logout = False
Expand Down Expand Up @@ -483,6 +491,7 @@

## Paths to search for jinja templates, before using the default templates.
#c.JupyterHub.template_paths = []
c.JupyterHub.template_paths = ["./templates"]

## Extra variables to be passed into jinja templates
#c.JupyterHub.template_vars = {}
Expand Down
24 changes: 24 additions & 0 deletions jupyter-compose/web-jupyterhub/templates/page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{% extends "templates/page.html" %}
{% block announcement %}
<div class="container announcement">
</div>
{% endblock %}

{% block script %}
{{ super() }}
<script>
$.get("/services/announcement/latest", function(data) {
var announcement = data["announcement"];
if(announcement) {
$(".announcement").html(`<div class="panel panel-warning">
<div class="panel-heading">
<h3 class="panel-title">Announcement</h3>
</div>
<div class="panel-body text-center announcement">
${announcement}
</div>
</div>`);
}
});
</script>
{% endblock %}
4 changes: 4 additions & 0 deletions jupyter-localhost/web-jupyterhub/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ RUN \
adduser -q --gecos "" --disabled-password master && \
echo master:you-have-failed-us-torgo | chpasswd

RUN \
pip install --no-cache-dir git+https://github.com/rcthomas/jupyterhub-announcement.git@persist-announcements

WORKDIR /srv
ADD announcement_config.py .
RUN chmod +x docker-entrypoint.sh
CMD ["jupyterhub", "--debug"]
ENTRYPOINT ["./docker-entrypoint.sh"]
72 changes: 72 additions & 0 deletions jupyter-localhost/web-jupyterhub/announcement_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Configuration file for application.

#------------------------------------------------------------------------------
# Application(SingletonConfigurable) configuration
#------------------------------------------------------------------------------

## This is an application.

## The date format used by logging formatters for %(asctime)s
#c.Application.log_datefmt = '%Y-%m-%d %H:%M:%S'

## The Logging format template
#c.Application.log_format = '[%(name)s]%(highlevel)s %(message)s'

## Set the log level by value or name.
#c.Application.log_level = 30
c.AnnouncementService.log_level = 0

#------------------------------------------------------------------------------
# AnnouncementService(Application) configuration
#------------------------------------------------------------------------------

## This is an application.

## Config file to load
#c.AnnouncementService.config_file = 'announcement_config.py'

## Fixed message to show at the top of the page.
#
# A good use for this parameter would be a link to a more general live system
# status page or MOTD.
#c.AnnouncementService.fixed_message = ''

## Generate default config file
#c.AnnouncementService.generate_config = False

## Logo path, can be used to override JupyterHub one
#c.AnnouncementService.logo_file = ''

## Port this service will listen on
#c.AnnouncementService.port = 8888

## Announcement service prefix
#c.AnnouncementService.service_prefix = '/services/announcement/'

## Search paths for jinja templates, coming before default ones
#c.AnnouncementService.template_paths = []

#------------------------------------------------------------------------------
# AnnouncementQueue(LoggingConfigurable) configuration
#------------------------------------------------------------------------------

## File path where announcements persist as JSON.
#
# For a persistent announcement queue, this parameter must be set to a non-empty
# value and correspond to a read+write-accessible path. The announcement queue
# is stored as a list of JSON objects. If this parameter is set to a non-empty
# value:
#
# * The persistence file is used to initialize the announcement queue
# at start-up. This is the only time the persistence file is read.
# * If the persistence file does not exist at start-up, it is
# created when an announcement is added to the queue.
# * The persistence file is over-written with the contents of the
# announcement queue each time a new announcement is added.
#
# If this parameter is set to an empty value (the default) then the queue is
# just empty at initialization and the queue is ephemeral; announcements will
# not be persisted on updates to the queue.
#c.AnnouncementQueue.persist_path = ''
c.AnnouncementQueue.persist_path = 'announcements.json'

9 changes: 9 additions & 0 deletions jupyter-localhost/web-jupyterhub/jupyterhub_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,15 @@
# }
# ]
#c.JupyterHub.services = []
import os
c.JupyterHub.services = [
{
'name': 'announcement',
'url': 'http://127.0.0.1:8888',
'command': ["python", "-m", "jupyterhub_announcement"]
# 'api_token': os.environ["ANNOUNCEMENT_JUPYTERHUB_API_TOKEN"]
}
]

## The class to use for spawning single-user servers.
#
Expand Down
9 changes: 7 additions & 2 deletions jupyter-nersc/app-notebooks/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,13 @@ RUN \

RUN \
pip install --no-cache-dir ipympl && \
jupyter nbextension enable --sys-prefix --py widgetsnbextension && \
jupyter labextension install \
jupyter nbextension enable --sys-prefix --py widgetsnbextension

RUN \
conda install --yes -c conda-forge nodejs

RUN \
jupyter labextension install --debug \
@jupyter-widgets/jupyterlab-manager \
jupyter-matplotlib \
@jupyterlab/toc \
Expand Down
14 changes: 14 additions & 0 deletions jupyter-nersc/web-announcement/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ARG branch=unknown

FROM registry.spin.nersc.gov/das/jupyter-base-${branch}:latest
LABEL maintainer="Rollin Thomas <rcthomas@lbl.gov>"

RUN \
pip install git+https://github.com/rcthomas/jupyterhub-announcement.git@persist-announcements

WORKDIR /srv

ADD docker-entrypoint.sh announcement_config.py ./
RUN chmod +x docker-entrypoint.sh
ENTRYPOINT ["./docker-entrypoint.sh"]
CMD ["python", "-m", "jupyterhub_announcement"]
Loading

0 comments on commit d0046ad

Please sign in to comment.