From 89661aa4b97af0c22ac484030e8a319691ea99d6 Mon Sep 17 00:00:00 2001 From: Irwan Cahyono Date: Thu, 7 Aug 2025 09:24:08 +0700 Subject: [PATCH] update docker --- freekake_api/.gitignore | 2 ++ freekake_api/Dockerfile | 37 +++++++++++++++++++++++-------------- freekake_api/entrypoint.sh | 13 +++++++++++++ 3 files changed, 38 insertions(+), 14 deletions(-) create mode 100644 freekake_api/entrypoint.sh diff --git a/freekake_api/.gitignore b/freekake_api/.gitignore index 101f69b..eb1acc1 100644 --- a/freekake_api/.gitignore +++ b/freekake_api/.gitignore @@ -71,6 +71,8 @@ media/ staticfiles/ # Migrations (optional, keep *.py if you want to version control) +**/migrations/*.py +**/migrations/__init__.py **/migrations/*.pyc **/migrations/__pycache__/ diff --git a/freekake_api/Dockerfile b/freekake_api/Dockerfile index c8b5a10..01ce88e 100644 --- a/freekake_api/Dockerfile +++ b/freekake_api/Dockerfile @@ -1,28 +1,37 @@ -# Use an official Python runtime as a base image FROM python:3.13.5-slim-bookworm -# Set environment variables -ENV PYTHONDONTWRITEBYTECODE 1 -ENV PYTHONUNBUFFERED 1 +ENV PYTHONDONTWRITEBYTECODE=1 \ + PYTHONUNBUFFERED=1 \ + PIP_NO_CACHE_DIR=1 -# Set work directory WORKDIR /app -# Install system dependencies RUN apt-get update && \ - apt-get install -y build-essential libpq-dev && \ - rm -rf /var/lib/apt/lists/* + apt-get install -y --no-install-recommends \ + build-essential \ + libpq-dev \ + curl \ + netcat \ + gcc \ + libffi-dev \ + libssl-dev \ + && rm -rf /var/lib/apt/lists/* -# Install Python dependencies COPY requirements.txt /app/ -RUN pip install --upgrade pip && pip install -r requirements.txt +RUN pip install --upgrade pip \ + && pip install --no-cache-dir -r requirements.txt -# Copy project -COPY . /app/ +COPY . . WORKDIR /app -# Run migrations & collect static in production (optional) -# CMD ["python", "manage.py", "migrate"] && ["python", "manage.py", "collectstatic", "--noinput"] +# Optionally run migrations and collectstatic on container start +# (better done via entrypoint script for robustness) +# CMD ["sh", "-c", "python manage.py migrate && python manage.py collectstatic --noinput"] + +# Use entrypoint for wait-for-db or init tasks +COPY ./entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] # Command to run the server CMD ["gunicorn", "freekake_api.wsgi:application", "--bind", "0.0.0.0:8000"] diff --git a/freekake_api/entrypoint.sh b/freekake_api/entrypoint.sh new file mode 100644 index 0000000..2b1e50e --- /dev/null +++ b/freekake_api/entrypoint.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +# Tunggu sampai DB siap (gunakan jika perlu) +# echo "Waiting for postgres..." +# while ! nc -z db 5432; do +# sleep 0.1 +# done +# echo "PostgreSQL started" + +python manage.py migrate --noinput +python manage.py collectstatic --noinput + +exec "$@"