temp6 / Dockerfile
motoe moto
Create Dockerfile
7fd9432 verified
raw
history blame contribute delete
No virus
2.48 kB
# Use an official Ubuntu as a parent image
FROM ubuntu:20.04
# Set environment variables to avoid user interaction during installation
ENV DEBIAN_FRONTEND=noninteractive
# Update and install necessary packages
RUN apt-get update && \
apt-get install -y wget python3 python3-pip && \
apt-get clean
# Download the playit-linux-amd64 file
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
# Set home to the /app directory
ENV HOME=/app
WORKDIR /app
# Install Flask
RUN pip3 install Flask
# Create a Python script for the HTTP server and playit process
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
# Create the entrypoint script
RUN echo "#!/bin/bash" > /app/entrypoint.sh && \
echo "python3 /app/server.py" >> /app/entrypoint.sh && \
chmod +x /app/entrypoint.sh
# Expose the Python server port
EXPOSE 8060
# Set entry point
ENTRYPOINT ["/app/entrypoint.sh"]