diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..1120be9 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +docker-compose.yml diff --git a/.gitignore b/.gitignore index 7bbc71c..b236b6e 100644 --- a/.gitignore +++ b/.gitignore @@ -99,3 +99,6 @@ ENV/ # mypy .mypy_cache/ + +# docker-compose +docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..914f00f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,52 @@ +FROM debian:9 + +# The Dockerfile for this project is split into 5 layers. +# - Base: The base image +# - System: System package installation +# - Compile: Custom compilation and installation +# - Packages: Application packages (e.g. npm, pip etc) +# - App: Task runs and application prep +# The order of the layers is based on which parts are likely to be +# modified the most. +# The project source is added in the App layer so as not to invalidate +# the Dockerfile cache. + +# SYSTEM +SHELL ["/bin/bash","-ex","-c"] +RUN apt-get update && apt-get install -y\ + build-essential\ + libgdal-dev\ + libpq-dev\ + python\ + python3-dev\ + python3\ + rsync\ + wget + +# COMPILE +WORKDIR /build +RUN wget https://nodejs.org/dist/v7.10.0/node-v7.10.0-linux-x64.tar.gz\ + && tar -xvf node-v7.10.0-linux-x64.tar.gz\ + && pushd node-v7.10.0-linux-x64\ + && rsync --archive ./* /usr/local\ + && popd\ + && wget http://download.osgeo.org/proj/proj-4.9.1.tar.gz\ + && wget http://download.osgeo.org/proj/proj-datumgrid-1.5.tar.gz\ + && tar -xvf proj-4.9.1.tar.gz && cd proj-4.9.1/nad\ + && tar -xvf ../../proj-datumgrid-1.5.tar.gz && cd ../ \ + && ./configure && make && make install + +# PACKAGES +WORKDIR /app +COPY ./requirements.txt . +RUN apt-get install python3-pip -y \ + && python3 -m pip install -r requirements.txt + +# APP +WORKDIR /app +COPY . . + +EXPOSE 8000 + +CMD [ "python3", "manage.py", "migrate", "&&", \ + "python3", "manage.py", "runserver", "0.0.0.0:8000" ] diff --git a/bin/build-ojuso-map b/bin/build-ojuso-map new file mode 100755 index 0000000..2692c0e --- /dev/null +++ b/bin/build-ojuso-map @@ -0,0 +1,3 @@ +#!/bin/bash +docker build --tag ojuso/map:latest\ + $( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/.. diff --git a/bin/create-discourse b/bin/create-discourse new file mode 100755 index 0000000..b064b4b --- /dev/null +++ b/bin/create-discourse @@ -0,0 +1,27 @@ +#!/bin/bash +# Create Discourse +docker run -d --restart=always + -e LANG=en_US.UTF-8 \ + -e RAILS_ENV=production \ + -e UNICORN_WORKERS=4 \ + -e UNICORN_SIDEKIQS=1 \ + -e RUBY_GLOBAL_METHOD_CACHE_SIZE=131072 \ + -e RUBY_GC_HEAP_GROWTH_MAX_SLOTS=40000 \ + -e RUBY_GC_HEAP_INIT_SLOTS=400000 \ + -e RUBY_GC_HEAP_OLDOBJECT_LIMIT_FACTOR=1.5 \ + -e DISCOURSE_DB_SOCKET=/var/run/postgresql \ + -e LETSENCRYPT_DIR=/shared/letsencrypt \ + -e DISCOURSE_HOSTNAME=forum.ojuso.org \ + -e DISCOURSE_DEVELOPER_EMAILS=admin@ojuso.org \ + -e DISCOURSE_SMTP_ADDRESS=mail.gandi.net \ + -e DISCOURSE_SMTP_PORT=587 \ + -e DISCOURSE_SMTP_USER_NAME=admin@ojuso.org \ + -e DISCOURSE_SMTP_PASSWORD=QN7yosrnch1le474H56mesVR1SRw6sfO3izJDZnJ6T62Cj9I57CplW6UYZY6VXsq7lLr868bIK3kSXGyWiSrAyWK \ + -e LETSENCRYPT_ACCOUNT_EMAIL=admin@ojuso.org -h energy-app \ + -e DOCKER_HOST_IP=172.17.0.1 \ + --name app \ + -t -p 80:80 -p 443:443 \ + -v /var/discourse/shared/standalone:/shared \ + -v /var/discourse/shared/standalone/log/var-log:/var/log \ + --mac-address 02:2d:a6:d4:85:4a \ + local_discourse/app /sbin/boot diff --git a/manage.py b/manage.py new file mode 100755 index 0000000..74641be --- /dev/null +++ b/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ojusomap.settings") + try: + from django.core.management import execute_from_command_line + except ImportError: + # The above import may fail for some other reason. Ensure that the + # issue is really that Django is missing to avoid masking other + # exceptions on Python 2. + try: + import django + except ImportError: + 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?" + ) + raise + execute_from_command_line(sys.argv) diff --git a/nginx.template b/nginx.template new file mode 100644 index 0000000..0ee674b --- /dev/null +++ b/nginx.template @@ -0,0 +1,27 @@ +server { + listen 80; listen [::]:80; + server_name forum.example.com; # <-- change this + + return 301 https://$host$request_uri; +} + +server { + listen 443 ssl http2; listen [::]:443 ssl http2; + server_name forum.ojuso.org; # <-- change this + + ssl on; + ssl_certificate /web/certs/forum.ojuso.org/forum.ojuso.org.cer; + ssl_certificate_key /web/certs/forum.ojuso.org/forum.ojuso.org.key; + ssl_session_tickets off; + ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:ECDHE-RSA-DES-CBC3-SHA:ECDHE-ECDSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA; + + http2_idle_timeout 5m; # up from 3m default + + location / { + proxy_pass http://unix:/containers/forum/http.sock:; + proxy_set_header Host $http_host; + proxy_http_version 1.1; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto https; + } +} diff --git a/ojusomap/__init__.py b/ojusomap/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/ojusomap/settings.py b/ojusomap/settings.py new file mode 100644 index 0000000..c77c4c8 --- /dev/null +++ b/ojusomap/settings.py @@ -0,0 +1,124 @@ +""" +Django settings for ojusomap project. + +Generated by 'django-admin startproject' using Django 1.11.1. + +For more information on this file, see +https://docs.djangoproject.com/en/1.11/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/1.11/ref/settings/ +""" + +import os + +# 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.11/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'r3vwfrawmnwh3kzp4(p#sg0!y%!jg80k06(j@p!y(q^h@5y*lw' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = os.getenv('ALLOWED_HOSTS', 'localhost').split() + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'django.contrib.gis', +] + +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 = 'ojusomap.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + '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 = 'ojusomap.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/1.11/ref/settings/#databases +DATABASES = { + 'default': { + 'ENGINE': 'django.contrib.gis.db.backends.postgis', + 'HOST': os.getenv('DATABASE_HOST','localhost'), + 'PORT': os.getenv('DATABASE_PORT', '5432'), + 'NAME': os.getenv('DATABASE_NAME', 'postgres'), + 'USER': os.getenv('DATABASE_USER', 'postgres'), + 'PASSWORD': os.getenv('DATABASE_PASSWORD','postgres'), + } +} + +# Password validation +# https://docs.djangoproject.com/en/1.11/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.11/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/1.11/howto/static-files/ + +STATIC_ROOT = os.path.join(BASE_DIR, 'static/') +STATIC_URL = os.getenv("STATIC_URL",'/static/') diff --git a/ojusomap/urls.py b/ojusomap/urls.py new file mode 100644 index 0000000..d11390e --- /dev/null +++ b/ojusomap/urls.py @@ -0,0 +1,21 @@ +"""ojusomap URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/1.11/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.conf.urls import url, include + 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) +""" +from django.conf.urls import url +from django.contrib import admin + +urlpatterns = [ + url(r'^admin/', admin.site.urls), +] diff --git a/ojusomap/wsgi.py b/ojusomap/wsgi.py new file mode 100644 index 0000000..9367154 --- /dev/null +++ b/ojusomap/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for ojusomap 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.11/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ojusomap.settings") + +application = get_wsgi_application() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..991d849 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,8 @@ +appdirs==1.4.3 +Django==1.11.1 +gunicorn==19.7.1 +packaging==16.8 +psycopg2==2.7.1 +pyparsing==2.2.0 +pytz==2017.2 +six==1.10.0