diff --git a/django.registry.Dockerfile b/django.registry.Dockerfile new file mode 100644 index 0000000..f4bd233 --- /dev/null +++ b/django.registry.Dockerfile @@ -0,0 +1,20 @@ +# Imagen de produccion del backend para publicar en el registry de Gitea. +# Autocontenida: incluye el codigo y un entrypoint que aplica migraciones, +# colecta estaticos y arranca gunicorn. Coolify solo hace pull y define env vars. +FROM python:3.12-slim + +ENV PYTHONDONTWRITEBYTECODE=1 \ + PYTHONUNBUFFERED=1 + +WORKDIR /app/ + +COPY requirements.txt ./ +RUN pip install --no-cache-dir -r requirements.txt + +COPY tienda_ilusion/ /app/ +COPY docker/entrypoint.sh /usr/local/bin/entrypoint.sh +RUN chmod +x /usr/local/bin/entrypoint.sh + +EXPOSE 8000 + +ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] \ No newline at end of file diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh new file mode 100755 index 0000000..f4cb406 --- /dev/null +++ b/docker/entrypoint.sh @@ -0,0 +1,23 @@ +#!/bin/sh +# Entrypoint de la imagen de produccion del backend. +# +# Sin argumentos: aplica migraciones, colecta estaticos y arranca gunicorn. +# Con argumentos: ejecuta ese comando tal cual (util para operaciones, p. ej. +# docker run --rm python manage.py createsuperuser). +set -e + +if [ "$#" -gt 0 ]; then + exec "$@" +fi + +echo "[entrypoint] Aplicando migraciones..." +python manage.py migrate --noinput + +echo "[entrypoint] Colectando estaticos..." +python manage.py collectstatic --noinput + +echo "[entrypoint] Arrancando gunicorn en 0.0.0.0:8000..." +exec gunicorn config.wsgi:application \ + --bind 0.0.0.0:8000 \ + --workers "${GUNICORN_WORKERS:-4}" \ + --timeout 120 \ No newline at end of file diff --git a/scripts/build-push-image.sh b/scripts/build-push-image.sh new file mode 100755 index 0000000..cc40953 --- /dev/null +++ b/scripts/build-push-image.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash +# Construye y publica la imagen del backend en el container registry de Gitea. +# +# Uso: +# scripts/build-push-image.sh +# +# Requiere haber hecho login previo en el registry (hazlo tu, con tu token): +# docker login gitea.onecluster.org -u +# (password = tu token con scope write:package) +# +# Variables opcionales: +# REGISTRY (default: gitea.onecluster.org) +# OWNER (default: oneteam) +# IMAGE (default: don_confiao_backend) +# TAG (default: git short sha) +set -euo pipefail + +REGISTRY="${REGISTRY:-gitea.onecluster.org}" +OWNER="${OWNER:-oneteam}" +IMAGE="${IMAGE:-don_confiao_backend}" +DOCKERFILE="${DOCKERFILE:-django.registry.Dockerfile}" + +TAG="${TAG:-$(git rev-parse --short HEAD)}" +FULL="${REGISTRY}/${OWNER}/${IMAGE}" + +echo "==> Imagen: ${FULL}:latest y ${FULL}:${TAG}" +echo "==> Dockerfile: ${DOCKERFILE}" + +docker build -f "${DOCKERFILE}" \ + -t "${FULL}:latest" \ + -t "${FULL}:${TAG}" \ + . + +docker push "${FULL}:latest" +docker push "${FULL}:${TAG}" + +echo "==> Publicado: ${FULL}:latest , ${FULL}:${TAG}" \ No newline at end of file