Skip to content

Commit

Permalink
Fix build and enable creation of self-sufficient docker images
Browse files Browse the repository at this point in the history
  • Loading branch information
timthelion committed Aug 25, 2020
1 parent 4e9f4b8 commit 0e0d6dd
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 46 deletions.
12 changes: 4 additions & 8 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,18 @@
.git
env*
db_backup
lib
media
static
scripts
!scripts/batch_generation/download_dispatched_subsidiary_boxes.sh
!scripts/batch_generation/split_csv.sh
!scripts/batch_generation/generate_delivery_batch_pdf.sh
htmlcov
htmlcov-max
sql
db
run
dpnk.log*
project/settings/local.py
amazon_script.sh
make_graph.sh
fabfile.py
cookies.txt
docker.env
third_party/
Dockerfile
.env
pipenv
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/media/
/static/
/env/
.env
*.swp
*.diff
*.rej
Expand Down
11 changes: 9 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
FROM python:3.6
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash -
RUN apt-get -qq update; apt-get -y install nodejs gettext libgettextpo-dev libgraphviz-dev libz-dev libjpeg-dev libfreetype6-dev python-dev gdal-bin python-numpy
RUN apt-get -qq update; apt-get -y install nodejs gettext libgettextpo-dev libgraphviz-dev libz-dev libjpeg-dev libfreetype6-dev python3-dev gdal-bin python-numpy
RUN npm install -g less bower
RUN pip3 install pipenv
RUN useradd test
RUN chsh test -s /bin/bash
RUN mkdir /home/test ; chown test /home/test ; chgrp test /home/test
WORKDIR "/home/test"
copy Pipfile.lock Pipfile.lock
copy Pipfile Pipfile
RUN su test ; cd /home/test ; pipenv install --python python3
copy . .
RUN chown -R test /home/test ; chgrp -R test /home/test
RUN su test ; cd /home/test ; pipenv install --python python3
run mkdir -p /var/log/django
run su test ; cd /home/test ; SECRET_KEY=foo pipenv run python3 manage.py collectstatic --noinput
run su test ; cd /home/test ; SECRET_KEY=foo pipenv run python manage.py collectmedia --noinput
run su test ; cd /home/test ; SECRET_KEY=foo pipenv run python3 manage.py compress
ENTRYPOINT ["./docker-entrypoint.sh"]
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ django = "<3.0"
django-simple-captcha = "*"
asgiref = "*"
django-dotenv = "*"
whitenoise = "*"

[dev-packages]
pudb = "*"
Expand Down
67 changes: 44 additions & 23 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions apps/cyklomapa/templates/mapa.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@

<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
{% compress css file main_css %}
<link rel="stylesheet" href="{% static "jquery-ui/themes/base/jquery-ui.css" %}" type="text/css" />
<link rel="stylesheet" href="{% static "bow/jqueryui/themes/base/jquery-ui.css" %}" type="text/css" />

<link rel="stylesheet" href="{% static "bootstrap/css/bootstrap.min.css" %}" type="text/css" />
<link rel="stylesheet" href="{% static "css/openlayers.css" %}" type="text/css" />
<link rel="stylesheet" href="{% static "css/google.css" %}" type="text/css" />
<link rel="stylesheet" href="{% static "css/layerswitcher.css" %}" type="text/css" />
<link rel="stylesheet" href="{% static "lightbox2/dist/css/lightbox.css" %}" type="text/css" />
<link rel="stylesheet" href="{% static "bow/lightbox/dist/css/lightbox.css" %}" type="text/css" />
<link rel="stylesheet" type="text/css" href="{% static "fluent_comments/css/ajaxcomments.css" %}" />
<link rel="stylesheet" href="{% static "feedback/main.css" %}" type="text/css" />
<link rel="stylesheet" href="{% static "css/prahounakole.less" %}" type="text/less" />
Expand All @@ -26,22 +26,22 @@
{% endcompress %}

