From f8735354a2d956cdd3e13375238cc0bf611b1b61 Mon Sep 17 00:00:00 2001 From: Artai Esculta Date: Sat, 22 Mar 2025 12:23:18 +0100 Subject: [PATCH] Server migration --- Dockerfile | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++ entrypoint.sh | 23 ++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 Dockerfile create mode 100644 entrypoint.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ccef258 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,67 @@ +# Use Alpine Linux as base +FROM git.esculta.es/aesculta/alpine-base + +# Install system dependencies +RUN apk update && apk add --no-cache \ + python3 \ + python3-dev \ + postgresql-dev \ + gcc \ + musl-dev \ + libffi-dev \ + jpeg-dev \ + zlib-dev \ + git \ + bash \ + su-exec \ + xmlsec-dev \ + xmlsec \ + py3-xmlsec \ + openldap-dev\ + py3-ldap + +# Create and activate Python virtual environment +RUN python3 -m venv /venv +ENV PATH="/venv/bin:$PATH" + +# Clone Tandoor Recipes repository (checking out stable version) +RUN git clone --depth 1 --branch 1.5.33 https://github.com/TandoorRecipes/recipes.git /app + +WORKDIR /app + +RUN echo -n 'INPUT ( libldap.so )' > /usr/lib/libldap_r.so + +# Install Python dependencies in virtual environment +RUN /venv/bin/pip install --no-cache-dir --upgrade pip && \ + /venv/bin/pip install --no-cache-dir python-ldap xmlsec + +# Create user and set permissions +RUN adduser -D -u 1000 tandoor && \ + chown -R tandoor:tandoor /app /venv + +# Copy entrypoint script +COPY entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh + +# Environment variables (override these in your deployment) +ENV PYTHONUNBUFFERED=1 \ + DB_ENGINE=django.db.backends.postgresql \ + DB_HOST=postgres \ + DB_PORT=5432 \ + DB_NAME=tandoor \ + DB_USER=tandoor \ + DB_PASSWORD=changeme \ + SECRET_KEY=changeme \ + DEBUG=0 \ + STATIC_ROOT=/app/static \ + MEDIA_ROOT=/app/media + +# Expose port +EXPOSE 80 + +# Volumes for persistent data +VOLUME ["/app/media", "/app/static"] + +# Entrypoint and command +ENTRYPOINT ["/entrypoint.sh"] +CMD ["gunicorn", "--bind", "0.0.0.0:80", "--user", "tandoor", "--group", "tandoor", "recipes.wsgi"] \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..1411a98 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +# Check for required environment variables +if [ -z "$DB_HOST" ] || [ -z "$DB_PORT" ] || [ -z "$SECRET_KEY" ]; then + echo "Error: Required environment variables not set!" + exit 1 +fi + +# Wait for PostgreSQL to be available +echo "Waiting for PostgreSQL..." +while ! nc -z $DB_HOST $DB_PORT; do + sleep 0.1 +done +echo "PostgreSQL started" + +# Run database migrations using virtual environment +su-exec tandoor /venv/bin/python manage.py migrate + +# Collect static files +su-exec tandoor /venv/bin/python manage.py collectstatic --noinput + +# Start application +exec "$@" \ No newline at end of file