chore: implement self-healing entrypoint and fix line endings
Build & Push Docker Image (Backend) / build (push) Successful in 2m8s
Build & Push Docker Image (Backend) / build (push) Successful in 2m8s
This commit is contained in:
+9
-8
@@ -35,19 +35,20 @@ RUN pip install --no-cache-dir -r requirements.txt
|
|||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# =========================
|
# =========================
|
||||||
# Collect Static Files
|
# Setup Entrypoint (เพิ่มตรงนี้ครับ)
|
||||||
# =========================
|
# =========================
|
||||||
RUN python manage.py collectstatic --noinput
|
# แนะนำให้ใช้คำสั่งนี้เพื่อให้มั่นใจว่าสิทธิ์ไฟล์ถูกต้องใน Linux environment
|
||||||
|
RUN chmod +x /app/entrypoint.sh
|
||||||
|
|
||||||
# =========================
|
# =========================
|
||||||
# Expose Application Port
|
# Environment Variables (Optional)
|
||||||
# =========================
|
# =========================
|
||||||
EXPOSE 8000
|
EXPOSE 8000
|
||||||
|
|
||||||
# =========================
|
# =========================
|
||||||
# Run Application
|
# ENTRYPOINT & CMD # ENTRYPOINT จะรันสคริปต์เพื่อ Migrate ฐานข้อมูลก่อนเสมอ
|
||||||
# =========================
|
# =========================
|
||||||
# =========================
|
ENTRYPOINT ["/app/entrypoint.sh"]
|
||||||
# Run Application
|
|
||||||
# =========================
|
# CMD จะถูกส่งไปเป็นพารามิเตอร์ $1 ให้กับ entrypoint.sh
|
||||||
CMD ["python", "-m", "gunicorn", "core.wsgi:application", "--bind", "0.0.0.0:8000", "--workers", "3", "--timeout", "120"]
|
CMD ["gunicorn"]
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# ฟังก์ชันสำหรับเตรียมระบบ Backend
|
||||||
|
prepare_backend() {
|
||||||
|
echo "--- Collecting static files ---"
|
||||||
|
python manage.py collectstatic --noinput
|
||||||
|
|
||||||
|
echo "--- Applying database migrations ---"
|
||||||
|
python manage.py migrate --noinput
|
||||||
|
}
|
||||||
|
|
||||||
|
# ตรวจสอบพารามิเตอร์ที่ส่งมาจาก Kubernetes Deployment (command/args)
|
||||||
|
if [ "$1" = "gunicorn" ]; then
|
||||||
|
prepare_backend
|
||||||
|
|
||||||
|
# ดึงค่า PORT และ WORKERS จาก Env (ถ้ามี) หรือใช้ค่า Default
|
||||||
|
APP_PORT=${PORT:-8000}
|
||||||
|
WORKERS=${GUNICORN_WORKERS:-3}
|
||||||
|
|
||||||
|
echo "Starting Gunicorn on port $APP_PORT with $WORKERS workers..."
|
||||||
|
exec gunicorn --bind 0.0.0.0:$APP_PORT \
|
||||||
|
--workers $WORKERS \
|
||||||
|
--access-logfile - \
|
||||||
|
--error-logfile - \
|
||||||
|
core.wsgi:application
|
||||||
|
|
||||||
|
elif [ "$1" = "celery" ]; then
|
||||||
|
echo "Starting Celery Worker..."
|
||||||
|
exec celery -A core worker -l info
|
||||||
|
|
||||||
|
else
|
||||||
|
# สำหรับคำสั่งอื่นๆ เช่น python manage.py createsuperuser
|
||||||
|
echo "Executing custom command: $@"
|
||||||
|
exec "$@"
|
||||||
|
fi
|
||||||
Reference in New Issue
Block a user