Skip to content

Commit

Permalink
Docker packaging
Browse files Browse the repository at this point in the history
It is useless to resist
  • Loading branch information
aleksihakli committed Aug 5, 2019
1 parent fec2138 commit 5224cdd
Show file tree
Hide file tree
Showing 44 changed files with 195 additions and 361 deletions.
3 changes: 0 additions & 3 deletions .bowerrc

This file was deleted.

12 changes: 12 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/virtualenv
/venv
/results
/etc
**.pyc
__pycache__
.env
.git
db.sqlite3
Makefile
Dockerfile
.coverage
1 change: 0 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ indent_style = space
[*.{js,py}]
indent_size = 4

# Matches the exact files either package.json or .travis.yml
[{*.json,*.yml}]
indent_size = 2
48 changes: 48 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
FROM python:3.7

EXPOSE 8888

ENV DJANGO_SETTINGS_MODULE="config.settings.docker"

ARG DJANGO_SECRET_KEY="notneededforbuilds"
ARG DATABASE_URL="postgres://not@neededforbuilds"
ARG MODEEMIUSERDB_URL="postgres://not@neededforbuilds"
ARG RECAPTCHA_PUBLIC_KEY="notneededforbuilds"
ARG RECAPTCHA_PRIVATE_KEY="notneededforbuilds"

COPY scripts/entrypoint /usr/local/bin/entrypoint
RUN chmod a+x /usr/local/bin/entrypoint

WORKDIR /app

ADD requirements.txt /app/requirements.txt
RUN python -m pip install --no-cache-dir -r requirements.txt

ADD . /app/

RUN python manage.py collectstatic --noinput

RUN groupadd -g 1001 modeemintternet
RUN useradd -u 1001 -g 1001 -d /app modeemintternet
USER modeemintternet

ENTRYPOINT ["/usr/local/bin/entrypoint"]
CMD [ \
"gunicorn", \
"--name", \
"modeemintternet", \
"--access-logfile", \
"-", \
"--access-logform", \
"%({X-Forwarded-For}i)s %(l)s %(u)s %(t)s '%(r)s' %(s)s %(b)s '%(f)s' '%(a)s'", \
"--log-level", \
"info", \
"--workers", \
"2", \
"--bind", \
"0.0.0.0:8888", \
"config.wsgi:application" \
]

ARG RELEASE
ENV RELEASE=${RELEASE}
28 changes: 28 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
RELEASE := $$(git show -s --format=%H)
IMAGE := modeemi/intternetvelho

test:
@echo "Running tests and linters"
python manage.py test

build:
docker build --build-arg RELEASE=${RELEASE} -t ${IMAGE} .

run:
docker run ${IMAGE}

push:
docker push ${IMAGE}

pull:
docker pull ${IMAGE}

default:
make test

all:
make test
make build
make push

.PHONY: all default test build push pull run
39 changes: 0 additions & 39 deletions bower.json

This file was deleted.

37 changes: 28 additions & 9 deletions config/settings/base.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
# -*- coding: utf-8 -*-

"""
Django settings for modeemintternet project.
For more information on this file, see
https://docs.djangoproject.com/en/1.8/topics/settings/
"""

from __future__ import unicode_literals

import warnings

import environ


PROJECT_ROOT = environ.Path(__file__) - 3 # type: environ.Path
PROJECT_DIR = PROJECT_ROOT.path('modeemintternet')

Expand All @@ -23,9 +20,6 @@
env.read_env('.env')
env.read_env('/etc/modeemintternet/env')

# Quick-start settings, check for deployment
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/

DEBUG = env('DJANGO_DEBUG', cast=bool, default=False)
ROOT_URLCONF = 'config.urls'
WSGI_APPLICATION = 'config.wsgi.application'
Expand Down Expand Up @@ -89,7 +83,6 @@
USE_TZ = True

