diff --git a/Dockerfile b/Dockerfile index 9746730..bdb0e4a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:14.04 +FROM ubuntu:16.04 # Enable production settings by default; for development, this can be set to # `false` in `docker run --env` @@ -17,16 +17,15 @@ RUN apt-get update && apt-get install -y \ libmysqlclient-dev \ mysql-server \ nginx \ - python-dev \ - python-mysqldb \ - python-setuptools \ + python3-dev \ + python3-mysqldb \ + python3-setuptools \ supervisor \ vim -RUN easy_install pip +RUN easy_install3 pip -# Handle urllib3 InsecurePlatformWarning -RUN apt-get install -y libffi-dev libssl-dev libpython2.7-dev -RUN pip install urllib3[security] requests[security] ndg-httpsclient pyasn1 +# Install Python libraries +RUN pip3 install urllib3 requests[security] ndg-httpsclient pyasn1 # Configure Django project ADD . /code @@ -36,7 +35,7 @@ RUN mkdir /logs RUN mkdir /logs/nginx RUN mkdir /logs/gunicorn WORKDIR /code -RUN pip install -r requirements.txt +RUN pip3 install -r requirements.txt RUN chmod ug+x /code/initialize.sh # Expose ports diff --git a/django_docker/db.sqlite3 b/django_docker/db.sqlite3 deleted file mode 100644 index a1a057f..0000000 Binary files a/django_docker/db.sqlite3 and /dev/null differ diff --git a/django_docker/django_docker/settings.py b/django_docker/django_docker/settings.py index 8f1901b..0ef0e60 100644 --- a/django_docker/django_docker/settings.py +++ b/django_docker/django_docker/settings.py @@ -1,73 +1,111 @@ """ -Django settings for django_docker project. +Django settings for django-docker project. + +Generated by 'django-admin startproject' using Django 2.0.2. For more information on this file, see -https://docs.djangoproject.com/en/1.6/topics/settings/ +https://docs.djangoproject.com/en/2.0/topics/settings/ For the full list of settings and their values, see -https://docs.djangoproject.com/en/1.6/ref/settings/ +https://docs.djangoproject.com/en/2.0/ref/settings/ """ -# Build paths inside the project like this: os.path.join(BASE_DIR, ...) import os -BASE_DIR = os.path.dirname(os.path.dirname(__file__)) + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # Quick-start development settings - unsuitable for production -# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/ +# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = 'w5-iqfj^5cl6tj0_8*xmgnj5r^@&p@n+)=6g1-!^i0&sohyicg' +SECRET_KEY = 'v#2ucc=3gt!((n96ngvk&5272+igyx-pwboe%zkjc+03k)=o4a' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True ALLOWED_HOSTS = ['*'] + # Application definition -INSTALLED_APPS = ( +INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', - 'hello_world', -) +] -MIDDLEWARE_CLASSES = ( +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', -) +] ROOT_URLCONF = 'django_docker.urls' +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [os.path.join(BASE_DIR, 'templates')], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + WSGI_APPLICATION = 'django_docker.wsgi.application' # Database -# https://docs.djangoproject.com/en/1.6/ref/settings/#databases +# https://docs.djangoproject.com/en/2.0/ref/settings/#databases DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. - 'NAME': 'devdb', # Or path to database file if using sqlite3. - # The following settings are not used with sqlite3: + 'ENGINE': 'django.db.backends.mysql', + 'NAME': 'devdb', 'USER': 'devuser', - 'PASSWORD': 'devpass', # Entered via fab command; leave blank if using SQLite - 'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP. - 'PORT': '', # Set to empty string for default. + 'PASSWORD': 'devpass', + 'HOST': '', + 'PORT': '', } } +# Password validation +# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + # Internationalization -# https://docs.djangoproject.com/en/1.6/topics/i18n/ +# https://docs.djangoproject.com/en/2.0/topics/i18n/ LANGUAGE_CODE = 'en-us' @@ -81,41 +119,6 @@ # Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/1.6/howto/static-files/ +# https://docs.djangoproject.com/en/2.0/howto/static-files/ STATIC_URL = '/static/' - -STATICFILES_DIRS = ( - os.path.join(BASE_DIR, "static"), -) - -STATIC_ROOT = '/static/'; - -TEMPLATES = [ - { - 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [ - os.path.join(BASE_DIR, 'templates'), - ], - 'APP_DIRS': True, - 'OPTIONS': { - 'context_processors': [ - # Insert your TEMPLATE_CONTEXT_PROCESSORS here or use this - # list if you haven't customized them: - 'django.contrib.auth.context_processors.auth', - 'django.template.context_processors.debug', - 'django.template.context_processors.i18n', - 'django.template.context_processors.media', - 'django.template.context_processors.static', - 'django.template.context_processors.tz', - 'django.contrib.messages.context_processors.messages', - ], - 'debug': True, - }, - }, -] - -# Import production settings if the environment variable DJANGO_PRODUCTION is true -# (It's set to True by default in the Dockerfile, but you can override it with `docker run` for development) -if os.environ['DJANGO_PRODUCTION'] == 'true': - from settings_production import * diff --git a/django_docker/django_docker/settings_production.py b/django_docker/django_docker/settings_production.py deleted file mode 100644 index ea5a937..0000000 --- a/django_docker/django_docker/settings_production.py +++ /dev/null @@ -1,21 +0,0 @@ -# see https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/ -ALLOWED_HOSTS = ['*'] -DEBUG = False - -# The values below are loaded from environment variables -import os - -SECRET_KEY = os.environ['SECRET_KEY'] - -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. - 'NAME': os.environ['DATABASE_NAME'], # Or path to database file if using sqlite3. - # The following settings are not used with sqlite3: - 'USER': os.environ['DATABASE_USERNAME'], - 'PASSWORD': os.environ['DATABASE_PASSWORD'], # Entered via fab command; leave blank if using SQLite - 'HOST': os.environ['DATABASE_HOST'], # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP. - 'PORT': '', # Set to empty string for default. - } -} - diff --git a/django_docker/django_docker/urls.py b/django_docker/django_docker/urls.py index e8763d9..52c6605 100644 --- a/django_docker/django_docker/urls.py +++ b/django_docker/django_docker/urls.py @@ -1,10 +1,21 @@ -from django.conf.urls import include, url -from hello_world import views as hello_world_views +"""django_docker URL Configuration +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/2.0/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" from django.contrib import admin -admin.autodiscover() +from django.urls import path urlpatterns = [ - url(r'^admin/', include(admin.site.urls)), - url(r'^$', hello_world_views.hello_world, name='hello_world'), + path('admin/', admin.site.urls), ] diff --git a/django_docker/django_docker/views.py b/django_docker/django_docker/views.py deleted file mode 100644 index ecb0ce3..0000000 --- a/django_docker/django_docker/views.py +++ /dev/null @@ -1,4 +0,0 @@ -from django.http import render - -def hello_world(request): - return render(request, 'hello_world/index.html') diff --git a/django_docker/django_docker/wsgi.py b/django_docker/django_docker/wsgi.py index 605b5f6..6422d34 100644 --- a/django_docker/django_docker/wsgi.py +++ b/django_docker/django_docker/wsgi.py @@ -1,14 +1,16 @@ """ -WSGI config for django_docker project. +WSGI config for django-docker project. It exposes the WSGI callable as a module-level variable named ``application``. For more information on this file, see -https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/ +https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/ """ import os -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_docker.settings") from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_docker.settings") + application = get_wsgi_application() diff --git a/django_docker/hello_world/__init__.py b/django_docker/hello_world/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/django_docker/hello_world/admin.py b/django_docker/hello_world/admin.py deleted file mode 100644 index 8c38f3f..0000000 --- a/django_docker/hello_world/admin.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.contrib import admin - -# Register your models here. diff --git a/django_docker/hello_world/models.py b/django_docker/hello_world/models.py deleted file mode 100644 index 71a8362..0000000 --- a/django_docker/hello_world/models.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.db import models - -# Create your models here. diff --git a/django_docker/hello_world/templates/hello_world/index.html b/django_docker/hello_world/templates/hello_world/index.html deleted file mode 100644 index 4380434..0000000 --- a/django_docker/hello_world/templates/hello_world/index.html +++ /dev/null @@ -1,7 +0,0 @@ -{% extends 'base.html' %} - -{% load staticfiles %} - -{% block content %} -