{% compress js file main_js %}
<script type="text/javascript" src="{% static "jquery/dist/jquery.min.js" %}"></script>
<script type="text/javascript" src="{% static "bootstrap/dist/js/bootstrap.min.js" %}"></script> <!-- Bootstrap musi byt hned za Jquery, resp, pret tools apod. -->
<script type="text/javascript" src="{% static "bow/jquery/dist/jquery.min.js" %}"></script>
<script type="text/javascript" src="{% static "bow/bootstrap/dist/js/bootstrap.min.js" %}"></script> <!-- Bootstrap musi byt hned za Jquery, resp, pret tools apod. -->
<script type="text/javascript" src="{% static "js/char_parameters.js" %}"></script>
<script type="text/javascript" src="{% static "js/OpenLayers.PNK.js" %}"></script>
<script type="text/javascript" src="{% static "bow/openlayers/OpenLayers.PNK.js" %}"></script>
<script type="text/javascript" src="{% static "js/OpenStreetMap.js" %}"></script>
<script type="text/javascript" src="{% static "js/cs-CZ.js" %}"></script>
<script type="text/javascript" src="{% static "js/search.js" %}"></script>
<script type="text/javascript" src="{% static "js/csapi.js" %}"></script>
<script type="text/javascript" src="{% static "js/mapa.js" %}"></script>
<script type="text/javascript" src="{% static "jquery-ui/jquery-ui.min.js" %}"></script>
<script type="text/javascript" src="{% static "bow/jqueryui/jquery-ui.min.js" %}"></script>
<script type="text/javascript" src="{% static "js/main-page.js" %}"></script>
<script type="text/javascript" src="{% static "lightbox2/dist/js/lightbox.min.js" %}"></script>
<script type="text/javascript" src="{% static "jquery-persist/jquery-persist.js" %}"></script>
<script type="text/javascript" src="{% static "bow/lightbox/dist/js/lightbox.min.js" %}"></script>
<script type="text/javascript" src="{% static "bow/jquery-persist/jquery-persist.js" %}"></script>
<script type="text/javascript" src="{% static "feedback/jquery.form.js" %}"></script>
<script type="text/javascript" src="{% static "feedback/main.js" %}"></script>
<script type="text/javascript" src="{% static "css-browser-selector/css_browser_selector.js" %}"></script>
<script type="text/javascript" src="{% static "bow/css-browser-selector/css_browser_selector.js" %}"></script>
{% endcompress %}
<script type="text/javascript" src="https://cdn.ravenjs.com/2.2.0/raven.min.js"></script>
<script>if(typeof Raven !== 'undefined'){Raven.config('{% sentry_public_dsn %}').install()}</script>
Expand Down
1 change: 0 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ version: '2'
services:
web:
build: .
entrypoint: /bin/bash
ports:
- "8033:8000"
links:
Expand Down
13 changes: 13 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
echo Starting Gunicorn.
echo $DJANGO_SETTINGS_MODULE
exec pipenv run gunicorn wsgi:application \
--name mapapnk \
--bind 0.0.0.0:${GUNICORN_PORT:-"8000"} \
--workers ${GUNICORN_NUM_WORKERS:-"2"} \
--timeout ${GUNICORN_TIMEOUT:-"60"} \
--preload \
--log-level=debug \
--log-file=- \
--access-logfile=- \
"$@"
6 changes: 3 additions & 3 deletions project/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def normpath(*args):
'USER': os.environ.get("DB_USER", 'pnk'),
'PASSWORD': os.environ.get("DB_PASSWORD", 'foobar'),
'HOST': os.environ.get("DB_HOST", 'postgres'),
'PORT': '',
'PORT': os.environ.get("DB_PORT", ''),
},
}

Expand Down Expand Up @@ -98,6 +98,7 @@ def normpath(*args):

MIDDLEWARE = (
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'raven.contrib.django.raven_compat.middleware.Sentry404CatchMiddleware',
'django.middleware.common.CommonMiddleware',
Expand Down Expand Up @@ -355,8 +356,7 @@ def normpath(*args):
CSRF_COOKIE_SECURE = True
SECURE_BROWSER_XSS_FILTER = True
SECURE_CONTENT_TYPE_NOSNIFF = True
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTOCOL', 'https')
SECURE_SSL_REDIRECT = True
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
SECURE_HSTS_SECONDS = 60
SECURE_HSTS_PRELOAD = True
SESSION_COOKIE_SECURE = True
Expand Down

0 comments on commit 0e0d6dd

Please sign in to comment.