diff --git a/Dockerfile b/Dockerfile index c20971d..3d10829 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,49 +1,63 @@ -FROM python:3.11-slim-bullseye AS build +FROM python:3.11-slim-bookworm AS build -# Install dependencies -RUN apt update && apt upgrade -y && apt install -y --no-install-recommends gettext p7zip-full python3-httpx libmpv-dev curl git-core && apt clean && rm -rf /var/lib/apt/lists/* +# Install build dependencies +RUN apt update && apt install -y --no-install-recommends \ + gettext \ + p7zip-full \ + python3-httpx \ + libmpv-dev \ + curl \ + git \ + && apt clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* + +# Create bot directory and user +RUN useradd -m -d /bot --system build -# Create build user and working directory -RUN useradd -d /bot --system build -RUN mkdir /bot && chown build:build /bot USER build - -# Download and extract PandoraBox.zip WORKDIR /bot -RUN curl -L -o PandoraBox.zip "https://git.techlabs.lol/radiant_code/teamtalkbot/archive/master.zip" -RUN 7z x PandoraBox.zip -o/bot/repo + +# Download and extract the bot source +RUN curl -L "https://git.techlabs.lol/radiant_code/teamtalkbot/archive/master.zip" -o PandoraBox.zip \ + && 7z x PandoraBox.zip -o/bot \ + && mv /bot/teamtalkbot /bot/repo \ + && rm PandoraBox.zip # Install Python dependencies and prepare bot WORKDIR /bot/repo -RUN pip install --no-cache-dir --upgrade -r requirements.txt -RUN python tools/ttsdk_downloader.py && python tools/compile_locales.py +RUN pip install --no-cache-dir --upgrade pip \ + && pip install --no-cache-dir -r requirements.txt \ + && python tools/ttsdk_downloader.py \ + && python tools/compile_locales.py \ + && chmod -R 0755 /bot/repo +# ---------------------------------------------------------------------------------- -# Set permissions for all files in /bot/repo -RUN chmod -R 0755 /bot/repo - -FROM python:3.11-slim-bullseye +FROM python:3.11-slim-bookworm # Install runtime dependencies -RUN apt update && apt upgrade -y && apt install -y --no-install-recommends libmpv-dev pulseaudio && apt clean && rm -rf /var/lib/apt/lists/* +RUN apt update && apt install -y --no-install-recommends \ + libmpv-dev \ + pulseaudio \ + && apt clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* -# Install yt-dlp with pip +# Install yt-dlp RUN pip install --no-cache-dir yt-dlp # Create runtime user RUN useradd --system -ms /bin/bash ttbot + USER ttbot - -# Set working directory and copy files WORKDIR /home/ttbot -COPY --from=build --chown=ttbot /bot/repo . -COPY --from=build --chown=ttbot /bot/.local ./.local -# Set permissions for all files in /home/ttbot +# Copy bot files from build stage +COPY --from=build --chown=ttbot:ttbot /bot/repo ./ +COPY --from=build --chown=ttbot:ttbot /bot/.local ./.local + +# Set permissions RUN chmod -R 0755 /home/ttbot -# Remove .git directory -RUN rm -rf .git +# Clean up unnecessary files +RUN rm -rf .git __pycache__ *.pyc *.pyo -# Command to run the bot +# Run the bot CMD ["sh", "-c", "rm -rf /tmp/* && pulseaudio --daemon --exit-idle-time=-1 && sleep 2 && ./TTMediaBot.sh -c data/config.json --cache data/TTMediaBotCache.dat --log data/TTMediaBot.log"]