Skip to content

Commit

Permalink
🔧 update conf files
Browse files Browse the repository at this point in the history
  • Loading branch information
bunop committed Feb 10, 2023
1 parent e34d8d2 commit 7692c94
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 4 deletions.
2 changes: 1 addition & 1 deletion compose/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ names and ports according your needs. Build and provide a service using the
Projects hosted in this repository:

* composetest: `docker-compose` tutorial
* django: composed image of `django`, `nginx` and `mysql` (or `postgres`)
* django: composed image of `django`, `nginx` and `mysql`
* gbrowse: composed image of `mysql` and `gbrowse2`
* gitlab: `gitlab` Community Edition image
* mysql: composed image of `mysql`, `nginx` and `php-fpm` serving `phpmyadmin`
Expand Down
3 changes: 2 additions & 1 deletion compose/django/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ services:
uwsgi:
# a custom image for django
build:
# required to include poetry stuff into uwsgi image
context: .
dockerfile: uwsgi/Dockerfile

Expand All @@ -35,7 +36,7 @@ services:
DEBUG: ${DEBUG}

# exec a different command from image
command: uwsgi --ini /var/uwsgi/mysite_uwsgi.ini
command: uwsgi --ini /var/uwsgi/mysite_uwsgi.ini --memory-report

# set working dir for uwsgi
working_dir: /var/uwsgi/
Expand Down
5 changes: 5 additions & 0 deletions compose/django/nginx/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ FROM nginx:1.23
# MAINTAINER is deprecated. Use LABEL instead
LABEL maintainer="[email protected]"

# synchronize timezone for container
# https://forums.docker.com/t/synchronize-timezone-from-host-to-container/39116
RUN echo "Europe/Rome" > /etc/timezone
RUN dpkg-reconfigure -f noninteractive tzdata

# Copy nginx configuration file in conf.d directory
COPY nginx.conf /etc/nginx/nginx.conf

Expand Down
7 changes: 5 additions & 2 deletions compose/django/nginx/conf.d/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ server {
return 404;
}


# Django media
location /mysite/media/ {
# your Django project's media files - amend as required. The final / is important
Expand All @@ -107,7 +106,11 @@ server {
include uwsgi_params;

# calling uwsgi script in mysite directory
# this is REQUIRED when using sublocation (ie http://localhost/mysite as index)
uwsgi_param SCRIPT_NAME /mysite;
}

# Setting timeout
uwsgi_read_timeout 120;
uwsgi_send_timeout 120;
}
}
13 changes: 13 additions & 0 deletions compose/django/uwsgi/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,20 @@ RUN poetry install

from python:${PYTHON_VERSION}-slim

# MAINTAINER is deprecated. Use LABEL instead
LABEL maintainer="[email protected]"

# Import ARGs which I need in this build stage
# IMPORTANT!: without this redefinition, you can't use variables defined
# before the first FROM statement
ARG APP_PATH
ARG VIRTUAL_ENV=${APP_PATH}/.venv

# synchronize timezone for container
# https://forums.docker.com/t/synchronize-timezone-from-host-to-container/39116
RUN echo "Europe/Rome" > /etc/timezone
RUN dpkg-reconfigure -f noninteractive tzdata

# install required packages
RUN apt-get update && apt-get install -y \
libmariadb3 \
Expand All @@ -83,6 +91,11 @@ ENV \
VIRTUAL_ENV=${VIRTUAL_ENV} \
PATH="${VIRTUAL_ENV}/bin:${PATH}"

# utility script to ensure that mysql server is up
# mind to the context path
COPY uwsgi/wait-for-mysql.sh /usr/local/bin
RUN chmod 755 /usr/local/bin/wait-for-mysql.sh

# copy the application from build stage
COPY --from=0 ${APP_PATH} ${APP_PATH}
WORKDIR ${APP_PATH}
Expand Down
26 changes: 26 additions & 0 deletions compose/django/uwsgi/wait-for-mysql.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
# wait-for-mysql.sh
# https://docs.docker.com/compose/startup-order/
# adapted from https://raw.githubusercontent.com/agileek/docker/master/tomcat/wait-for-mysql.sh

set -e
set -x

cmd="$@"

NEXT_WAIT_TIME=0
MAX_STEPS=6

until mysql -h db -u ${SHINY_USER} -p${SHINY_PASSWORD} ${SHINY_DATABASE} -e 'select 1' || [ ${NEXT_WAIT_TIME} -eq ${MAX_STEPS} ]; do
>&2 echo "MySQL is unavailable - sleeping"
sleep 5
NEXT_WAIT_TIME=$((NEXT_WAIT_TIME+1))
done

if [ ${NEXT_WAIT_TIME} -eq ${MAX_STEPS} ]; then
>&2 echo "Problem in waiting MySQL"
exit 1;
fi

>&2 echo "MySQL is up - executing command"
exec $cmd

0 comments on commit 7692c94

Please sign in to comment.