Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: entrypoint in all stages, remove wait-for-it #2

Merged
merged 1 commit into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 8 additions & 20 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ RUN set -ex \
"libwebp-dev" \
&& rm -rf /var/lib/apt/lists/*
# Copy the entrypoint script into the Docker image
COPY --chown=wagtail:wagtail entrypoint.dev.sh /app/entrypoint.dev.sh
COPY --chown=wagtail:wagtail container-entrypoint.sh /
# Copy pip dependencies from build stage
COPY --from=build \
/root/.local \
Expand All @@ -95,9 +95,11 @@ COPY . /app/
# Add non-root user, permissions
RUN useradd -u 1001 -m -c "hotosm account" -d /home/wagtail -s /bin/false wagtail \
&& chown -R wagtail:wagtail /app /home/wagtail \
&& chmod +x /app/entrypoint.dev.sh
&& chmod +x /container-entrypoint.sh
# Change to non-root user
USER wagtail
# Add entrypoint for all following stages
ENTRYPOINT ["/container-entrypoint.sh"]


# Define test (ci) stage
Expand All @@ -117,18 +119,15 @@ RUN mv /home/wagtail/.local/bin/* /usr/local/bin/ \
&& rm -r /opt/python \
# Pre-compile packages to .pyc (init speed gains)
&& python -c "import compileall; compileall.compile_path(maxlevels=10, quiet=1)"
CMD [ "pytest" ]
CMD ["pytest"]


# Define debug (development) stage
FROM runtime as debug
# Add Healthcheck
HEALTHCHECK --start-period=10s --interval=5s --retries=20 --timeout=5s \
CMD curl --fail http://localhost:8000 || exit 1
# Use the entrypoint script as the Docker entrypoint
ENTRYPOINT ["/app/entrypoint.dev.sh"]
CMD ["./wait-for-it.sh", "db:5432", "--", \
"python", "manage.py", "runserver", "0.0.0.0:8000"]
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]


# Define prod stage
Expand All @@ -137,16 +136,5 @@ FROM runtime as prod
HEALTHCHECK --start-period=10s --interval=5s --retries=20 --timeout=5s \
CMD curl --fail http://localhost:8000 || exit 1
# Pre-compile packages to .pyc (init speed gains)
RUN python -c "import compileall; compileall.compile_path(maxlevels=10, quiet=1)" \
# Collect static files
&& python manage.py collectstatic --noinput --clear
# Runtime command that executes when "docker run" is called, it does the
# following:
# 1. Migrate the database.
# 2. Start the application server.
# WARNING:
# Migrating database at the same time as starting the server IS NOT THE BEST
# PRACTICE. The database should be migrated manually or using the release
# phase facilities of your hosting platform. This is used only so the
# Wagtail instance can be started with a simple "docker run" command.
CMD set -xe; python manage.py migrate --noinput; gunicorn hot_osm.wsgi:application
RUN python -c "import compileall; compileall.compile_path(maxlevels=10, quiet=1)"
CMD ["gunicorn", "hot_osm.wsgi:application"]
16 changes: 13 additions & 3 deletions entrypoint.dev.sh → container-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
#!/bin/sh

# WARNING:
# Migrating database at the same time as starting the server IS NOT THE BEST
# PRACTICE. The database should be migrated manually or using the release
# phase facilities of your hosting platform. This is used only so the
# Wagtail instance can be started with a simple "docker run" command.

# Apply database migrations
echo "Apply database migrations"
python manage.py migrate

# Collect static
echo "Collect static files"
python manage.py collectstatic --noinput --clear

# Create superuser
echo "Creating superuser"
if [ -z "$DJANGO_SUPERUSER_USERNAME" ] || [ -z "$DJANGO_SUPERUSER_PASSWORD" ] ; then
echo "Superuser credentials not provided, skipping superuser creation."
else
echo "Creating superuser $DJANGO_SUPERUSER_USERNAME"
echo "from django.contrib.auth import get_user_model; User = get_user_model(); User.objects.create_superuser('$DJANGO_SUPERUSER_USERNAME', '$DJANGO_SUPERUSER_EMAIL', '$DJANGO_SUPERUSER_PASSWORD')" | python manage.py shell
fi

# Start server
echo "Starting server"
gunicorn hot_osm.wsgi:application
echo "Running command: $@"
exec "$@"
183 changes: 0 additions & 183 deletions wait-for-it.sh

This file was deleted.