Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dockerfile to python3, sample project to Django2 #25

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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`
Expand All @@ -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
Expand All @@ -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
Expand Down
Binary file removed django_docker/db.sqlite3
Binary file not shown.
115 changes: 59 additions & 56 deletions django_docker/django_docker/settings.py
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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 *
21 changes: 0 additions & 21 deletions django_docker/django_docker/settings_production.py

This file was deleted.

21 changes: 16 additions & 5 deletions django_docker/django_docker/urls.py
Original file line number Diff line number Diff line change
@@ -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),
]
4 changes: 0 additions & 4 deletions django_docker/django_docker/views.py

This file was deleted.

8 changes: 5 additions & 3 deletions django_docker/django_docker/wsgi.py
Original file line number Diff line number Diff line change
@@ -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()
Empty file.
3 changes: 0 additions & 3 deletions django_docker/hello_world/admin.py

This file was deleted.

3 changes: 0 additions & 3 deletions django_docker/hello_world/models.py

This file was deleted.

7 changes: 0 additions & 7 deletions django_docker/hello_world/templates/hello_world/index.html

This file was deleted.

3 changes: 0 additions & 3 deletions django_docker/hello_world/tests.py

This file was deleted.

4 changes: 0 additions & 4 deletions django_docker/hello_world/views.py

This file was deleted.

11 changes: 8 additions & 3 deletions django_docker/manage.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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)
6 changes: 0 additions & 6 deletions django_docker/static/css/style.css

This file was deleted.

18 changes: 0 additions & 18 deletions django_docker/templates/base.html

This file was deleted.

2 changes: 1 addition & 1 deletion supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down