diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..651665bbd --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +node_modules +.git diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..de4cc2097 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,15 @@ +version: '3' + +services: + server: + build: + dockerfile: docker/Dockerfile + context: . + init: true + ports: + - 8000:8000 + volumes: + - db_data:/app/tracker_development/db + +volumes: + db_data: diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 000000000..3accdca06 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,48 @@ +FROM node:12 AS client + +WORKDIR /app + +COPY package.json yarn.lock ./ +RUN yarn install --frozen-lockfile + +COPY \ + .browserslistrc \ + babel.config.js \ + declarations.d.ts \ + postcss.config.js \ + webpack.config.js \ + ./ +COPY bundles bundles +RUN yarn build + + +FROM python:3.7 + +WORKDIR /app +RUN pip install django~=2.2 +RUN django-admin startproject tracker_development + +WORKDIR /app/tracker_development/donation-tracker +COPY \ + __init__.py \ + .flake8 \ + pyproject.toml \ + README.md \ + setup.py \ + ./ +COPY tracker tracker +COPY --from=client /app/tracker tracker +RUN pip install -e . + +WORKDIR /app/tracker_development +COPY docker/tracker_development /app/tracker_development/tracker_development +RUN mkdir db + +RUN apt update +RUN apt install -y locales +RUN echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen +RUN locale-gen en_US.UTF-8 +ENV LC_ALL en_US.UTF-8 + +CMD ["sh", "-c", "python manage.py migrate && python manage.py runserver 0.0.0.0:8000"] + diff --git a/docker/nginx.conf b/docker/nginx.conf new file mode 100644 index 000000000..3aaba1eb0 --- /dev/null +++ b/docker/nginx.conf @@ -0,0 +1,49 @@ +user nginx; +worker_processes auto; + +error_log /var/log/nginx/error.log notice; +pid /var/run/nginx.pid; + + +events { + worker_connections 1024; +} + + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + sendfile on; + keepalive_timeout 65; + gzip on; + + server { + listen 80; + server_name localhost; + + location /tracker/admin { + proxy_pass http://server:8000/admin; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $host; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + } + + # location /tracker { + # proxy_pass http://server:8000/tracker; + # proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + # proxy_set_header Host $host; + # proxy_http_version 1.1; + # proxy_set_header Upgrade $http_upgrade; + # proxy_set_header Connection 'upgrade'; + # } + } +} diff --git a/docker/tracker_development/routing.py b/docker/tracker_development/routing.py new file mode 100644 index 000000000..52d01b4c9 --- /dev/null +++ b/docker/tracker_development/routing.py @@ -0,0 +1,16 @@ +from channels.auth import AuthMiddlewareStack +from channels.routing import ProtocolTypeRouter, URLRouter +from channels.security.websocket import AllowedHostsOriginValidator +from django.urls import path + +import tracker.routing + +application = ProtocolTypeRouter({ + 'websocket': AllowedHostsOriginValidator( + AuthMiddlewareStack( + URLRouter( + [path('tracker/', URLRouter(tracker.routing.websocket_urlpatterns))] + ) + ) + ), +}) diff --git a/docker/tracker_development/settings.py b/docker/tracker_development/settings.py new file mode 100644 index 000000000..cd4cbb5ad --- /dev/null +++ b/docker/tracker_development/settings.py @@ -0,0 +1,142 @@ +""" +Django settings for tracker_development project. + +Generated by 'django-admin startproject' using Django 2.2.24. + +For more information on this file, see +https://docs.djangoproject.com/en/2.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/2.2/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/2.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'v!801)q@a8)ltd0!z62eud8ytoh7q35yu7^9llhc#3-bc!3jfc' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = ['*'] + +DOMAIN = 'test' + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'channels', + 'post_office', + 'paypal.standard.ipn', + 'tracker', + 'timezone_field', + 'ajax_select', + 'mptt', +] + +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 = 'tracker_development.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 = 'tracker_development.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/2.2/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db/db.sqlite3'), + } +} + + +# Password validation +# https://docs.djangoproject.com/en/2.2/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/2.2/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/2.2/howto/static-files/ + +STATIC_URL = '/static/' + +from tracker import ajax_lookup_channels +AJAX_LOOKUP_CHANNELS = ajax_lookup_channels.AJAX_LOOKUP_CHANNELS +ASGI_APPLICATION = 'tracker_development.routing.application' +CHANNEL_LAYERS = {'default': {'BACKEND': 'channels.layers.InMemoryChannelLayer'}} + + +import logging + +logging.basicConfig( + level = logging.DEBUG, + format = '%(asctime)s %(levelname)s %(message)s', +) diff --git a/docker/tracker_development/urls.py b/docker/tracker_development/urls.py new file mode 100644 index 000000000..8f553f847 --- /dev/null +++ b/docker/tracker_development/urls.py @@ -0,0 +1,26 @@ +"""tracker_development URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/2.2/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 +from django.urls import path, include + +import tracker.urls +import ajax_select.urls + +urlpatterns = [ + path('tracker/admin/', admin.site.urls), + path('tracker/admin/lookups/', include(ajax_select.urls)), + path('tracker/', include(tracker.urls, namespace='tracker')), +] diff --git a/docker/tracker_development/wsgi.py b/docker/tracker_development/wsgi.py new file mode 100644 index 000000000..671060a2e --- /dev/null +++ b/docker/tracker_development/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for tracker_development 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/2.2/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tracker_development.settings') + +application = get_wsgi_application()