From 303460f513bf4b2d994dc0a5605521062a71e33a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Fri, 10 May 2019 15:59:57 +0400 Subject: [PATCH 1/2] :sparkles: Add prestart script support for uwsgi-nginx --- python2.7-alpine3.7/Dockerfile | 8 +++++++- python2.7-alpine3.7/app/prestart.sh | 12 ++++++++++++ python2.7-alpine3.7/start.sh | 15 +++++++++++++++ python2.7-alpine3.8/Dockerfile | 8 +++++++- python2.7-alpine3.8/app/prestart.sh | 12 ++++++++++++ python2.7-alpine3.8/start.sh | 15 +++++++++++++++ python2.7-alpine3.9/Dockerfile | 8 +++++++- python2.7-alpine3.9/app/prestart.sh | 12 ++++++++++++ python2.7-alpine3.9/start.sh | 15 +++++++++++++++ python2.7/Dockerfile | 8 +++++++- python2.7/app/prestart.sh | 12 ++++++++++++ python2.7/start.sh | 15 +++++++++++++++ python3.5/Dockerfile | 8 +++++++- python3.5/app/prestart.sh | 12 ++++++++++++ python3.5/start.sh | 15 +++++++++++++++ python3.6-alpine3.7/Dockerfile | 8 +++++++- python3.6-alpine3.7/app/prestart.sh | 12 ++++++++++++ python3.6-alpine3.7/start.sh | 15 +++++++++++++++ python3.6-alpine3.8/Dockerfile | 8 +++++++- python3.6-alpine3.8/app/prestart.sh | 12 ++++++++++++ python3.6-alpine3.8/start.sh | 15 +++++++++++++++ python3.6-alpine3.9/Dockerfile | 8 +++++++- python3.6-alpine3.9/app/prestart.sh | 12 ++++++++++++ python3.6-alpine3.9/start.sh | 15 +++++++++++++++ python3.6/Dockerfile | 8 +++++++- python3.6/app/prestart.sh | 12 ++++++++++++ python3.6/start.sh | 15 +++++++++++++++ python3.7-alpine3.7/Dockerfile | 8 +++++++- python3.7-alpine3.7/app/prestart.sh | 12 ++++++++++++ python3.7-alpine3.7/start.sh | 15 +++++++++++++++ python3.7-alpine3.8/Dockerfile | 8 +++++++- python3.7-alpine3.8/app/prestart.sh | 12 ++++++++++++ python3.7-alpine3.8/start.sh | 15 +++++++++++++++ python3.7-alpine3.9/Dockerfile | 8 +++++++- python3.7-alpine3.9/app/prestart.sh | 12 ++++++++++++ python3.7-alpine3.9/start.sh | 15 +++++++++++++++ python3.7/Dockerfile | 8 +++++++- python3.7/app/prestart.sh | 12 ++++++++++++ python3.7/start.sh | 15 +++++++++++++++ 39 files changed, 442 insertions(+), 13 deletions(-) create mode 100644 python2.7-alpine3.7/app/prestart.sh create mode 100644 python2.7-alpine3.7/start.sh create mode 100644 python2.7-alpine3.8/app/prestart.sh create mode 100644 python2.7-alpine3.8/start.sh create mode 100644 python2.7-alpine3.9/app/prestart.sh create mode 100644 python2.7-alpine3.9/start.sh create mode 100644 python2.7/app/prestart.sh create mode 100644 python2.7/start.sh create mode 100644 python3.5/app/prestart.sh create mode 100644 python3.5/start.sh create mode 100644 python3.6-alpine3.7/app/prestart.sh create mode 100644 python3.6-alpine3.7/start.sh create mode 100644 python3.6-alpine3.8/app/prestart.sh create mode 100644 python3.6-alpine3.8/start.sh create mode 100644 python3.6-alpine3.9/app/prestart.sh create mode 100644 python3.6-alpine3.9/start.sh create mode 100644 python3.6/app/prestart.sh create mode 100644 python3.6/start.sh create mode 100644 python3.7-alpine3.7/app/prestart.sh create mode 100644 python3.7-alpine3.7/start.sh create mode 100644 python3.7-alpine3.8/app/prestart.sh create mode 100644 python3.7-alpine3.8/start.sh create mode 100644 python3.7-alpine3.9/app/prestart.sh create mode 100644 python3.7-alpine3.9/start.sh create mode 100644 python3.7/app/prestart.sh create mode 100644 python3.7/start.sh diff --git a/python2.7-alpine3.7/Dockerfile b/python2.7-alpine3.7/Dockerfile index c7a4eb6..9a1a9aa 100644 --- a/python2.7-alpine3.7/Dockerfile +++ b/python2.7-alpine3.7/Dockerfile @@ -181,6 +181,10 @@ ENV NGINX_WORKER_PROCESSES 1 # (in a Dockerfile or with an option for `docker run`) ENV LISTEN_PORT 80 +# Copy start.sh script that will check for a /app/prestart.sh script and run it before starting the app +COPY start.sh /start.sh +RUN chmod +x /start.sh + # Copy the entrypoint that will generate Nginx additional configs COPY entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh @@ -191,4 +195,6 @@ ENTRYPOINT ["sh", "/entrypoint.sh"] COPY ./app /app WORKDIR /app -CMD ["/usr/bin/supervisord"] +# Run the start script, it will check for an /app/prestart.sh script (e.g. for migrations) +# And then will start Supervisor, which in turn will start Nginx and uWSGI +CMD ["/start.sh"] diff --git a/python2.7-alpine3.7/app/prestart.sh b/python2.7-alpine3.7/app/prestart.sh new file mode 100644 index 0000000..9ccb1da --- /dev/null +++ b/python2.7-alpine3.7/app/prestart.sh @@ -0,0 +1,12 @@ +#! /usr/bin/env sh + +echo "Running inside /app/prestart.sh, you could add migrations to this file, e.g.:" + +echo " +#! /usr/bin/env bash + +# Let the DB start +sleep 10; +# Run migrations +alembic upgrade head +" diff --git a/python2.7-alpine3.7/start.sh b/python2.7-alpine3.7/start.sh new file mode 100644 index 0000000..60718f4 --- /dev/null +++ b/python2.7-alpine3.7/start.sh @@ -0,0 +1,15 @@ +#! /usr/bin/env sh +set -e + +# If there's a prestart.sh script in the /app directory, run it before starting +PRE_START_PATH=/app/prestart.sh +echo "Checking for script in $PRE_START_PATH" +if [ -f $PRE_START_PATH ] ; then + echo "Running script $PRE_START_PATH" + . $PRE_START_PATH +else + echo "There is no script $PRE_START_PATH" +fi + +# Start Supervisor, with Nginx and uWSGI +exec /usr/bin/supervisord diff --git a/python2.7-alpine3.8/Dockerfile b/python2.7-alpine3.8/Dockerfile index 3ae72cd..26d9e1a 100644 --- a/python2.7-alpine3.8/Dockerfile +++ b/python2.7-alpine3.8/Dockerfile @@ -181,6 +181,10 @@ ENV NGINX_WORKER_PROCESSES 1 # (in a Dockerfile or with an option for `docker run`) ENV LISTEN_PORT 80 +# Copy start.sh script that will check for a /app/prestart.sh script and run it before starting the app +COPY start.sh /start.sh +RUN chmod +x /start.sh + # Copy the entrypoint that will generate Nginx additional configs COPY entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh @@ -191,4 +195,6 @@ ENTRYPOINT ["sh", "/entrypoint.sh"] COPY ./app /app WORKDIR /app -CMD ["/usr/bin/supervisord"] +# Run the start script, it will check for an /app/prestart.sh script (e.g. for migrations) +# And then will start Supervisor, which in turn will start Nginx and uWSGI +CMD ["/start.sh"] diff --git a/python2.7-alpine3.8/app/prestart.sh b/python2.7-alpine3.8/app/prestart.sh new file mode 100644 index 0000000..9ccb1da --- /dev/null +++ b/python2.7-alpine3.8/app/prestart.sh @@ -0,0 +1,12 @@ +#! /usr/bin/env sh + +echo "Running inside /app/prestart.sh, you could add migrations to this file, e.g.:" + +echo " +#! /usr/bin/env bash + +# Let the DB start +sleep 10; +# Run migrations +alembic upgrade head +" diff --git a/python2.7-alpine3.8/start.sh b/python2.7-alpine3.8/start.sh new file mode 100644 index 0000000..60718f4 --- /dev/null +++ b/python2.7-alpine3.8/start.sh @@ -0,0 +1,15 @@ +#! /usr/bin/env sh +set -e + +# If there's a prestart.sh script in the /app directory, run it before starting +PRE_START_PATH=/app/prestart.sh +echo "Checking for script in $PRE_START_PATH" +if [ -f $PRE_START_PATH ] ; then + echo "Running script $PRE_START_PATH" + . $PRE_START_PATH +else + echo "There is no script $PRE_START_PATH" +fi + +# Start Supervisor, with Nginx and uWSGI +exec /usr/bin/supervisord diff --git a/python2.7-alpine3.9/Dockerfile b/python2.7-alpine3.9/Dockerfile index ce33c79..e172341 100644 --- a/python2.7-alpine3.9/Dockerfile +++ b/python2.7-alpine3.9/Dockerfile @@ -181,6 +181,10 @@ ENV NGINX_WORKER_PROCESSES 1 # (in a Dockerfile or with an option for `docker run`) ENV LISTEN_PORT 80 +# Copy start.sh script that will check for a /app/prestart.sh script and run it before starting the app +COPY start.sh /start.sh +RUN chmod +x /start.sh + # Copy the entrypoint that will generate Nginx additional configs COPY entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh @@ -191,4 +195,6 @@ ENTRYPOINT ["sh", "/entrypoint.sh"] COPY ./app /app WORKDIR /app -CMD ["/usr/bin/supervisord"] +# Run the start script, it will check for an /app/prestart.sh script (e.g. for migrations) +# And then will start Supervisor, which in turn will start Nginx and uWSGI +CMD ["/start.sh"] diff --git a/python2.7-alpine3.9/app/prestart.sh b/python2.7-alpine3.9/app/prestart.sh new file mode 100644 index 0000000..9ccb1da --- /dev/null +++ b/python2.7-alpine3.9/app/prestart.sh @@ -0,0 +1,12 @@ +#! /usr/bin/env sh + +echo "Running inside /app/prestart.sh, you could add migrations to this file, e.g.:" + +echo " +#! /usr/bin/env bash + +# Let the DB start +sleep 10; +# Run migrations +alembic upgrade head +" diff --git a/python2.7-alpine3.9/start.sh b/python2.7-alpine3.9/start.sh new file mode 100644 index 0000000..60718f4 --- /dev/null +++ b/python2.7-alpine3.9/start.sh @@ -0,0 +1,15 @@ +#! /usr/bin/env sh +set -e + +# If there's a prestart.sh script in the /app directory, run it before starting +PRE_START_PATH=/app/prestart.sh +echo "Checking for script in $PRE_START_PATH" +if [ -f $PRE_START_PATH ] ; then + echo "Running script $PRE_START_PATH" + . $PRE_START_PATH +else + echo "There is no script $PRE_START_PATH" +fi + +# Start Supervisor, with Nginx and uWSGI +exec /usr/bin/supervisord diff --git a/python2.7/Dockerfile b/python2.7/Dockerfile index efd2056..3a8116f 100644 --- a/python2.7/Dockerfile +++ b/python2.7/Dockerfile @@ -138,6 +138,10 @@ ENV NGINX_WORKER_PROCESSES 1 # (in a Dockerfile or with an option for `docker run`) ENV LISTEN_PORT 80 +# Copy start.sh script that will check for a /app/prestart.sh script and run it before starting the app +COPY start.sh /start.sh +RUN chmod +x /start.sh + # Copy the entrypoint that will generate Nginx additional configs COPY entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh @@ -148,4 +152,6 @@ ENTRYPOINT ["/entrypoint.sh"] COPY ./app /app WORKDIR /app -CMD ["/usr/bin/supervisord"] +# Run the start script, it will check for an /app/prestart.sh script (e.g. for migrations) +# And then will start Supervisor, which in turn will start Nginx and uWSGI +CMD ["/start.sh"] diff --git a/python2.7/app/prestart.sh b/python2.7/app/prestart.sh new file mode 100644 index 0000000..9ccb1da --- /dev/null +++ b/python2.7/app/prestart.sh @@ -0,0 +1,12 @@ +#! /usr/bin/env sh + +echo "Running inside /app/prestart.sh, you could add migrations to this file, e.g.:" + +echo " +#! /usr/bin/env bash + +# Let the DB start +sleep 10; +# Run migrations +alembic upgrade head +" diff --git a/python2.7/start.sh b/python2.7/start.sh new file mode 100644 index 0000000..60718f4 --- /dev/null +++ b/python2.7/start.sh @@ -0,0 +1,15 @@ +#! /usr/bin/env sh +set -e + +# If there's a prestart.sh script in the /app directory, run it before starting +PRE_START_PATH=/app/prestart.sh +echo "Checking for script in $PRE_START_PATH" +if [ -f $PRE_START_PATH ] ; then + echo "Running script $PRE_START_PATH" + . $PRE_START_PATH +else + echo "There is no script $PRE_START_PATH" +fi + +# Start Supervisor, with Nginx and uWSGI +exec /usr/bin/supervisord diff --git a/python3.5/Dockerfile b/python3.5/Dockerfile index 888ec2e..3c96ee7 100644 --- a/python3.5/Dockerfile +++ b/python3.5/Dockerfile @@ -136,6 +136,10 @@ ENV NGINX_WORKER_PROCESSES 1 # (in a Dockerfile or with an option for `docker run`) ENV LISTEN_PORT 80 +# Copy start.sh script that will check for a /app/prestart.sh script and run it before starting the app +COPY start.sh /start.sh +RUN chmod +x /start.sh + # Copy the entrypoint that will generate Nginx additional configs COPY entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh @@ -146,4 +150,6 @@ ENTRYPOINT ["/entrypoint.sh"] COPY ./app /app WORKDIR /app -CMD ["/usr/bin/supervisord"] +# Run the start script, it will check for an /app/prestart.sh script (e.g. for migrations) +# And then will start Supervisor, which in turn will start Nginx and uWSGI +CMD ["/start.sh"] diff --git a/python3.5/app/prestart.sh b/python3.5/app/prestart.sh new file mode 100644 index 0000000..9ccb1da --- /dev/null +++ b/python3.5/app/prestart.sh @@ -0,0 +1,12 @@ +#! /usr/bin/env sh + +echo "Running inside /app/prestart.sh, you could add migrations to this file, e.g.:" + +echo " +#! /usr/bin/env bash + +# Let the DB start +sleep 10; +# Run migrations +alembic upgrade head +" diff --git a/python3.5/start.sh b/python3.5/start.sh new file mode 100644 index 0000000..60718f4 --- /dev/null +++ b/python3.5/start.sh @@ -0,0 +1,15 @@ +#! /usr/bin/env sh +set -e + +# If there's a prestart.sh script in the /app directory, run it before starting +PRE_START_PATH=/app/prestart.sh +echo "Checking for script in $PRE_START_PATH" +if [ -f $PRE_START_PATH ] ; then + echo "Running script $PRE_START_PATH" + . $PRE_START_PATH +else + echo "There is no script $PRE_START_PATH" +fi + +# Start Supervisor, with Nginx and uWSGI +exec /usr/bin/supervisord diff --git a/python3.6-alpine3.7/Dockerfile b/python3.6-alpine3.7/Dockerfile index b0cfc20..bceb6a9 100644 --- a/python3.6-alpine3.7/Dockerfile +++ b/python3.6-alpine3.7/Dockerfile @@ -181,6 +181,10 @@ ENV NGINX_WORKER_PROCESSES 1 # (in a Dockerfile or with an option for `docker run`) ENV LISTEN_PORT 80 +# Copy start.sh script that will check for a /app/prestart.sh script and run it before starting the app +COPY start.sh /start.sh +RUN chmod +x /start.sh + # Copy the entrypoint that will generate Nginx additional configs COPY entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh @@ -191,4 +195,6 @@ ENTRYPOINT ["sh", "/entrypoint.sh"] COPY ./app /app WORKDIR /app -CMD ["/usr/bin/supervisord"] +# Run the start script, it will check for an /app/prestart.sh script (e.g. for migrations) +# And then will start Supervisor, which in turn will start Nginx and uWSGI +CMD ["/start.sh"] diff --git a/python3.6-alpine3.7/app/prestart.sh b/python3.6-alpine3.7/app/prestart.sh new file mode 100644 index 0000000..9ccb1da --- /dev/null +++ b/python3.6-alpine3.7/app/prestart.sh @@ -0,0 +1,12 @@ +#! /usr/bin/env sh + +echo "Running inside /app/prestart.sh, you could add migrations to this file, e.g.:" + +echo " +#! /usr/bin/env bash + +# Let the DB start +sleep 10; +# Run migrations +alembic upgrade head +" diff --git a/python3.6-alpine3.7/start.sh b/python3.6-alpine3.7/start.sh new file mode 100644 index 0000000..60718f4 --- /dev/null +++ b/python3.6-alpine3.7/start.sh @@ -0,0 +1,15 @@ +#! /usr/bin/env sh +set -e + +# If there's a prestart.sh script in the /app directory, run it before starting +PRE_START_PATH=/app/prestart.sh +echo "Checking for script in $PRE_START_PATH" +if [ -f $PRE_START_PATH ] ; then + echo "Running script $PRE_START_PATH" + . $PRE_START_PATH +else + echo "There is no script $PRE_START_PATH" +fi + +# Start Supervisor, with Nginx and uWSGI +exec /usr/bin/supervisord diff --git a/python3.6-alpine3.8/Dockerfile b/python3.6-alpine3.8/Dockerfile index efc9f5b..889dd32 100644 --- a/python3.6-alpine3.8/Dockerfile +++ b/python3.6-alpine3.8/Dockerfile @@ -181,6 +181,10 @@ ENV NGINX_WORKER_PROCESSES 1 # (in a Dockerfile or with an option for `docker run`) ENV LISTEN_PORT 80 +# Copy start.sh script that will check for a /app/prestart.sh script and run it before starting the app +COPY start.sh /start.sh +RUN chmod +x /start.sh + # Copy the entrypoint that will generate Nginx additional configs COPY entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh @@ -191,4 +195,6 @@ ENTRYPOINT ["sh", "/entrypoint.sh"] COPY ./app /app WORKDIR /app -CMD ["/usr/bin/supervisord"] +# Run the start script, it will check for an /app/prestart.sh script (e.g. for migrations) +# And then will start Supervisor, which in turn will start Nginx and uWSGI +CMD ["/start.sh"] diff --git a/python3.6-alpine3.8/app/prestart.sh b/python3.6-alpine3.8/app/prestart.sh new file mode 100644 index 0000000..9ccb1da --- /dev/null +++ b/python3.6-alpine3.8/app/prestart.sh @@ -0,0 +1,12 @@ +#! /usr/bin/env sh + +echo "Running inside /app/prestart.sh, you could add migrations to this file, e.g.:" + +echo " +#! /usr/bin/env bash + +# Let the DB start +sleep 10; +# Run migrations +alembic upgrade head +" diff --git a/python3.6-alpine3.8/start.sh b/python3.6-alpine3.8/start.sh new file mode 100644 index 0000000..60718f4 --- /dev/null +++ b/python3.6-alpine3.8/start.sh @@ -0,0 +1,15 @@ +#! /usr/bin/env sh +set -e + +# If there's a prestart.sh script in the /app directory, run it before starting +PRE_START_PATH=/app/prestart.sh +echo "Checking for script in $PRE_START_PATH" +if [ -f $PRE_START_PATH ] ; then + echo "Running script $PRE_START_PATH" + . $PRE_START_PATH +else + echo "There is no script $PRE_START_PATH" +fi + +# Start Supervisor, with Nginx and uWSGI +exec /usr/bin/supervisord diff --git a/python3.6-alpine3.9/Dockerfile b/python3.6-alpine3.9/Dockerfile index 216c76c..f108f48 100644 --- a/python3.6-alpine3.9/Dockerfile +++ b/python3.6-alpine3.9/Dockerfile @@ -181,6 +181,10 @@ ENV NGINX_WORKER_PROCESSES 1 # (in a Dockerfile or with an option for `docker run`) ENV LISTEN_PORT 80 +# Copy start.sh script that will check for a /app/prestart.sh script and run it before starting the app +COPY start.sh /start.sh +RUN chmod +x /start.sh + # Copy the entrypoint that will generate Nginx additional configs COPY entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh @@ -191,4 +195,6 @@ ENTRYPOINT ["sh", "/entrypoint.sh"] COPY ./app /app WORKDIR /app -CMD ["/usr/bin/supervisord"] +# Run the start script, it will check for an /app/prestart.sh script (e.g. for migrations) +# And then will start Supervisor, which in turn will start Nginx and uWSGI +CMD ["/start.sh"] diff --git a/python3.6-alpine3.9/app/prestart.sh b/python3.6-alpine3.9/app/prestart.sh new file mode 100644 index 0000000..9ccb1da --- /dev/null +++ b/python3.6-alpine3.9/app/prestart.sh @@ -0,0 +1,12 @@ +#! /usr/bin/env sh + +echo "Running inside /app/prestart.sh, you could add migrations to this file, e.g.:" + +echo " +#! /usr/bin/env bash + +# Let the DB start +sleep 10; +# Run migrations +alembic upgrade head +" diff --git a/python3.6-alpine3.9/start.sh b/python3.6-alpine3.9/start.sh new file mode 100644 index 0000000..60718f4 --- /dev/null +++ b/python3.6-alpine3.9/start.sh @@ -0,0 +1,15 @@ +#! /usr/bin/env sh +set -e + +# If there's a prestart.sh script in the /app directory, run it before starting +PRE_START_PATH=/app/prestart.sh +echo "Checking for script in $PRE_START_PATH" +if [ -f $PRE_START_PATH ] ; then + echo "Running script $PRE_START_PATH" + . $PRE_START_PATH +else + echo "There is no script $PRE_START_PATH" +fi + +# Start Supervisor, with Nginx and uWSGI +exec /usr/bin/supervisord diff --git a/python3.6/Dockerfile b/python3.6/Dockerfile index 71e0840..92cd009 100644 --- a/python3.6/Dockerfile +++ b/python3.6/Dockerfile @@ -139,6 +139,10 @@ ENV NGINX_WORKER_PROCESSES 1 # (in a Dockerfile or with an option for `docker run`) ENV LISTEN_PORT 80 +# Copy start.sh script that will check for a /app/prestart.sh script and run it before starting the app +COPY start.sh /start.sh +RUN chmod +x /start.sh + # Copy the entrypoint that will generate Nginx additional configs COPY entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh @@ -149,4 +153,6 @@ ENTRYPOINT ["/entrypoint.sh"] COPY ./app /app WORKDIR /app -CMD ["/usr/bin/supervisord"] +# Run the start script, it will check for an /app/prestart.sh script (e.g. for migrations) +# And then will start Supervisor, which in turn will start Nginx and uWSGI +CMD ["/start.sh"] diff --git a/python3.6/app/prestart.sh b/python3.6/app/prestart.sh new file mode 100644 index 0000000..9ccb1da --- /dev/null +++ b/python3.6/app/prestart.sh @@ -0,0 +1,12 @@ +#! /usr/bin/env sh + +echo "Running inside /app/prestart.sh, you could add migrations to this file, e.g.:" + +echo " +#! /usr/bin/env bash + +# Let the DB start +sleep 10; +# Run migrations +alembic upgrade head +" diff --git a/python3.6/start.sh b/python3.6/start.sh new file mode 100644 index 0000000..60718f4 --- /dev/null +++ b/python3.6/start.sh @@ -0,0 +1,15 @@ +#! /usr/bin/env sh +set -e + +# If there's a prestart.sh script in the /app directory, run it before starting +PRE_START_PATH=/app/prestart.sh +echo "Checking for script in $PRE_START_PATH" +if [ -f $PRE_START_PATH ] ; then + echo "Running script $PRE_START_PATH" + . $PRE_START_PATH +else + echo "There is no script $PRE_START_PATH" +fi + +# Start Supervisor, with Nginx and uWSGI +exec /usr/bin/supervisord diff --git a/python3.7-alpine3.7/Dockerfile b/python3.7-alpine3.7/Dockerfile index 0b102f2..1b059f8 100644 --- a/python3.7-alpine3.7/Dockerfile +++ b/python3.7-alpine3.7/Dockerfile @@ -181,6 +181,10 @@ ENV NGINX_WORKER_PROCESSES 1 # (in a Dockerfile or with an option for `docker run`) ENV LISTEN_PORT 80 +# Copy start.sh script that will check for a /app/prestart.sh script and run it before starting the app +COPY start.sh /start.sh +RUN chmod +x /start.sh + # Copy the entrypoint that will generate Nginx additional configs COPY entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh @@ -191,4 +195,6 @@ ENTRYPOINT ["sh", "/entrypoint.sh"] COPY ./app /app WORKDIR /app -CMD ["/usr/bin/supervisord"] +# Run the start script, it will check for an /app/prestart.sh script (e.g. for migrations) +# And then will start Supervisor, which in turn will start Nginx and uWSGI +CMD ["/start.sh"] diff --git a/python3.7-alpine3.7/app/prestart.sh b/python3.7-alpine3.7/app/prestart.sh new file mode 100644 index 0000000..9ccb1da --- /dev/null +++ b/python3.7-alpine3.7/app/prestart.sh @@ -0,0 +1,12 @@ +#! /usr/bin/env sh + +echo "Running inside /app/prestart.sh, you could add migrations to this file, e.g.:" + +echo " +#! /usr/bin/env bash + +# Let the DB start +sleep 10; +# Run migrations +alembic upgrade head +" diff --git a/python3.7-alpine3.7/start.sh b/python3.7-alpine3.7/start.sh new file mode 100644 index 0000000..60718f4 --- /dev/null +++ b/python3.7-alpine3.7/start.sh @@ -0,0 +1,15 @@ +#! /usr/bin/env sh +set -e + +# If there's a prestart.sh script in the /app directory, run it before starting +PRE_START_PATH=/app/prestart.sh +echo "Checking for script in $PRE_START_PATH" +if [ -f $PRE_START_PATH ] ; then + echo "Running script $PRE_START_PATH" + . $PRE_START_PATH +else + echo "There is no script $PRE_START_PATH" +fi + +# Start Supervisor, with Nginx and uWSGI +exec /usr/bin/supervisord diff --git a/python3.7-alpine3.8/Dockerfile b/python3.7-alpine3.8/Dockerfile index 3a3f3ca..6247daa 100644 --- a/python3.7-alpine3.8/Dockerfile +++ b/python3.7-alpine3.8/Dockerfile @@ -181,6 +181,10 @@ ENV NGINX_WORKER_PROCESSES 1 # (in a Dockerfile or with an option for `docker run`) ENV LISTEN_PORT 80 +# Copy start.sh script that will check for a /app/prestart.sh script and run it before starting the app +COPY start.sh /start.sh +RUN chmod +x /start.sh + # Copy the entrypoint that will generate Nginx additional configs COPY entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh @@ -191,4 +195,6 @@ ENTRYPOINT ["sh", "/entrypoint.sh"] COPY ./app /app WORKDIR /app -CMD ["/usr/bin/supervisord"] +# Run the start script, it will check for an /app/prestart.sh script (e.g. for migrations) +# And then will start Supervisor, which in turn will start Nginx and uWSGI +CMD ["/start.sh"] diff --git a/python3.7-alpine3.8/app/prestart.sh b/python3.7-alpine3.8/app/prestart.sh new file mode 100644 index 0000000..9ccb1da --- /dev/null +++ b/python3.7-alpine3.8/app/prestart.sh @@ -0,0 +1,12 @@ +#! /usr/bin/env sh + +echo "Running inside /app/prestart.sh, you could add migrations to this file, e.g.:" + +echo " +#! /usr/bin/env bash + +# Let the DB start +sleep 10; +# Run migrations +alembic upgrade head +" diff --git a/python3.7-alpine3.8/start.sh b/python3.7-alpine3.8/start.sh new file mode 100644 index 0000000..60718f4 --- /dev/null +++ b/python3.7-alpine3.8/start.sh @@ -0,0 +1,15 @@ +#! /usr/bin/env sh +set -e + +# If there's a prestart.sh script in the /app directory, run it before starting +PRE_START_PATH=/app/prestart.sh +echo "Checking for script in $PRE_START_PATH" +if [ -f $PRE_START_PATH ] ; then + echo "Running script $PRE_START_PATH" + . $PRE_START_PATH +else + echo "There is no script $PRE_START_PATH" +fi + +# Start Supervisor, with Nginx and uWSGI +exec /usr/bin/supervisord diff --git a/python3.7-alpine3.9/Dockerfile b/python3.7-alpine3.9/Dockerfile index db34e67..b83604d 100644 --- a/python3.7-alpine3.9/Dockerfile +++ b/python3.7-alpine3.9/Dockerfile @@ -181,6 +181,10 @@ ENV NGINX_WORKER_PROCESSES 1 # (in a Dockerfile or with an option for `docker run`) ENV LISTEN_PORT 80 +# Copy start.sh script that will check for a /app/prestart.sh script and run it before starting the app +COPY start.sh /start.sh +RUN chmod +x /start.sh + # Copy the entrypoint that will generate Nginx additional configs COPY entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh @@ -191,4 +195,6 @@ ENTRYPOINT ["sh", "/entrypoint.sh"] COPY ./app /app WORKDIR /app -CMD ["/usr/bin/supervisord"] +# Run the start script, it will check for an /app/prestart.sh script (e.g. for migrations) +# And then will start Supervisor, which in turn will start Nginx and uWSGI +CMD ["/start.sh"] diff --git a/python3.7-alpine3.9/app/prestart.sh b/python3.7-alpine3.9/app/prestart.sh new file mode 100644 index 0000000..9ccb1da --- /dev/null +++ b/python3.7-alpine3.9/app/prestart.sh @@ -0,0 +1,12 @@ +#! /usr/bin/env sh + +echo "Running inside /app/prestart.sh, you could add migrations to this file, e.g.:" + +echo " +#! /usr/bin/env bash + +# Let the DB start +sleep 10; +# Run migrations +alembic upgrade head +" diff --git a/python3.7-alpine3.9/start.sh b/python3.7-alpine3.9/start.sh new file mode 100644 index 0000000..60718f4 --- /dev/null +++ b/python3.7-alpine3.9/start.sh @@ -0,0 +1,15 @@ +#! /usr/bin/env sh +set -e + +# If there's a prestart.sh script in the /app directory, run it before starting +PRE_START_PATH=/app/prestart.sh +echo "Checking for script in $PRE_START_PATH" +if [ -f $PRE_START_PATH ] ; then + echo "Running script $PRE_START_PATH" + . $PRE_START_PATH +else + echo "There is no script $PRE_START_PATH" +fi + +# Start Supervisor, with Nginx and uWSGI +exec /usr/bin/supervisord diff --git a/python3.7/Dockerfile b/python3.7/Dockerfile index b286959..1875865 100644 --- a/python3.7/Dockerfile +++ b/python3.7/Dockerfile @@ -139,6 +139,10 @@ ENV NGINX_WORKER_PROCESSES 1 # (in a Dockerfile or with an option for `docker run`) ENV LISTEN_PORT 80 +# Copy start.sh script that will check for a /app/prestart.sh script and run it before starting the app +COPY start.sh /start.sh +RUN chmod +x /start.sh + # Copy the entrypoint that will generate Nginx additional configs COPY entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh @@ -149,4 +153,6 @@ ENTRYPOINT ["/entrypoint.sh"] COPY ./app /app WORKDIR /app -CMD ["/usr/bin/supervisord"] +# Run the start script, it will check for an /app/prestart.sh script (e.g. for migrations) +# And then will start Supervisor, which in turn will start Nginx and uWSGI +CMD ["/start.sh"] diff --git a/python3.7/app/prestart.sh b/python3.7/app/prestart.sh new file mode 100644 index 0000000..9ccb1da --- /dev/null +++ b/python3.7/app/prestart.sh @@ -0,0 +1,12 @@ +#! /usr/bin/env sh + +echo "Running inside /app/prestart.sh, you could add migrations to this file, e.g.:" + +echo " +#! /usr/bin/env bash + +# Let the DB start +sleep 10; +# Run migrations +alembic upgrade head +" diff --git a/python3.7/start.sh b/python3.7/start.sh new file mode 100644 index 0000000..60718f4 --- /dev/null +++ b/python3.7/start.sh @@ -0,0 +1,15 @@ +#! /usr/bin/env sh +set -e + +# If there's a prestart.sh script in the /app directory, run it before starting +PRE_START_PATH=/app/prestart.sh +echo "Checking for script in $PRE_START_PATH" +if [ -f $PRE_START_PATH ] ; then + echo "Running script $PRE_START_PATH" + . $PRE_START_PATH +else + echo "There is no script $PRE_START_PATH" +fi + +# Start Supervisor, with Nginx and uWSGI +exec /usr/bin/supervisord From 656026f39b69069a69d13176e976449acef09e20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Fri, 10 May 2019 16:01:58 +0400 Subject: [PATCH 2/2] :white_check_mark: Add custom prestart script tests --- tests/test_01_main/test_defaults.py | 5 +++++ tests/test_01_main/test_env_vars_1.py | 5 +++++ tests/test_02_app/custom_app/latest.dockerfile | 1 + tests/test_02_app/custom_app/prestart.sh | 2 ++ tests/test_02_app/custom_app/python2.7-alpine3.7.dockerfile | 1 + tests/test_02_app/custom_app/python2.7-alpine3.8.dockerfile | 1 + tests/test_02_app/custom_app/python2.7-alpine3.9.dockerfile | 1 + tests/test_02_app/custom_app/python2.7.dockerfile | 1 + tests/test_02_app/custom_app/python3.5.dockerfile | 1 + tests/test_02_app/custom_app/python3.6-alpine3.7.dockerfile | 1 + tests/test_02_app/custom_app/python3.6-alpine3.8.dockerfile | 1 + tests/test_02_app/custom_app/python3.6-alpine3.9.dockerfile | 1 + tests/test_02_app/custom_app/python3.6.dockerfile | 1 + tests/test_02_app/custom_app/python3.7-alpine3.7.dockerfile | 1 + tests/test_02_app/custom_app/python3.7-alpine3.8.dockerfile | 1 + tests/test_02_app/custom_app/python3.7-alpine3.9.dockerfile | 1 + tests/test_02_app/custom_app/python3.7.dockerfile | 1 + tests/test_02_app/test_app_and_env_vars.py | 3 +++ tests/test_02_app/test_custom_nginx_app.py | 5 +++++ tests/test_02_app/test_simple_app.py | 5 +++++ 20 files changed, 39 insertions(+) create mode 100644 tests/test_02_app/custom_app/prestart.sh diff --git a/tests/test_01_main/test_defaults.py b/tests/test_01_main/test_defaults.py index e3eef70..b84308d 100644 --- a/tests/test_01_main/test_defaults.py +++ b/tests/test_01_main/test_defaults.py @@ -40,6 +40,11 @@ def verify_container(container, response_text): assert "wsgi-file = /app/main.py" in logs assert "processes = 16" in logs assert "cheaper = 2" in logs + assert "Checking for script in /app/prestart.sh" in logs + assert "Running script /app/prestart.sh" in logs + assert ( + "Running inside /app/prestart.sh, you could add migrations to this file" in logs + ) assert "spawned uWSGI master process" in logs assert "spawned uWSGI worker 1" in logs assert "spawned uWSGI worker 2" in logs diff --git a/tests/test_01_main/test_env_vars_1.py b/tests/test_01_main/test_env_vars_1.py index 35e9705..0eb80d9 100644 --- a/tests/test_01_main/test_env_vars_1.py +++ b/tests/test_01_main/test_env_vars_1.py @@ -40,6 +40,11 @@ def verify_container(container, response_text): assert "wsgi-file = /app/main.py" in logs assert "processes = 8" in logs assert "cheaper = 3" in logs + assert "Checking for script in /app/prestart.sh" in logs + assert "Running script /app/prestart.sh" in logs + assert ( + "Running inside /app/prestart.sh, you could add migrations to this file" in logs + ) assert "spawned uWSGI master process" in logs assert "spawned uWSGI worker 1" in logs assert "spawned uWSGI worker 2" in logs diff --git a/tests/test_02_app/custom_app/latest.dockerfile b/tests/test_02_app/custom_app/latest.dockerfile index b88cae6..f24c6a5 100644 --- a/tests/test_02_app/custom_app/latest.dockerfile +++ b/tests/test_02_app/custom_app/latest.dockerfile @@ -1,6 +1,7 @@ FROM tiangolo/uwsgi-nginx:latest COPY ./application /application +COPY ./prestart.sh /app/prestart.sh WORKDIR /application EXPOSE 8080 diff --git a/tests/test_02_app/custom_app/prestart.sh b/tests/test_02_app/custom_app/prestart.sh new file mode 100644 index 0000000..72d7a76 --- /dev/null +++ b/tests/test_02_app/custom_app/prestart.sh @@ -0,0 +1,2 @@ +#! /usr/bin/env bash +echo "custom prestart.sh running" diff --git a/tests/test_02_app/custom_app/python2.7-alpine3.7.dockerfile b/tests/test_02_app/custom_app/python2.7-alpine3.7.dockerfile index 7fe44c4..1e5f280 100644 --- a/tests/test_02_app/custom_app/python2.7-alpine3.7.dockerfile +++ b/tests/test_02_app/custom_app/python2.7-alpine3.7.dockerfile @@ -1,6 +1,7 @@ FROM tiangolo/uwsgi-nginx:python2.7-alpine3.7 COPY ./application /application +COPY ./prestart.sh /app/prestart.sh WORKDIR /application EXPOSE 8080 diff --git a/tests/test_02_app/custom_app/python2.7-alpine3.8.dockerfile b/tests/test_02_app/custom_app/python2.7-alpine3.8.dockerfile index 023db97..79ac639 100644 --- a/tests/test_02_app/custom_app/python2.7-alpine3.8.dockerfile +++ b/tests/test_02_app/custom_app/python2.7-alpine3.8.dockerfile @@ -1,6 +1,7 @@ FROM tiangolo/uwsgi-nginx:python2.7-alpine3.8 COPY ./application /application +COPY ./prestart.sh /app/prestart.sh WORKDIR /application EXPOSE 8080 diff --git a/tests/test_02_app/custom_app/python2.7-alpine3.9.dockerfile b/tests/test_02_app/custom_app/python2.7-alpine3.9.dockerfile index b436820..17181f8 100644 --- a/tests/test_02_app/custom_app/python2.7-alpine3.9.dockerfile +++ b/tests/test_02_app/custom_app/python2.7-alpine3.9.dockerfile @@ -1,6 +1,7 @@ FROM tiangolo/uwsgi-nginx:python2.7-alpine3.9 COPY ./application /application +COPY ./prestart.sh /app/prestart.sh WORKDIR /application EXPOSE 8080 diff --git a/tests/test_02_app/custom_app/python2.7.dockerfile b/tests/test_02_app/custom_app/python2.7.dockerfile index 21204cc..188926b 100644 --- a/tests/test_02_app/custom_app/python2.7.dockerfile +++ b/tests/test_02_app/custom_app/python2.7.dockerfile @@ -1,6 +1,7 @@ FROM tiangolo/uwsgi-nginx:python2.7 COPY ./application /application +COPY ./prestart.sh /app/prestart.sh WORKDIR /application EXPOSE 8080 diff --git a/tests/test_02_app/custom_app/python3.5.dockerfile b/tests/test_02_app/custom_app/python3.5.dockerfile index f35f790..b4dbae8 100644 --- a/tests/test_02_app/custom_app/python3.5.dockerfile +++ b/tests/test_02_app/custom_app/python3.5.dockerfile @@ -1,6 +1,7 @@ FROM tiangolo/uwsgi-nginx:python3.5 COPY ./application /application +COPY ./prestart.sh /app/prestart.sh WORKDIR /application EXPOSE 8080 diff --git a/tests/test_02_app/custom_app/python3.6-alpine3.7.dockerfile b/tests/test_02_app/custom_app/python3.6-alpine3.7.dockerfile index 5c0a52a..09f09fa 100644 --- a/tests/test_02_app/custom_app/python3.6-alpine3.7.dockerfile +++ b/tests/test_02_app/custom_app/python3.6-alpine3.7.dockerfile @@ -1,6 +1,7 @@ FROM tiangolo/uwsgi-nginx:python3.6-alpine3.7 COPY ./application /application +COPY ./prestart.sh /app/prestart.sh WORKDIR /application EXPOSE 8080 diff --git a/tests/test_02_app/custom_app/python3.6-alpine3.8.dockerfile b/tests/test_02_app/custom_app/python3.6-alpine3.8.dockerfile index 075fbe4..bb2cd77 100644 --- a/tests/test_02_app/custom_app/python3.6-alpine3.8.dockerfile +++ b/tests/test_02_app/custom_app/python3.6-alpine3.8.dockerfile @@ -1,6 +1,7 @@ FROM tiangolo/uwsgi-nginx:python3.6-alpine3.8 COPY ./application /application +COPY ./prestart.sh /app/prestart.sh WORKDIR /application EXPOSE 8080 diff --git a/tests/test_02_app/custom_app/python3.6-alpine3.9.dockerfile b/tests/test_02_app/custom_app/python3.6-alpine3.9.dockerfile index 96434e3..70e0fae 100644 --- a/tests/test_02_app/custom_app/python3.6-alpine3.9.dockerfile +++ b/tests/test_02_app/custom_app/python3.6-alpine3.9.dockerfile @@ -1,6 +1,7 @@ FROM tiangolo/uwsgi-nginx:python3.6-alpine3.9 COPY ./application /application +COPY ./prestart.sh /app/prestart.sh WORKDIR /application EXPOSE 8080 diff --git a/tests/test_02_app/custom_app/python3.6.dockerfile b/tests/test_02_app/custom_app/python3.6.dockerfile index 6c2a624..227bcf7 100644 --- a/tests/test_02_app/custom_app/python3.6.dockerfile +++ b/tests/test_02_app/custom_app/python3.6.dockerfile @@ -1,6 +1,7 @@ FROM tiangolo/uwsgi-nginx:python3.6 COPY ./application /application +COPY ./prestart.sh /app/prestart.sh WORKDIR /application EXPOSE 8080 diff --git a/tests/test_02_app/custom_app/python3.7-alpine3.7.dockerfile b/tests/test_02_app/custom_app/python3.7-alpine3.7.dockerfile index 3917ed0..e22d019 100644 --- a/tests/test_02_app/custom_app/python3.7-alpine3.7.dockerfile +++ b/tests/test_02_app/custom_app/python3.7-alpine3.7.dockerfile @@ -1,6 +1,7 @@ FROM tiangolo/uwsgi-nginx:python3.7-alpine3.7 COPY ./application /application +COPY ./prestart.sh /app/prestart.sh WORKDIR /application EXPOSE 8080 diff --git a/tests/test_02_app/custom_app/python3.7-alpine3.8.dockerfile b/tests/test_02_app/custom_app/python3.7-alpine3.8.dockerfile index a47a5b8..14bd813 100644 --- a/tests/test_02_app/custom_app/python3.7-alpine3.8.dockerfile +++ b/tests/test_02_app/custom_app/python3.7-alpine3.8.dockerfile @@ -1,6 +1,7 @@ FROM tiangolo/uwsgi-nginx:python3.7-alpine3.8 COPY ./application /application +COPY ./prestart.sh /app/prestart.sh WORKDIR /application EXPOSE 8080 diff --git a/tests/test_02_app/custom_app/python3.7-alpine3.9.dockerfile b/tests/test_02_app/custom_app/python3.7-alpine3.9.dockerfile index ad2ef02..e5d34d0 100644 --- a/tests/test_02_app/custom_app/python3.7-alpine3.9.dockerfile +++ b/tests/test_02_app/custom_app/python3.7-alpine3.9.dockerfile @@ -1,6 +1,7 @@ FROM tiangolo/uwsgi-nginx:python3.7-alpine3.9 COPY ./application /application +COPY ./prestart.sh /app/prestart.sh WORKDIR /application EXPOSE 8080 diff --git a/tests/test_02_app/custom_app/python3.7.dockerfile b/tests/test_02_app/custom_app/python3.7.dockerfile index 21874c3..5c8adf9 100644 --- a/tests/test_02_app/custom_app/python3.7.dockerfile +++ b/tests/test_02_app/custom_app/python3.7.dockerfile @@ -1,6 +1,7 @@ FROM tiangolo/uwsgi-nginx:python3.7 COPY ./application /application +COPY ./prestart.sh /app/prestart.sh WORKDIR /application EXPOSE 8080 diff --git a/tests/test_02_app/test_app_and_env_vars.py b/tests/test_02_app/test_app_and_env_vars.py index 473c0d1..164dad7 100644 --- a/tests/test_02_app/test_app_and_env_vars.py +++ b/tests/test_02_app/test_app_and_env_vars.py @@ -40,6 +40,9 @@ def verify_container(container, response_text): assert "wsgi-file = /application/custom_app/main.py" in logs assert "processes = 16" in logs assert "cheaper = 2" in logs + assert "Checking for script in /app/prestart.sh" in logs + assert "Running script /app/prestart.sh" in logs + assert "custom prestart.sh running" in logs assert "spawned uWSGI master process" in logs assert "spawned uWSGI worker 1" in logs assert "spawned uWSGI worker 2" in logs diff --git a/tests/test_02_app/test_custom_nginx_app.py b/tests/test_02_app/test_custom_nginx_app.py index 906cf36..1cc3557 100644 --- a/tests/test_02_app/test_custom_nginx_app.py +++ b/tests/test_02_app/test_custom_nginx_app.py @@ -41,6 +41,11 @@ def verify_container(container, response_text): assert "wsgi-file = /app/main.py" in logs assert "processes = 16" in logs assert "cheaper = 2" in logs + assert "Checking for script in /app/prestart.sh" in logs + assert "Running script /app/prestart.sh" in logs + assert ( + "Running inside /app/prestart.sh, you could add migrations to this file" in logs + ) assert "spawned uWSGI master process" in logs assert "spawned uWSGI worker 1" in logs assert "spawned uWSGI worker 2" in logs diff --git a/tests/test_02_app/test_simple_app.py b/tests/test_02_app/test_simple_app.py index 5044176..01c8cf9 100644 --- a/tests/test_02_app/test_simple_app.py +++ b/tests/test_02_app/test_simple_app.py @@ -40,6 +40,11 @@ def verify_container(container, response_text): assert "wsgi-file = /app/main.py" in logs assert "processes = 16" in logs assert "cheaper = 2" in logs + assert "Checking for script in /app/prestart.sh" in logs + assert "Running script /app/prestart.sh" in logs + assert ( + "Running inside /app/prestart.sh, you could add migrations to this file" in logs + ) assert "spawned uWSGI master process" in logs assert "spawned uWSGI worker 1" in logs assert "spawned uWSGI worker 2" in logs