diff --git a/.dockerignore b/.dockerignore new file mode 100755 index 00000000..e0cc78f0 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,27 @@ +**/__pycache__ +**/.venv +**/.classpath +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/bin +**/charts +**/docker-compose* +**/compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +LICENSE +README.md diff --git a/.gitattributes b/.gitattributes old mode 100644 new mode 100755 diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 index 9f2e8485..745920a6 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ .DS_Store __pycache__/ +**/__pycache__/ +.vscode/launch.json +.vscode/tasks.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100755 index 00000000..16d04702 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "docker.imageBuildContextPath": "${workspaceFolder}" + //"docker.imageBuildContextPath": "/MainPool/Main/Vital_Data/Scripts/Dispatcharr/Dispatcharr" + +} \ No newline at end of file diff --git a/docker/DockerfileAIO b/docker/DockerfileAIO new file mode 100755 index 00000000..fa9fa40a --- /dev/null +++ b/docker/DockerfileAIO @@ -0,0 +1,45 @@ +FROM python:3.10-slim + +# Add PostgreSQL repository +RUN apt-get update && apt-get install -y wget gnupg2 && \ + echo "deb http://apt.postgresql.org/pub/repos/apt/ bookworm-pgdg main" > /etc/apt/sources.list.d/pgdg.list && \ + wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - + +# Install required packages +RUN apt-get update && apt-get install -y \ + ffmpeg \ + streamlink \ + vlc \ + libpq-dev \ + gcc \ + postgresql-14 \ + postgresql-contrib-14 \ + redis-server \ + && rm -rf /var/lib/apt/lists/* + +# Set the working directory +WORKDIR /app + +# Copy requirements.txt from the parent directory +COPY requirements.txt /app/ + +# Install Python dependencies +RUN pip install --no-cache-dir -r /app/requirements.txt + +# Copy the application source code from the parent directory +COPY . /app/ + +# Set environment variables +ENV DJANGO_SETTINGS_MODULE=dispatcharr.settings +ENV PYTHONUNBUFFERED=1 +ENV SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt + +# Copy the entrypoint script +COPY docker/entrypoint.sh /app/entrypoint.sh +RUN chmod +x /app/entrypoint.sh + +# Expose the port +EXPOSE 9191 + +# Command to run the startup script +CMD ["/app/entrypoint.sh"] diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh new file mode 100755 index 00000000..a4979bff --- /dev/null +++ b/docker/entrypoint.sh @@ -0,0 +1,87 @@ +#!/bin/sh + +# Set PostgreSQL environment variables +export POSTGRES_DB=${POSTGRES_DB:-dispatcharr} +export POSTGRES_USER=${POSTGRES_USER:-dispatch} +export POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-secret} +export POSTGRES_HOST=${POSTGRES_HOST:-localhost} +export POSTGRES_PORT=${POSTGRES_PORT:-5432} +export PGDATA=${PGDATA:-/app/data/db} +export PG_BINDIR="/usr/lib/postgresql/14/bin" + +# Echo environment variables for debugging +echo "POSTGRES_DB: $POSTGRES_DB" +echo "POSTGRES_USER: $POSTGRES_USER" +echo "POSTGRES_PASSWORD: $POSTGRES_PASSWORD" +echo "POSTGRES_HOST: $POSTGRES_HOST" +echo "POSTGRES_PORT: $POSTGRES_PORT" + +# Create group if it doesn't exist +if ! getent group "$PGID" >/dev/null 2>&1; then + groupadd -g "$PGID" mygroup +fi +# Create user if it doesn't exist +if ! getent passwd $PUID > /dev/null 2>&1; then + useradd -u $PUID -g $PGID -m $POSTGRES_USER +else + existing_user=$(getent passwd $PUID | cut -d: -f1) + if [ "$existing_user" != "$POSTGRES_USER" ]; then + usermod -l $POSTGRES_USER -g $PGID "$existing_user" + fi +fi + +# Initialize PostgreSQL database +if [ -z "$(ls -A "$PGDATA")" ]; then + echo "Initializing PostgreSQL database..." + mkdir -p "$PGDATA" + chown -R postgres:postgres "$PGDATA" + chmod 700 "$PGDATA" + + # Initialize PostgreSQL + su - postgres -c "$PG_BINDIR/initdb -D $PGDATA" + # Configure PostgreSQL + echo "host all all 0.0.0.0/0 md5" >> "$PGDATA/pg_hba.conf" + echo "listen_addresses='*'" >> "$PGDATA/postgresql.conf" + +fi + +# Start PostgreSQL +su - postgres -c "$PG_BINDIR/pg_ctl -D $PGDATA start -w -t 300 -o '-c port=${POSTGRES_PORT}'" + +# Wait for PostgreSQL to be ready +until su - postgres -c "$PG_BINDIR/pg_isready -h ${POSTGRES_HOST} -p ${POSTGRES_PORT}" >/dev/null 2>&1; do + echo "Waiting for PostgreSQL to be ready..." + sleep 1 +done + +# Setup database if needed +if ! su - postgres -c "psql -p ${POSTGRES_PORT} -tAc \"SELECT 1 FROM pg_database WHERE datname = '$POSTGRES_DB';\"" | grep -q 1; then + # Create PostgreSQL database + su - postgres -c "createdb -p ${POSTGRES_PORT} ${POSTGRES_DB}" + + # Create user, set ownership, and grant privileges + su - postgres -c "psql -p ${POSTGRES_PORT} -d ${POSTGRES_DB}" <