From 57372772564dc5dc2c198075cd97828e08fccffd Mon Sep 17 00:00:00 2001 From: klmp200 Date: Sat, 12 Jun 2021 12:09:04 +0200 Subject: [PATCH] =?UTF-8?q?Bro=20c'est=20un=20gros=20baka=20qui=20ne=20sai?= =?UTF-8?q?s=20pas=20=C3=A9crire=20des=20docker?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++- Dockerfile | 33 +++++++++++++++++++++++++++++++++ entrypoint.sh | 20 ++++++++++++++++++++ ices.xml.jinja | 2 +- next_song.py | 15 ++++++++------- 5 files changed, 64 insertions(+), 9 deletions(-) create mode 100644 Dockerfile create mode 100755 entrypoint.sh diff --git a/.gitignore b/.gitignore index d684990..c86b351 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *~ -state.json \ No newline at end of file +state.json +*.xml \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2f00321 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,33 @@ +# docker build . -t radio-bullshit && docker run --rm -p 8000:8000 -v `pwd`/jingles:/jingles -v `pwd`/songs:/songs radio-bullshit +FROM python:3.9 + +ENV DEBIAN_FRONTEND=noninteractive +RUN apt-get update +RUN apt-get install -y icecast2 ices2 +RUN pip install jinja2 j2cli + +WORKDIR /config + +RUN adduser zambla + +COPY icecast.xml.jinja . +COPY ices.xml.jinja . + +COPY next_song.py /opt +COPY yt_sync.py /opt + +RUN chmod +x /opt/yt_sync.py /opt/next_song.py + +RUN mkdir -p /songs /jingles /var/log/icecast + +RUN chown -R zambla:zambla /config +RUN chown -R zambla:zambla /opt +RUN chown -R zambla:zambla /songs +RUN chown -R zambla:zambla /jingles +RUN chown -R zambla:zambla /var/log/icecast +RUN chown -R zambla:zambla /usr/share/icecast2 + +COPY entrypoint.sh /opt/entrypoint.sh +RUN chmod +x /opt/entrypoint.sh + +ENTRYPOINT [ "/opt/entrypoint.sh" ] \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..76e1c5d --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,20 @@ +#!/bin/bash -e + +export hostname=${HOSTNAME:=localhost} +export port=${PORT:=8000} +export max_listeners=${MAX_LISTENERS:=30} +export admin_user=${ADMIN_USER:=admin} +export admin_password=${ADMIN_PASSWORD:=admin} + +pass_gen="python3 -c 'import secrets, string; print(\"\".join((secrets.choice(string.ascii_letters + string.digits) for i in range(20))))'" + +export source_username=$(eval $pass_gen) +export source_password=$(eval $pass_gen) + +pip install youtube-dl + +j2 ices.xml.jinja > ices.xml +j2 icecast.xml.jinja > icecast.xml + +runuser -l zambla -c 'icecast2 -c /config/icecast.xml &' +runuser -l zambla -c 'ices2 /config/ices.xml' diff --git a/ices.xml.jinja b/ices.xml.jinja index 955bf13..d0bb972 100644 --- a/ices.xml.jinja +++ b/ices.xml.jinja @@ -9,7 +9,7 @@ script - next_song.py + /opt/next_song.py {{ source_username }} diff --git a/next_song.py b/next_song.py index b9d5085..aa5dd60 100755 --- a/next_song.py +++ b/next_song.py @@ -4,25 +4,26 @@ import random, glob, os, json if __name__ == "__main__": - script_dir = os.path.dirname(os.path.abspath(__file__)) + songs_folder = "/songs" + jingles_folder = "/jingles" - if not os.path.isfile(f"{script_dir}/state.json"): + if not os.path.isfile(f"{songs_folder}/state.json"): # create state file if it doesnt exist - with open(f"{script_dir}/state.json", "w") as f: + with open(f"{songs_folder}/state.json", "w") as f: state = {"current_song_type": "jingle"} json.dump(state, f, indent=4) else: - with open(f"{script_dir}/state.json") as f: + with open(f"{songs_folder}/state.json") as f: state = json.load(f) if state["current_song_type"] == "song": state["current_song_type"] = "jingle" - print(random.choice(glob.glob(f"{script_dir}/jingles/*.ogg"))) + print(random.choice(glob.glob(f"{jingles_folder}/*.ogg"))) elif state["current_song_type"] == "jingle": state["current_song_type"] = "song" - print(random.choice(glob.glob(f"{script_dir}/songs/*.ogg"))) + print(random.choice(glob.glob(f"{songs_folder}/*.ogg"))) else: exit(1) - with open(f"{script_dir}/state.json", "w") as f: + with open(f"{songs_folder}/state.json", "w") as f: json.dump(state, f, indent=4)