fix: Ensure deploy script runs once and is part of entrypoint
The deploy.sh script is now re-added to the entrypoint.sh script to ensure it runs only during first container startup. A flag file (/flags/.deployed) is now created after a successful deployment. The deploy.sh script checks for this flag and will not re-run deployment steps unless FORCE_DEPLOY is set to true. This prevents unnecessary re-runs of migrations, collectstatic, etc., on subsequent container starts within the same deployment. Corrected permissions for `/app/.cursor-server` and created a `/flags` directory with appropriate permissions in the `Dockerfile`. Added ENV DJANGO_SETTINGS_MODULE with default value to `Dockerfile`.
This commit is contained in:
parent
c87d73435b
commit
d4948e7cd3
3 changed files with 21 additions and 8 deletions
|
|
@ -62,6 +62,7 @@ ENV PATH=/app/bin:$PATH
|
||||||
ENV PYTHONPATH=/app
|
ENV PYTHONPATH=/app
|
||||||
ENV PYTHONUNBUFFERED=1
|
ENV PYTHONUNBUFFERED=1
|
||||||
ENV HOME=/app
|
ENV HOME=/app
|
||||||
|
ENV DJANGO_SETTINGS_MODULE=pkmntrade_club.django_project.settings
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
|
@ -94,11 +95,13 @@ COPY --chown=app:app --chmod=700 /manage.py /app/manage.py
|
||||||
ENTRYPOINT ["/entrypoint.sh"]
|
ENTRYPOINT ["/entrypoint.sh"]
|
||||||
|
|
||||||
RUN --mount=type=cache,target=${CACHE_DIR} \
|
RUN --mount=type=cache,target=${CACHE_DIR} \
|
||||||
mkdir -p /app/.cursor-server && chown app:app /app /app/.cursor-server
|
mkdir -p /app/.cursor-server && chmod 755 /app/.cursor-server && chown app:app /app /app/.cursor-server
|
||||||
|
|
||||||
|
RUN --mount=type=cache,target=${CACHE_DIR} \
|
||||||
|
mkdir -p /flags && chmod 700 /flags && chown app:app /flags
|
||||||
|
|
||||||
USER app
|
USER app
|
||||||
|
|
||||||
EXPOSE 8000
|
EXPOSE 8000
|
||||||
|
|
||||||
CMD ["granian", "--interface", "wsgi", "pkmntrade_club.django_project.wsgi:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "1", "--backpressure", "16", "--workers-kill-timeout", "180", "--access-log"]
|
CMD ["granian", "--interface", "wsgi", "pkmntrade_club.django_project.wsgi:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "1", "--backpressure", "16", "--workers-kill-timeout", "180", "--access-log"]
|
||||||
#, "--static-path-mount", "./staticfiles"
|
|
||||||
|
|
@ -1,5 +1,10 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [[ -f /flags/.deployed && "$FORCE_DEPLOY" != "true" ]]; then
|
||||||
|
echo "*** Previously deployed successfully."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
echo "*** Running makemigrations --check to make sure migrations are up to date..."
|
echo "*** Running makemigrations --check to make sure migrations are up to date..."
|
||||||
django-admin makemigrations --noinput --check 2>&1 || exit 1
|
django-admin makemigrations --noinput --check 2>&1 || exit 1
|
||||||
|
|
||||||
|
|
@ -12,4 +17,7 @@ django-admin clear_cache 2>&1
|
||||||
echo "*** Running collectstatic..."
|
echo "*** Running collectstatic..."
|
||||||
django-admin collectstatic -c --no-input 2>&1
|
django-admin collectstatic -c --no-input 2>&1
|
||||||
|
|
||||||
|
echo "*** Marking as deployed..."
|
||||||
|
touch /flags/.deployed
|
||||||
|
|
||||||
echo "*** Deployed successfully!"
|
echo "*** Deployed successfully!"
|
||||||
|
|
@ -13,5 +13,7 @@ else
|
||||||
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
|
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
/deploy.sh
|
||||||
|
|
||||||
echo "Environment is correct - executing command: '$@'"
|
echo "Environment is correct - executing command: '$@'"
|
||||||
exec "$@" && exit 0
|
exec "$@" && exit 0
|
||||||
Loading…
Add table
Add a link
Reference in a new issue