update docker

This commit is contained in:
Irwan Cahyono 2025-08-07 09:24:08 +07:00
parent b7df911c36
commit 89661aa4b9
3 changed files with 38 additions and 14 deletions

View File

@ -71,6 +71,8 @@ media/
staticfiles/ staticfiles/
# Migrations (optional, keep *.py if you want to version control) # Migrations (optional, keep *.py if you want to version control)
**/migrations/*.py
**/migrations/__init__.py
**/migrations/*.pyc **/migrations/*.pyc
**/migrations/__pycache__/ **/migrations/__pycache__/

View File

@ -1,28 +1,37 @@
# Use an official Python runtime as a base image
FROM python:3.13.5-slim-bookworm FROM python:3.13.5-slim-bookworm
# Set environment variables ENV PYTHONDONTWRITEBYTECODE=1 \
ENV PYTHONDONTWRITEBYTECODE 1 PYTHONUNBUFFERED=1 \
ENV PYTHONUNBUFFERED 1 PIP_NO_CACHE_DIR=1
# Set work directory
WORKDIR /app WORKDIR /app
# Install system dependencies
RUN apt-get update && \ RUN apt-get update && \
apt-get install -y build-essential libpq-dev && \ apt-get install -y --no-install-recommends \
rm -rf /var/lib/apt/lists/* build-essential \
libpq-dev \
curl \
netcat \
gcc \
libffi-dev \
libssl-dev \
&& rm -rf /var/lib/apt/lists/*
# Install Python dependencies
COPY requirements.txt /app/ 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 . .
COPY . /app/
WORKDIR /app WORKDIR /app
# Run migrations & collect static in production (optional) # Optionally run migrations and collectstatic on container start
# CMD ["python", "manage.py", "migrate"] && ["python", "manage.py", "collectstatic", "--noinput"] # (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 # Command to run the server
CMD ["gunicorn", "freekake_api.wsgi:application", "--bind", "0.0.0.0:8000"] CMD ["gunicorn", "freekake_api.wsgi:application", "--bind", "0.0.0.0:8000"]

View File

@ -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 "$@"