STATICFILES_DIRS = (
PROJECT_ROOT('vendor'),
PROJECT_DIR('static'),
)

Expand All @@ -109,14 +102,16 @@

'crispy_forms',
'rest_framework',
'raven.contrib.django.raven_compat',
'snowpenguin.django.recaptcha2',

'modeemintternet',
)

MIDDLEWARE = (
'django.middleware.security.SecurityMiddleware',

'whitenoise.middleware.WhiteNoiseMiddleware',

'django.middleware.cache.UpdateCacheMiddleware',
'django.middleware.http.ConditionalGetMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
Expand Down Expand Up @@ -152,4 +147,28 @@
},
]

LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'console': {
'class': 'logging.StreamHandler',
},
},
'loggers': {
'': {
'handlers': ['console'],
'level': env('DJANGO_LOG_LEVEL', default='INFO'),
},
'django': {
'handlers': ['console'],
'level': env('DJANGO_LOG_LEVEL', default='INFO'),
},
'django.request': {
'handlers': ['console'],
'level': env('DJANGO_REQUEST_LOG_LEVEL', default='INFO'),
},
},
}

CRISPY_TEMPLATE_PACK = 'bootstrap3'
4 changes: 4 additions & 0 deletions config/settings/docker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .production import * # noqa


STATIC_ROOT = '/app/static'
3 changes: 0 additions & 3 deletions config/settings/local.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
# -*- coding: utf-8 -*-

import os

from .base import * # noqa

DEBUG = True
SECRET_KEY = env('DJANGO_SECRETKEY', default='thisisthedummydjangosecretkey')


EMAIL_BACKEND = env('DJANGO_EMAIL_BACKEND', default='django.core.mail.backends.console.EmailBackend')

RECAPTCHA_PUBLIC_KEY = env('RECAPTCHA_PUBLIC_KEY', default=None)
Expand Down
23 changes: 6 additions & 17 deletions config/settings/production.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-

import raven
from logging import getLogger

from django.core.exceptions import ImproperlyConfigured
Expand All @@ -19,27 +16,19 @@
RECAPTCHA_PUBLIC_KEY = env('RECAPTCHA_PUBLIC_KEY')
RECAPTCHA_PRIVATE_KEY = env('RECAPTCHA_PRIVATE_KEY')

if len(SECRET_KEY) < 42:
if len(SECRET_KEY) < 18:
raise ImproperlyConfigured('Django SECRET_KEY is too short, length is {}'.format(len(SECRET_KEY)))

# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
DATABASES = {
'default': env.db(),
'modeemiuserdb': env.db('MODEEMIUSERDB_URL'),
}

STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.CachedStaticFilesStorage'
STATICFILES_STORAGE = env(
'DJANGO_STATICFILES_STORAGE',
default='whitenoise.storage.CompressedStaticFilesStorage',
)

STATIC_ROOT = '/var/www/modeemintternet/static'
MEDIA_ROOT = '/var/www/modeemintternet/media'

try:
release = raven.fetch_git_sha(str(PROJECT_ROOT))
except Exception as e:
log.error(e)
release = None

RAVEN_CONFIG = {
'dsn': env('RAVEN_DSN', default=None),
'release': release,
}
4 changes: 0 additions & 4 deletions config/settings/test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-

import os

from .local import * # noqa

SECRET_KEY = env('DJANGO_SECRETKEY', default='thisisthedummydjangosecretkey')
Expand Down
4 changes: 0 additions & 4 deletions config/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-

from __future__ import unicode_literals

from django.urls import include, path
from django.conf.urls.static import static

Expand Down
4 changes: 0 additions & 4 deletions config/wsgi.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-

from __future__ import unicode_literals

import os

from django.core.wsgi import get_wsgi_application
Expand Down
54 changes: 0 additions & 54 deletions etc/apache2/sites-available/www.modeemi.fi

This file was deleted.

Loading

0 comments on commit 5224cdd

Please sign in to comment.