archive
This commit is contained in:
66
silverstrike/scratch/Dockerfile
Executable file
66
silverstrike/scratch/Dockerfile
Executable file
@@ -0,0 +1,66 @@
|
||||
FROM ubuntu:18.04 as builder
|
||||
|
||||
### SYS
|
||||
RUN export DEBIAN_FRONTEND=noninteractive; \
|
||||
apt -y update || true; \
|
||||
apt -y install tzdata; \
|
||||
ln -fs /usr/share/zoneinfo/America/Denver /etc/localtime; \
|
||||
dpkg-reconfigure --frontend noninteractive tzdata; \
|
||||
apt -y install \
|
||||
curl \
|
||||
rsync \
|
||||
cron \
|
||||
postgresql postgresql-contrib \
|
||||
&& mkdir -p /mnt/save
|
||||
|
||||
### POSTGRES
|
||||
RUN apt -y install sudo \
|
||||
&& service postgresql start
|
||||
USER postgres
|
||||
RUN service postgresql start \
|
||||
&& createuser www-data \
|
||||
&& createdb -O www-data silverstrikedb
|
||||
|
||||
#&& psql --command "CREATE USER ss WITH SUPERUSER PASSWORD 'ss';" \
|
||||
#&& psql --command "CREATE DATABASE silverstrikedb;" \
|
||||
#&& psql --command "GRANT ALL PRIVILEGES ON DATABASE silverstrikedb TO ss;"
|
||||
|
||||
USER root
|
||||
|
||||
### APP
|
||||
RUN \
|
||||
apt -y install nginx postgresql uwsgi uwsgi-plugin-python git python-pip python python-psycopg2 libpq-dev python-dev \
|
||||
&& pip install venv \
|
||||
&& mkdir -p /srv/webapps \
|
||||
&& cd /srv/webapps \
|
||||
&& git clone https://github.com/agstrike/production-project silverstrike \
|
||||
&& cd silverstrike \
|
||||
&& python -m venv env \
|
||||
&& . env/bin/activate \
|
||||
&& pip3 install silverstrike psycopg2 django
|
||||
COPY settings.py /srv/webapps/silverstrike/
|
||||
RUN \
|
||||
cd /srv/webapps/silverstrike \
|
||||
&& service postgresql start \
|
||||
&& python manage.py migrate \
|
||||
&& python manage.py collectstatic \
|
||||
&& ln -s /srv/webapps/silverstrike/uwsgi.ini /etc/uwsgi/apps-enabled/silverstrike.ini \
|
||||
&& service uwsgi start
|
||||
|
||||
### CRON BACKUPS
|
||||
RUN true \
|
||||
&& echo 'b=$(date +%Y%m%d%H%M%S) && mkdir -p /mnt/save/$b && pg_dump $DATABASE_URL --clean > /mnt/save/$b/pg.dump' > /backup.sh \
|
||||
&& echo 'b=$(find /mnt/save -type f | sort | tail -n 1); if [ -n "$b" ]; then echo restoring $b; psql $DATABASE_URL < "$b"; fi && service postgresql start;' > /restore.sh \
|
||||
&& echo '0 4,8,12,16,20 * * * bash /backup.sh >> /var/log/cronj.log 2>&1' > /etc/cron.d/backups \
|
||||
&& echo '' >> /etc/cron.d/backups \
|
||||
&& chmod 0644 /etc/cron.d/backups \
|
||||
&& touch /var/log/cronj.log
|
||||
|
||||
### FINAL
|
||||
ENV DATABASE_URL=postgres://www-data:password@localhost/silverstrikedb?sslmode=disable
|
||||
ENV SECRET_KEY=AimmBfzjdWcVN3rQs8YawbUowv5R8Eex
|
||||
ENV ALLOWED_HOSTS=*
|
||||
ENTRYPOINT \
|
||||
until psql $DATABASE_URL < /dev/null; do sleep 5; done \
|
||||
&& bash /restore.sh \
|
||||
&& sleep 5 && python manage.py migrate && exec uwsgi
|
||||
178
silverstrike/scratch/settings.py
Executable file
178
silverstrike/scratch/settings.py
Executable file
@@ -0,0 +1,178 @@
|
||||
"""
|
||||
Django settings for SilverStrike.
|
||||
|
||||
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
|
||||
|
||||
# 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 = 'AimmBfzjdWcVN3rQs8YawbUowv5R8Eex'
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
|
||||
ALLOWED_HOSTS = [
|
||||
"192.168.0.86",
|
||||
"firefly2.scratch.com",
|
||||
"silverstrike.scratch.com",
|
||||
]
|
||||
|
||||
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',
|
||||
'allauth.socialaccount',
|
||||
'rest_framework',
|
||||
'rest_framework.authtoken',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'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': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
|
||||
}
|
||||
#'default': {
|
||||
# 'ENGINE': 'django.db.backends.postgresql_psycopg2',
|
||||
# 'NAME': 'silverstrikedb',
|
||||
# 'USER': 'www-data',
|
||||
# 'PASSWORD': 'password',
|
||||
#}
|
||||
#'default': {
|
||||
# 'ENGINE': 'django.db.backends.mysql',
|
||||
# 'NAME': 'silverstrikedb',
|
||||
# 'USER': 'silverstrike',
|
||||
# 'PASSWORD': 'password',
|
||||
#}
|
||||
}
|
||||
|
||||
|
||||
# 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/'
|
||||
STATIC_ROOT = os.path.join(BASE_DIR, 'public', 'static')
|
||||
|
||||
|
||||
LOGIN_REDIRECT_URL = 'index'
|
||||
LOGIN_URL = 'account_login'
|
||||
LOGOUT_URL = 'account_logout'
|
||||
ACCOUNT_LOGOUT_REDIRECT_URL = 'account_login'
|
||||
|
||||
ACCOUNT_ADAPTER = 'signupadapter.SignupDisabledAdapter'
|
||||
|
||||
LOGGING = {
|
||||
'version': 1,
|
||||
'filters': {
|
||||
'require_debug_true': {
|
||||
'()': 'django.utils.log.RequireDebugTrue',
|
||||
}
|
||||
},
|
||||
'handlers': {
|
||||
'console': {
|
||||
'level': 'DEBUG',
|
||||
'filters': ['require_debug_true'],
|
||||
'class': 'logging.StreamHandler',
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1
silverstrike/scratch/try
Executable file
1
silverstrike/scratch/try
Executable file
@@ -0,0 +1 @@
|
||||
docker build -t bel/silverstrike:v0.0 -f Dockerfile . && docker run --rm -it --name ss -p 51131:8000 --entrypoint bash bel/silverstrike:v0.0
|
||||
Reference in New Issue
Block a user