Hello, world!

-{% endblock content %} diff --git a/django_docker/hello_world/tests.py b/django_docker/hello_world/tests.py deleted file mode 100644 index 7ce503c..0000000 --- a/django_docker/hello_world/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/django_docker/hello_world/views.py b/django_docker/hello_world/views.py deleted file mode 100644 index 62e9001..0000000 --- a/django_docker/hello_world/views.py +++ /dev/null @@ -1,4 +0,0 @@ -from django.shortcuts import render - -def hello_world(request): - return render(request, 'hello_world/index.html') diff --git a/django_docker/manage.py b/django_docker/manage.py old mode 100644 new mode 100755 index edb63a9..1662d4a --- a/django_docker/manage.py +++ b/django_docker/manage.py @@ -4,7 +4,12 @@ if __name__ == "__main__": os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_docker.settings") - - from django.core.management import execute_from_command_line - + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc execute_from_command_line(sys.argv) diff --git a/django_docker/static/css/style.css b/django_docker/static/css/style.css deleted file mode 100644 index 3fea22f..0000000 --- a/django_docker/static/css/style.css +++ /dev/null @@ -1,6 +0,0 @@ -p.hello-world { - font-family: 'Helvetica', sans-serif; - font-size: 36px; - margin: 100px auto; - text-align: center; -} diff --git a/django_docker/templates/base.html b/django_docker/templates/base.html deleted file mode 100644 index 2cd2572..0000000 --- a/django_docker/templates/base.html +++ /dev/null @@ -1,18 +0,0 @@ -{% load staticfiles %} - - - - - - - - - - {% block content %}{% endblock content %} - - - - - diff --git a/supervisord.conf b/supervisord.conf index 67fdf47..5b14f7f 100644 --- a/supervisord.conf +++ b/supervisord.conf @@ -3,7 +3,7 @@ nodaemon=true [program:mysql] ; Don't start the MySQL daemon if we're in production -command=/bin/bash -c 'if [ "$DJANGO_PRODUCTION" != "true" ]; then /usr/bin/mysqld_safe; fi' +command=/bin/bash -c 'if [ "$DJANGO_PRODUCTION" != "true" ]; then /usr/bin/pidproxy /var/run/mysqld/mysqld.pid /usr/sbin/mysqld; fi' autostart=true exitcodes=0 startsecs=0