Bro c'est un gros baka qui ne sais pas écrire des docker
This commit is contained in:
parent
a9b4198f93
commit
5737277256
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
*~
|
||||
state.json
|
||||
state.json
|
||||
*.xml
|
33
Dockerfile
Normal file
33
Dockerfile
Normal file
@ -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" ]
|
20
entrypoint.sh
Executable file
20
entrypoint.sh
Executable file
@ -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'
|
@ -9,7 +9,7 @@
|
||||
</metadata>
|
||||
<input>
|
||||
<param name="type">script</param>
|
||||
<param name="program">next_song.py</param>
|
||||
<param name="program">/opt/next_song.py</param>
|
||||
</input>
|
||||
<instance>
|
||||
<username>{{ source_username }}</username>
|
||||
|
15
next_song.py
15
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)
|
||||
|
Loading…
Reference in New Issue
Block a user