Add: entypoint script to docker backend
This commit is contained in:
parent
09203e797c
commit
89e6f2e271
2 changed files with 36 additions and 3 deletions
|
@ -31,10 +31,10 @@ COPY requirements.txt ./
|
||||||
RUN pip install --no-cache-dir -r requirements.txt
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
# Copy the entrypoint script first
|
# Copy the entrypoint script first
|
||||||
COPY --chown=archivist:archivist ./entrypoint.sh /app/entrypoint.sh
|
COPY ./entrypoint.sh /entrypoint.sh
|
||||||
|
|
||||||
# Ensure it's executable inside the container too
|
# Ensure it's executable inside the container too
|
||||||
RUN chmod +x /app/entrypoint.sh
|
RUN chmod +x /entrypoint.sh
|
||||||
|
|
||||||
# Copy the rest of the backend source code
|
# Copy the rest of the backend source code
|
||||||
COPY --chown=archivist:archivist . .
|
COPY --chown=archivist:archivist . .
|
||||||
|
@ -43,7 +43,7 @@ COPY --chown=archivist:archivist . .
|
||||||
USER archivist
|
USER archivist
|
||||||
|
|
||||||
# Set the entrypoint script
|
# Set the entrypoint script
|
||||||
ENTRYPOINT ["/app/entrypoint.sh"]
|
ENTRYPOINT ["/entrypoint.sh"]
|
||||||
|
|
||||||
# Set the default command that the entrypoint will execute if none is provided by compose
|
# Set the default command that the entrypoint will execute if none is provided by compose
|
||||||
# This is useful if you run the image directly without compose sometimes
|
# This is useful if you run the image directly without compose sometimes
|
||||||
|
|
33
backend/entrypoint.sh
Normal file
33
backend/entrypoint.sh
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Exit immediately if a command exits with a non-zero status.
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Optional: Wait for the database to be ready
|
||||||
|
# This simple loop tries to connect using Django's checks until it succeeds.
|
||||||
|
# Requires DATABASE_URL environment variable to be set correctly.
|
||||||
|
echo "Waiting for database..."
|
||||||
|
# You might need to install netcat (nc) in your Dockerfile for this:
|
||||||
|
# RUN apt-get update && apt-get install -y netcat-openbsd && rm -rf /var/lib/apt/lists/*
|
||||||
|
# Or use a more robust python script check if nc is not available/preferred.
|
||||||
|
|
||||||
|
# Simple check using Django shell (assumes DATABASE_URL is configured)
|
||||||
|
# Loop until the db connection is successful
|
||||||
|
until python manage.py shell -c "import sys; from django.db import connections; sys.exit(0) if connections['default'].cursor() else sys.exit(1)"; do
|
||||||
|
echo "Database is unavailable - sleeping"
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
echo "Database is up - continuing..."
|
||||||
|
|
||||||
|
# Apply database migrations
|
||||||
|
echo "Applying database migrations..."
|
||||||
|
python manage.py migrate --noinput
|
||||||
|
|
||||||
|
# --- Create Superuser using the management command ---
|
||||||
|
echo "Attempting to create superuser if needed..."
|
||||||
|
python manage.py createadmin
|
||||||
|
|
||||||
|
# Start the main process (passed as arguments to the script)
|
||||||
|
# "$@" executes the command passed in the docker-compose 'command' or the Dockerfile 'CMD'.
|
||||||
|
echo "Starting server..."
|
||||||
|
exec "$@"
|
Loading…
Add table
Add a link
Reference in a new issue