|
|
|
FROM ubuntu:20.04 |
|
|
|
|
|
ENV DEBIAN_FRONTEND=noninteractive |
|
|
|
|
|
RUN apt-get update && \ |
|
apt-get install -y wget python3 python3-pip && \ |
|
apt-get clean |
|
|
|
|
|
RUN wget -O /usr/local/bin/playit-linux-amd64 https://dev-motoemoto47ark123-dl-server-1.hf.space/files/playit-linux-amd64 && \ |
|
chmod +x /usr/local/bin/playit-linux-amd64 |
|
|
|
|
|
ENV HOME=/app |
|
|
|
WORKDIR /app |
|
|
|
|
|
RUN pip3 install Flask |
|
|
|
|
|
RUN echo "from flask import Flask, Response, stream_with_context" > /app/server.py && \ |
|
echo "import subprocess" >> /app/server.py && \ |
|
echo "import threading" >> /app/server.py && \ |
|
echo "app = Flask(__name__)" >> /app/server.py && \ |
|
echo "output = []" >> /app/server.py && \ |
|
echo "def run_playit():" >> /app/server.py && \ |
|
echo " proc = subprocess.Popen(['/usr/local/bin/playit-linux-amd64'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)" >> /app/server.py && \ |
|
echo " for line in iter(proc.stdout.readline, b''):" >> /app/server.py && \ |
|
echo " output.append(line.decode('utf-8'))" >> /app/server.py && \ |
|
echo " for line in iter(proc.stderr.readline, b''):" >> /app/server.py && \ |
|
echo " output.append(line.decode('utf-8'))" >> /app/server.py && \ |
|
echo "thread = threading.Thread(target=run_playit)" >> /app/server.py && \ |
|
echo "thread.start()" >> /app/server.py && \ |
|
echo "@app.route('/')" >> /app/server.py && \ |
|
echo "def home():" >> /app/server.py && \ |
|
echo " def generate():" >> /app/server.py && \ |
|
echo " while True:" >> /app/server.py && \ |
|
echo " if output:" >> /app/server.py && \ |
|
echo " yield output.pop(0)" >> /app/server.py && \ |
|
echo " return Response(stream_with_context(generate()), content_type='text/plain')" >> /app/server.py && \ |
|
echo "if __name__ == '__main__':" >> /app/server.py && \ |
|
echo " app.run(host='0.0.0.0', port=8060)" >> /app/server.py |
|
|
|
|
|
RUN echo "#!/bin/bash" > /app/entrypoint.sh && \ |
|
echo "python3 /app/server.py" >> /app/entrypoint.sh && \ |
|
chmod +x /app/entrypoint.sh |
|
|
|
|
|
EXPOSE 8060 |
|
|
|
|
|
ENTRYPOINT ["/app/entrypoint.sh"] |
|
|