diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index f7445c6..0000000 --- a/Dockerfile +++ /dev/null @@ -1,22 +0,0 @@ -FROM python:slim-stretch - - -# Copy the code -ADD . /code -WORKDIR /code - -# install deps -RUN apt-get update && apt-get install -y gcc libmariadbclient-dev python3-dev && \ - pip install --no-cache-dir -r requirements.txt && \ - apt-get remove -y gcc && apt-get autoremove -y - -# configure django -ENV DJANGO_SETTINGS_MODULE=settings - -# configure uwsgi -ENV UWSGI_WSGI_FILE=wsgi.py UWSGI_HTTP=:8000 UWSGI_MASTER=1 UWSGI_WORKERS=2 UWSGI_THREADS=8 UWSGI_UID=1000 UWSGI_GID=2000 UWSGI_LAZY_APPS=1 UWSGI_WSGI_ENV_BEHAVIOR=holy - -# collect static files -RUN python manage.py collectstatic - -CMD sleep 5 && python manage.py migrate && uwsgi diff --git a/README.md b/README.md new file mode 100644 index 0000000..442de75 --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +# docker-compose examples + +You can find example compose files for deploying SilverStrike. `demo` contains the stack used for the demo deployment at demo.silverstrike.org. + +If you want to try out silverstrike, change into the demo folder and run `docker-compose up`. +You can create a superuser in the running container `docker exec -it demo-ags-1 python manage.py createsuperuser` + +The `production` stack is an example stack using sqlite, which should be more than enough for your needs. +If you'd rather use postgres or mariadb, there are example for using them. diff --git a/demo/demo_middleware.py b/demo/demo_middleware.py new file mode 100644 index 0000000..0addc52 --- /dev/null +++ b/demo/demo_middleware.py @@ -0,0 +1,17 @@ +from django.conf import settings +from django.contrib.auth import login +from django.contrib.auth.models import User + +try: + from django.utils.deprecation import MiddlewareMixin +except ImportError: + MiddlewareMixin = object + + +class AlwaysAuthenticatedMiddleware(MiddlewareMixin): + def process_request(self, request): + if not request.user.is_authenticated: + user, created = User.objects.get_or_create(username='demo') + user.backend = settings.AUTHENTICATION_BACKENDS[0] + login(request, user) + diff --git a/demo/docker-compose.yml b/demo/docker-compose.yml new file mode 100644 index 0000000..095a85f --- /dev/null +++ b/demo/docker-compose.yml @@ -0,0 +1,17 @@ +version: "3" +services: + ags: + image: simhnna/silverstrike:dev + entrypoint: /app/start.sh + environment: + - DATABASE_URL=sqlite:////data/db.sqlite3 + ports: + - "8000:8000" + volumes: + # - data:/data + - ./start.sh:/app/start.sh + - ./demo_middleware.py:/app/demo_middleware.py + - ./settings_override.py:/app/local_settings.py +# volumes: +# data: + diff --git a/demo/settings_override.py b/demo/settings_override.py new file mode 100644 index 0000000..001ce1a --- /dev/null +++ b/demo/settings_override.py @@ -0,0 +1,17 @@ +SECRET_KEY="$_99bc($w4iv1h8qn=q5*g-gtb&99db+0kls8m6+avmzu8w^8x" +CSRF_TRUSTED_ORIGINS = ['http://127.0.0.1:8000', 'http://localhost:8080', 'https://demo.silverstrike.org'] +ALLOWED_HOSTS = ['127.0.0.1', 'localhost', 'demo.silverstrike.org'] +DEBUG = True +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'whitenoise.middleware.WhiteNoiseMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'corsheaders.middleware.CorsMiddleware', + 'django.middleware.locale.LocaleMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'demo_middleware.AlwaysAuthenticatedMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] diff --git a/demo/start.sh b/demo/start.sh new file mode 100755 index 0000000..1e67702 --- /dev/null +++ b/demo/start.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +python manage.py migrate --noinput +python manage.py createtestdata --prune +uwsgi + diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index 4b97573..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,21 +0,0 @@ ---- -version: "3.2" -services: - app: - environment: - - ALLOWED_HOSTS='*' - - DATABASE_URL=postgres://silverstrike:secretpass@database/silverstrikedb - - SECRET_KEY=PLprXpLzxemgLD57GPQQ84SBZdLVKFYg - image: simhnna/silverstrike - links: - - database:database - ports: - - 8000:8000 - database: - environment: - POSTGRES_DB: silverstrikedb - POSTGRES_USER: silverstrike - POSTGRES_PASSWORD: secretpass - image: postgres:10.3 - volumes: - - ./silverstrikedb:/var/lib/postgresql/data diff --git a/manage.py b/manage.py deleted file mode 100755 index 7646e46..0000000 --- a/manage.py +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env python -import os -import sys - -if __name__ == "__main__": - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "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/production/docker-compose-mariadb.yml b/production/docker-compose-mariadb.yml new file mode 100644 index 0000000..81ab4a9 --- /dev/null +++ b/production/docker-compose-mariadb.yml @@ -0,0 +1,23 @@ +version: "3" +services: + database: + image: mariadb + restart: always + environment: + MARIADB_DATABASE: silverstrikedb + MARIADB_USER: silverstrike + MARIADB_PASSWORD: secretpass + ags: + image: simhnna/silverstrike:dev + restart: always + entrypoint: /app/start.sh + environment: + - DATABASE_URL=mysql://silverstrike:secretpass@database/silverstrikedb + ports: + - "8000:8000" + volumes: + - ./start.sh:/app/start.sh + - ./settings_override.py:/app/local_settings.py + - app_data:/data +volumes: + app_data: diff --git a/production/docker-compose-postgres.yml b/production/docker-compose-postgres.yml new file mode 100644 index 0000000..afee1e9 --- /dev/null +++ b/production/docker-compose-postgres.yml @@ -0,0 +1,23 @@ +version: "3" +services: + database: + image: postgres + restart: always + environment: + POSTGRES_DB: silverstrikedb + POSTGRES_USER: silverstrike + POSTGRES_PASSWORD: secretpass + ags: + image: simhnna/silverstrike:dev + restart: always + entrypoint: /app/start.sh + environment: + - DATABASE_URL=postgres://silverstrike:secretpass@database/silverstrikedb + ports: + - "8000:8000" + volumes: + - ./start.sh:/app/start.sh + - ./settings_override.py:/app/local_settings.py + - app_data:/data +volumes: + app_data: diff --git a/production/docker-compose.yml b/production/docker-compose.yml new file mode 100644 index 0000000..e07d3aa --- /dev/null +++ b/production/docker-compose.yml @@ -0,0 +1,15 @@ +version: "3" +services: + ags: + image: simhnna/silverstrike:dev + entrypoint: /app/start.sh + environment: + - DATABASE_URL=sqlite:////data/db.sqlite3 + ports: + - "8000:8000" + volumes: + - ./start.sh:/app/start.sh + - ./settings_override.py:/app/local_settings.py + - data:/data +volumes: + data: diff --git a/production/settings_override.py b/production/settings_override.py new file mode 100644 index 0000000..3c15929 --- /dev/null +++ b/production/settings_override.py @@ -0,0 +1,15 @@ +SECRET_KEY="$_99bc($w4iv1h8qn=q5*g-gtb&99db+0kls8m6+avmzu8w^8x" +CSRF_TRUSTED_ORIGINS = ['demo.silverstrike.org'] +ALLOWED_HOSTS = ['demo.silverstrike.org'] +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'whitenoise.middleware.WhiteNoiseMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'corsheaders.middleware.CorsMiddleware', + 'django.middleware.locale.LocaleMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] diff --git a/production/start.sh b/production/start.sh new file mode 100755 index 0000000..ef10931 --- /dev/null +++ b/production/start.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +python manage.py migrate --noinput +uwsgi + diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 3580b94..0000000 --- a/requirements.txt +++ /dev/null @@ -1,6 +0,0 @@ -silverstrike -whitenoise -uwsgi -psycopg2-binary -dj-database-url -mysqlclient diff --git a/settings.py b/settings.py deleted file mode 100644 index 90059c2..0000000 --- a/settings.py +++ /dev/null @@ -1,163 +0,0 @@ -""" -Django settings for demo project. - -Generated by 'django-admin startproject' using Django 1.10.3. - -For more information on this file, see -https://docs.djangoproject.com/en/1.10/topics/settings/ - -For the full list of settings and their values, see -https://docs.djangoproject.com/en/1.10/ref/settings/ -""" - -import os - -import dj_database_url - - -# Build paths inside the project like this: os.path.join(BASE_DIR, ...) -BASE_DIR = os.path.dirname(os.path.abspath(__file__)) - - -# Quick-start development settings - unsuitable for production -# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/ - -# SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = os.environ.get('SECRET_KEY', 'PLprXpLzxemgLD57GPQQ84SBZdLVKFYg') - -# SECURITY WARNING: don't run with debug turned on in production! -DEBUG = False - -ALLOWED_HOSTS = ['*'] - -SITE_ID = 1 - -# Application definition - -INSTALLED_APPS = [ - 'django.contrib.admin', - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.humanize', - 'django.contrib.sessions', - 'django.contrib.messages', - 'django.contrib.staticfiles', - 'django.contrib.sites', - 'widget_tweaks', - 'silverstrike', - 'allauth', - 'allauth.account', - 'rest_framework', - 'rest_framework.authtoken' -] - -MIDDLEWARE = [ - 'django.middleware.security.SecurityMiddleware', - 'whitenoise.middleware.WhiteNoiseMiddleware', - 'django.contrib.sessions.middleware.SessionMiddleware', - 'django.middleware.locale.LocaleMiddleware', - 'django.middleware.common.CommonMiddleware', - 'django.middleware.csrf.CsrfViewMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.messages.middleware.MessageMiddleware', - 'django.middleware.clickjacking.XFrameOptionsMiddleware', -] - -ROOT_URLCONF = '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 = 'wsgi.application' - - -# Database -# https://docs.djangoproject.com/en/1.10/ref/settings/#databases - -DATABASES = { - 'default': dj_database_url.config(conn_max_age=600) -} - - - -# Password validation -# https://docs.djangoproject.com/en/1.10/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', - }, -] - -AUTHENTICATION_BACKENDS = ( - 'django.contrib.auth.backends.ModelBackend', - 'allauth.account.auth_backends.AuthenticationBackend', -) - - -# Internationalization -# https://docs.djangoproject.com/en/1.10/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.10/howto/static-files/ - -STATIC_URL = '/static/' -STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' -STATIC_ROOT = os.path.join(BASE_DIR, 'static') - - -LOGIN_REDIRECT_URL = 'index' -LOGIN_URL = 'account_login' -LOGOUT_URL = 'account_logout' -ACCOUNT_LOGOUT_REDIRECT_URL = 'account_login' -ACCOUNT_ADAPTER = 'signupadapter.SignupDisabledAdapter' - -# Uncomment to prevent signup -# ACCOUNT_ADAPTER = 'silverstrike.models.SignupDisabledAdapter' - -REST_FRAMEWORK = { - 'DEFAULT_PERMISSION_CLASSES': [ - 'rest_framework.permissions.IsAuthenticated' - ], - 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination', - 'PAGE_SIZE': 10, - 'DEFAULT_AUTHENTICATION_CLASSES': ( - 'rest_framework.authentication.BasicAuthentication', - 'rest_framework.authentication.SessionAuthentication', - 'rest_framework.authentication.TokenAuthentication' - ) -} - diff --git a/signupadapter.py b/signupadapter.py deleted file mode 100644 index bf2baad..0000000 --- a/signupadapter.py +++ /dev/null @@ -1,6 +0,0 @@ -from allauth.account.adapter import DefaultAccountAdapter - - -class SignupDisabledAdapter(DefaultAccountAdapter): - def is_open_for_signup(self, request): - return False diff --git a/urls.py b/urls.py deleted file mode 100644 index ab0cfd3..0000000 --- a/urls.py +++ /dev/null @@ -1,9 +0,0 @@ -from django.contrib import admin -from django.urls import path, include -from django.views.generic import RedirectView - - -urlpatterns = [ - path('admin/', admin.site.urls), - path('', include('silverstrike.urls')), -] diff --git a/wsgi.py b/wsgi.py deleted file mode 100644 index 51ec7e3..0000000 --- a/wsgi.py +++ /dev/null @@ -1,16 +0,0 @@ -""" -WSGI config for demo 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.10/howto/deployment/wsgi/ -""" - -import os - -from django.core.wsgi import get_wsgi_application - -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings") - -application = get_wsgi_application()