diff --git a/images/fetch-course-emails/Dockerfile b/images/fetch-course-emails/Dockerfile index 0fe097e2..939af1d7 100644 --- a/images/fetch-course-emails/Dockerfile +++ b/images/fetch-course-emails/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:19.04 +FROM ubuntu:20.04 RUN apt-get update && \ apt-get install -y --no-install-recommends \ @@ -15,5 +15,6 @@ ADD requirements.txt /tmp/requirements.txt RUN pip3 install --no-cache-dir -r /tmp/requirements.txt ADD course-emails.py /usr/local/bin/ +ADD save-course-emails.sh /usr/local/bin/ -CMD ["/usr/local/bin/course-emails.py", "-v"] +CMD ["/usr/local/bin/save-course-emails.sh"] diff --git a/images/fetch-course-emails/requirements.txt b/images/fetch-course-emails/requirements.txt index 0b8af2e5..de1cb65b 100644 --- a/images/fetch-course-emails/requirements.txt +++ b/images/fetch-course-emails/requirements.txt @@ -1,4 +1,5 @@ -aiohttp==3.5.4 -ruamel.yaml==0.16.0 +aiohttp==3.7.3 +ruamel.yaml==0.16.12 +yq==2.12.0 git+https://github.com/ryanlovett/sis-cli.git@1635650 git+https://github.com/ryanlovett/ucbhr.git@48975fb diff --git a/images/fetch-course-emails/save-course-emails.sh b/images/fetch-course-emails/save-course-emails.sh new file mode 100755 index 00000000..d0d9645f --- /dev/null +++ b/images/fetch-course-emails/save-course-emails.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +# set -e + +# all hub configuration +config_values="/etc/jupyterhub/config/values.yaml" + +# output location +profile_dir="/srv/jupyterhub/profiles.d" + +course_emails="/usr/local/bin/course-emails.py" + +# space 24 hours apart; TODO: guessing k8s can loop this for us somehow +sleep_time=86400 + +while true ; do + + if [ ! -f $custom_profiles ]; then + echo "No such file: $custom_profiles" + else + + if [ ! -d $profile_dir ]; then mkdir -p $profile_dir ; fi + + profiles=`cat ${config_values} | yq .custom.profiles | jq -r 'keys[]'` + echo profiles: ${profiles} + + # write out email lists for each profile + for profile in ${profiles} ; do + for people in students instructors ; do + filename="${profile_dir}/${profile}-${people}.txt" + # write to tempfile because gathering addresses takes time + # and we don't want the hub to read an abbreviated list + outfile=`mktemp` + echo $profile $people $outfile + $course_emails $profile $people > $outfile + if [ -f $outfile ]; then mv $outfile $filename ; fi + done + done + fi + + sleep $sleep_time +done