From 5b0bb2517733b235ba0565e63b5f15a557e2eefd Mon Sep 17 00:00:00 2001 From: Maxim Vershinin Date: Wed, 29 Jul 2026 20:05:17 +0500 Subject: [PATCH] Test docker image, basic functionality --- .dockerignore | 40 ++++++++++++++++++++++++++++++++++ Dockerfile | 51 ++++++++++++++++++++++++++++++++++++++++++++ docker-entrypoint.sh | 17 +++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100755 docker-entrypoint.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..e095cb7 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,40 @@ +# Git +.git/ +.gitignore + +# Python cache +*.pyc +__pycache__/ +*.pyo +*.pyd + +# Build artifacts +build/ +dist/ +*.egg-info/ +.eggs/ + +# Virtual environments +.venv +venv/ +env/ +ENV/ + +# IDE +.vscode/ +.idea/ +*.swp + +# License (not needed for installation) +LICENSE + +# Docker files (not needed in build context) +Dockerfile +.dockerignore + +# Local test files +*.mp3 +*.flac +*.wav +*.txt +*.log diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0a369c5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,51 @@ +FROM python:3.13-slim + +# Install FFmpeg and dependencies (gosu will be downloaded separately) +RUN apt-get update && \ + apt-get install -y --no-install-recommends ffmpeg ca-certificates wget gpg && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# Install gosu (lightweight tool for dropping privileges) +RUN set -eux; \ + dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')"; \ + wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/1.17/gosu-$dpkgArch"; \ + wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/1.17/gosu-$dpkgArch.asc"; \ + export GNUPGHOME="$(mktemp -d)"; \ + gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; \ + gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \ + gpgconf --kill all; \ + rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc; \ + chmod +x /usr/local/bin/gosu; \ + gosu --version + +# Set Python environment variables +ENV PYTHONDONTWRITEBYTECODE=1 \ + PYTHONUNBUFFERED=1 + +# Set working directory +WORKDIR /app + +# Copy package metadata and source code +COPY setup.py pyproject.toml README.md ./ +COPY audio_splitter/ ./audio_splitter/ + +# Install the package +RUN pip install --no-cache-dir . + +# Create a non-root user with UID 1000 +RUN addgroup --system --gid 1000 appgroup && \ + adduser --system --uid 1000 --ingroup appgroup appuser + +# Change ownership of /app to the container user (so it can write there if needed) +RUN chown -R appuser:appgroup /app + +# Copy the entrypoint script +COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh +RUN chmod +x /usr/local/bin/docker-entrypoint.sh + +# Set the entrypoint +ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"] + +# Default command (shows help if no arguments) +CMD ["audio_splitter", "--help"] diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100755 index 0000000..34edfa6 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,17 @@ +#!/bin/bash +set -e + +# Check if we are running as root (default) +if [ "$(id -u)" = "0" ]; then + # If /data is a directory, change its ownership to the container user + if [ -d "/data" ]; then + echo "Setting ownership of /data to appuser:appgroup" + chown -R appuser:appgroup /data + fi + + # Drop privileges and run the command using gosu + exec gosu appuser "$@" +else + # If not root, just run the command directly + exec "$@" +fi