From 5dd5390fac6595432213169524d400e73b81b869 Mon Sep 17 00:00:00 2001 From: Roy Olav Purser Date: Wed, 19 May 2021 10:40:18 +0200 Subject: [PATCH] use pip for python dependencies --- Dockerfile | 30 ++++++++++++++++++++---------- backend/install.sh | 5 +++++ sources.py => backend/sources.py | 3 +-- backend/start.sh | 3 +++ stream.py => backend/stream.py | 0 5 files changed, 29 insertions(+), 12 deletions(-) create mode 100644 backend/install.sh rename sources.py => backend/sources.py (97%) create mode 100644 backend/start.sh rename stream.py => backend/stream.py (100%) diff --git a/Dockerfile b/Dockerfile index 6f5738e..fdfbda0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,20 +1,30 @@ FROM alpine:edge as base -RUN ["apk", "add", "--no-cache", "--repository", "https://dl-cdn.alpinelinux.org/alpine/edge/testing", "streamlink", "py3-tornado", "py3-aiohttp", "py3-aiohttp-socks"] -RUN ["mkdir", "/app"] -COPY ["stream.py", "/app/stream.py"] -COPY ["sources.py", "/app/sources.py"] +RUN ["apk", "add", "--no-cache", "py3-virtualenv"] +RUN ["mkdir", "-p", "/app"] +COPY ["tv.json", "/app/setup/tv.json"] +COPY ["backend/start.sh", "/app/start.sh"] +COPY ["backend/install.sh", "/app/setup/install.sh"] +COPY ["backend/sources.py", "/app/setup/sources.py"] +COPY ["backend/stream.py", "/app/stream.py"] COPY ["frontend/index.html", "/app/index.html"] COPY ["frontend/script.js", "/app/script.js"] COPY ["frontend/style.css", "/app/style.css"] RUN ["chmod", "-R", "755", "/app"] -COPY ["tv.json", "/app/tv.json"] -RUN ["python3", "/app/sources.py"] -RUN ["rm", "/app/tv.json"] -RUN ["rm", "/app/sources.py"] + +FROM base as sources +RUN ["apk", "add", "--no-cache", "py3-requests"] +RUN ["python3", "/app/setup/sources.py"] +RUN ["rm", "-r", "/app/setup"] + +FROM base as venv +RUN ["apk", "add", "--no-cache", "musl-dev", "build-base", "python3-dev"] +RUN ["/app/setup/install.sh"] +RUN ["rm", "-r", "/app/setup"] FROM scratch -COPY --from=base / / +COPY --from=sources / / +COPY --from=venv /app/venv /app/venv USER 1444:1444 ENV ICECAST_SERVER=https://icecast.purser.it:7000 ENV STREAM_SERVER=https://stream.purser.it -ENTRYPOINT ["/app/stream.py"] +ENTRYPOINT ["/app/start.sh"] diff --git a/backend/install.sh b/backend/install.sh new file mode 100644 index 0000000..b556bbe --- /dev/null +++ b/backend/install.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env sh +virtualenv --python=$(which python3) /app/venv +source /app/venv/bin/activate +pip install --upgrade pip +pip install --upgrade streamlink tornado aiohttp aiohttp-socks diff --git a/sources.py b/backend/sources.py similarity index 97% rename from sources.py rename to backend/sources.py index 6debf09..c62f05d 100755 --- a/sources.py +++ b/backend/sources.py @@ -25,11 +25,10 @@ else: playlist[mount_name] = value if playlist is not None: - with open("/app/tv.json", "r") as f: + with open("/app/setup/tv.json", "r") as f: tv = json.loads(f.read()) for name in tv: playlist[name] = tv[name] - with open("/app/sources.json", "w+") as f: f.write(json.dumps(playlist)) try: diff --git a/backend/start.sh b/backend/start.sh new file mode 100644 index 0000000..1f5ea08 --- /dev/null +++ b/backend/start.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env sh +source /app/venv/bin/activate +exec /app/stream.py diff --git a/stream.py b/backend/stream.py similarity index 100% rename from stream.py rename to backend/stream.py