diff --git a/code/core.old/__init__.py b/code/core.old/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/code/core.old/_settings/__init__.py b/code/core.old/_settings/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/code/core.old/_settings/development.py b/code/core.old/_settings/development.py new file mode 100644 index 0000000..c7f504a --- /dev/null +++ b/code/core.old/_settings/development.py @@ -0,0 +1,8 @@ +LOCAL_SETTINGS = True # avoid recursive imports + +from core._settings.development_generated import * + +import logging + +LOCAL_LOGGING_PREFIX = "%s %%(message)s" % BRANCH +logging.basicConfig(format=LOCAL_LOGGING_PREFIX, level=logging.DEBUG) diff --git a/code/core.old/_settings/development.py.bak b/code/core.old/_settings/development.py.bak new file mode 100644 index 0000000..c7f504a --- /dev/null +++ b/code/core.old/_settings/development.py.bak @@ -0,0 +1,8 @@ +LOCAL_SETTINGS = True # avoid recursive imports + +from core._settings.development_generated import * + +import logging + +LOCAL_LOGGING_PREFIX = "%s %%(message)s" % BRANCH +logging.basicConfig(format=LOCAL_LOGGING_PREFIX, level=logging.DEBUG) diff --git a/code/core.old/_settings/development_generated.py b/code/core.old/_settings/development_generated.py new file mode 100644 index 0000000..29823f6 --- /dev/null +++ b/code/core.old/_settings/development_generated.py @@ -0,0 +1,169 @@ +# this file contains settings that are automatically generated +# put custom commands/ imports in a separate file! + +LOCAL_SETTINGS = True # avoid recursive imports +BRANCH = 'development' + +from core.settings import * + +import logging + +LOCAL_LOGGING_PREFIX = "%s %%(message)s" % BRANCH +logging.basicConfig(format=LOCAL_LOGGING_PREFIX, level=logging.DEBUG) + +SITE_ID = 1 + +TEMPLATES[0]['DIRS'].append( + "/Users/ronny/projects/django/api-sandbox.prj/share/templates") + +# +# NOTE: a lot of the code in these local settings files are automated and you +# might be inclined to take them out and move them into the main settings.py +# file. That would be a mistake. These automatic files AT THE VERY LEAST have +# one variable, and that is WHICH BRANCH CONFIGURATION FILE ARE WE LOOKING AT. +# Once I set that file, THEN all the rest of the information can be automated. +# So all these automated info needs to be here. + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql', + 'NAME': 'api-sandbox_dvp', + 'USER': 'ronny', + 'PASSWORD': 'admin', + 'HOST': 'localhost', + 'PORT': '49041', + } +} + + +# +# directory from which we serve static files +# +# NOTE: both STATIC and MEDIA roots are getting their values from the +# initialization files that are set up above. Also, MEDIA_ROOT is being set +# to something called "paths.server.media.dynamic" - the names are different, +# but it means the same thing. +# +# MEDIA_ROOT is the dynamic media information that the web server, user or +# admin # will be adding and taking out. It's why I call it "dynamic" + +STATIC_ROOT = '/usr/local/var/www/api-sandbox.dvp/public/media/static' +MEDIA_ROOT = '/usr/local/var/www/api-sandbox.dvp/public/media/dynamic' + +# directories from which we search for static files to place in STATIC_ROOT +# these static files are located within the project root as opposed to the +# server root location + +STATICFILES_DIRS = ( + os.path.join("/Users/ronny/projects/django/api-sandbox.prj", "share", "media"), +) + +# debug and debug toolbar settings +DEBUG = True +TEMPLATES[0]['OPTIONS']['debug'] = DEBUG +USE_DEBUG_TOOLBAR = DEBUG + +# allow template debug outputs on development environment +INTERNAL_IPS = ['127.0.0.1', '127.0.0.2', '127.0.0.3', ] + +ALLOWED_HOSTS = ['127.0.0.1', 'PROJECT_NAME.BRANCH_EXT', 'api-sandbox.dvp', 'localhost'] + +# ----------------------------------------- +# Debug logging to the console + +LOGGING = { + 'version': 1, + 'disable_existing_loggers': False, + + 'formatters': { + 'verbose': { + 'format': "%(levelname)s %(asctime)s %(module)s %(process)d" + " %(thread)d %(message)s" + }, + 'simple': { + 'format': '%(levelname)s:%(module)s - %(message)s' + }, + + 'code': { + 'format': "%(module)s:%(funcName)s:%(lineno)d - %(message)s" + }, + + 'code.file': { + 'format': "%(levelname)s %(module)s:%(funcName)s - %(message)s\n" + }, + }, + + 'handlers': { + 'file.log': { + 'class': 'logging.FileHandler', + + 'filename': + '/Users/ronny/projects/django/api-sandbox.prj/var/log/django.log', + + 'formatter': 'code.file' + }, + + 'file.log.debug': { + 'class': 'logging.FileHandler', + + 'filename': + '/Users/ronny/projects/django/api-sandbox.prj/var/log/django.log.debug', + + 'formatter': 'code.file' + }, + + 'server.file.log.debug': { + 'level': 'DEBUG', + 'class': 'logging.FileHandler', + + 'filename': + '/usr/local/var/www/api-sandbox.dvp/logs/django/django.log.debug', + + 'formatter': 'code.file' + }, + + 'console': { + 'class': 'logging.StreamHandler', + 'formatter': 'simple' + }, + + 'console.code': { + 'class': 'logging.StreamHandler', + 'formatter': 'code', + }, + + 'null': { + 'class': 'logging.NullHandler', + } + }, + + 'root': { + # automatically set to level WARNING + + 'handlers': ['console.code', 'file.log', 'server.file.log.debug' ], + 'propagate': True, + }, + + 'loggers': { + 'django.info': { + 'handlers': + [ + 'console', + 'file.log' + ], + 'level': 'INFO', + 'propagate': False, + }, + + 'django.debug': { + 'handlers': + [ + 'console.code', + 'file.log.debug', + 'server.file.log.debug', + ], + 'level': 'DEBUG', + 'propagate': True, + }, + } +} diff --git a/code/core.old/_settings/development_generated.py.bak b/code/core.old/_settings/development_generated.py.bak new file mode 100644 index 0000000..29823f6 --- /dev/null +++ b/code/core.old/_settings/development_generated.py.bak @@ -0,0 +1,169 @@ +# this file contains settings that are automatically generated +# put custom commands/ imports in a separate file! + +LOCAL_SETTINGS = True # avoid recursive imports +BRANCH = 'development' + +from core.settings import * + +import logging + +LOCAL_LOGGING_PREFIX = "%s %%(message)s" % BRANCH +logging.basicConfig(format=LOCAL_LOGGING_PREFIX, level=logging.DEBUG) + +SITE_ID = 1 + +TEMPLATES[0]['DIRS'].append( + "/Users/ronny/projects/django/api-sandbox.prj/share/templates") + +# +# NOTE: a lot of the code in these local settings files are automated and you +# might be inclined to take them out and move them into the main settings.py +# file. That would be a mistake. These automatic files AT THE VERY LEAST have +# one variable, and that is WHICH BRANCH CONFIGURATION FILE ARE WE LOOKING AT. +# Once I set that file, THEN all the rest of the information can be automated. +# So all these automated info needs to be here. + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql', + 'NAME': 'api-sandbox_dvp', + 'USER': 'ronny', + 'PASSWORD': 'admin', + 'HOST': 'localhost', + 'PORT': '49041', + } +} + + +# +# directory from which we serve static files +# +# NOTE: both STATIC and MEDIA roots are getting their values from the +# initialization files that are set up above. Also, MEDIA_ROOT is being set +# to something called "paths.server.media.dynamic" - the names are different, +# but it means the same thing. +# +# MEDIA_ROOT is the dynamic media information that the web server, user or +# admin # will be adding and taking out. It's why I call it "dynamic" + +STATIC_ROOT = '/usr/local/var/www/api-sandbox.dvp/public/media/static' +MEDIA_ROOT = '/usr/local/var/www/api-sandbox.dvp/public/media/dynamic' + +# directories from which we search for static files to place in STATIC_ROOT +# these static files are located within the project root as opposed to the +# server root location + +STATICFILES_DIRS = ( + os.path.join("/Users/ronny/projects/django/api-sandbox.prj", "share", "media"), +) + +# debug and debug toolbar settings +DEBUG = True +TEMPLATES[0]['OPTIONS']['debug'] = DEBUG +USE_DEBUG_TOOLBAR = DEBUG + +# allow template debug outputs on development environment +INTERNAL_IPS = ['127.0.0.1', '127.0.0.2', '127.0.0.3', ] + +ALLOWED_HOSTS = ['127.0.0.1', 'PROJECT_NAME.BRANCH_EXT', 'api-sandbox.dvp', 'localhost'] + +# ----------------------------------------- +# Debug logging to the console + +LOGGING = { + 'version': 1, + 'disable_existing_loggers': False, + + 'formatters': { + 'verbose': { + 'format': "%(levelname)s %(asctime)s %(module)s %(process)d" + " %(thread)d %(message)s" + }, + 'simple': { + 'format': '%(levelname)s:%(module)s - %(message)s' + }, + + 'code': { + 'format': "%(module)s:%(funcName)s:%(lineno)d - %(message)s" + }, + + 'code.file': { + 'format': "%(levelname)s %(module)s:%(funcName)s - %(message)s\n" + }, + }, + + 'handlers': { + 'file.log': { + 'class': 'logging.FileHandler', + + 'filename': + '/Users/ronny/projects/django/api-sandbox.prj/var/log/django.log', + + 'formatter': 'code.file' + }, + + 'file.log.debug': { + 'class': 'logging.FileHandler', + + 'filename': + '/Users/ronny/projects/django/api-sandbox.prj/var/log/django.log.debug', + + 'formatter': 'code.file' + }, + + 'server.file.log.debug': { + 'level': 'DEBUG', + 'class': 'logging.FileHandler', + + 'filename': + '/usr/local/var/www/api-sandbox.dvp/logs/django/django.log.debug', + + 'formatter': 'code.file' + }, + + 'console': { + 'class': 'logging.StreamHandler', + 'formatter': 'simple' + }, + + 'console.code': { + 'class': 'logging.StreamHandler', + 'formatter': 'code', + }, + + 'null': { + 'class': 'logging.NullHandler', + } + }, + + 'root': { + # automatically set to level WARNING + + 'handlers': ['console.code', 'file.log', 'server.file.log.debug' ], + 'propagate': True, + }, + + 'loggers': { + 'django.info': { + 'handlers': + [ + 'console', + 'file.log' + ], + 'level': 'INFO', + 'propagate': False, + }, + + 'django.debug': { + 'handlers': + [ + 'console.code', + 'file.log.debug', + 'server.file.log.debug', + ], + 'level': 'DEBUG', + 'propagate': True, + }, + } +} diff --git a/code/core.old/asgi.py b/code/core.old/asgi.py new file mode 100644 index 0000000..e36e2c8 --- /dev/null +++ b/code/core.old/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for core project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings') + +application = get_asgi_application() diff --git a/code/core.old/settings.py b/code/core.old/settings.py new file mode 100644 index 0000000..3a1a313 --- /dev/null +++ b/code/core.old/settings.py @@ -0,0 +1,145 @@ +""" +Django settings for api-sandbox project. + +Generated by 'django-admin startproject' using Django 4.2.1. + +For more information on this file, see +https://docs.djangoproject.com/en/4.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/4.2/ref/settings/ +""" + +import os +import sys + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +PROJECT_ROOT = os.path.abspath(os.path.join(BASE_DIR, os.pardir)) + +# +# add the directory that has the intialize.py module which contains the +# get_config function definition which will pull out all the configuraiton +# infomration for the settings file + +sys.path.insert(0, os.path.join( + PROJECT_ROOT, 'usr/bin/customfabric')) + +# +# add an "apps" directory to this project, which is where all the apps +# ought to be in the first place. + +sys.path.insert(0, os.path.join(BASE_DIR, 'apps')) + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = '0=-gL:f[7fG*PRv+,$40O52oUV}ukffT1-@*9rwC9+lPFu-xpL' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', +] + +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 = 'core.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [os.path.join(PROJECT_ROOT, '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 = 'core.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/4.2/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + + +# Password validation +# https://docs.djangoproject.com/en/4.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/4.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/4.2/howto/static-files/ + +STATIC_URL = '/static/' +MEDIA_URL = '/media/' + +# Default primary key field type +# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' \ No newline at end of file diff --git a/code/core.old/settings.py.bak b/code/core.old/settings.py.bak new file mode 100644 index 0000000..f60996a --- /dev/null +++ b/code/core.old/settings.py.bak @@ -0,0 +1,122 @@ +""" +Django settings for core project. + +Generated by 'django-admin startproject' using Django 5.2. + +For more information on this file, see +https://docs.djangoproject.com/en/5.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/5.2/ref/settings/ +""" + +from pathlib import Path + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'django-insecure-k41czrqxrqaqcbr2h87v6cpdz1mt=9rz_2aswi+pyxs8ey(v0=' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', +] + +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 = 'core.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'core.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/5.2/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/5.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/5.2/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/5.2/howto/static-files/ + +STATIC_URL = 'static/' + +# Default primary key field type +# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' diff --git a/code/core.old/urls.py b/code/core.old/urls.py new file mode 100644 index 0000000..cd1cf6e --- /dev/null +++ b/code/core.old/urls.py @@ -0,0 +1,22 @@ +""" +URL configuration for core project. + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/5.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 + +urlpatterns = [ + path('admin/', admin.site.urls), +] diff --git a/code/core.old/wsgi.py b/code/core.old/wsgi.py new file mode 100644 index 0000000..0206f63 --- /dev/null +++ b/code/core.old/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for estate 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.8/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "core._settings") + +application = get_wsgi_application() diff --git a/code/core.old/wsgi.py.bak b/code/core.old/wsgi.py.bak new file mode 100644 index 0000000..050d8bc --- /dev/null +++ b/code/core.old/wsgi.py.bak @@ -0,0 +1,16 @@ +""" +WSGI config for core 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/5.2/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings') + +application = get_wsgi_application() diff --git a/code/core/__init__.py b/code/core/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/code/core/_settings/__init__.py b/code/core/_settings/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/code/core/_settings/development.py b/code/core/_settings/development.py new file mode 100644 index 0000000..c7f504a --- /dev/null +++ b/code/core/_settings/development.py @@ -0,0 +1,8 @@ +LOCAL_SETTINGS = True # avoid recursive imports + +from core._settings.development_generated import * + +import logging + +LOCAL_LOGGING_PREFIX = "%s %%(message)s" % BRANCH +logging.basicConfig(format=LOCAL_LOGGING_PREFIX, level=logging.DEBUG) diff --git a/code/core/_settings/development.py.bak b/code/core/_settings/development.py.bak new file mode 100644 index 0000000..c7f504a --- /dev/null +++ b/code/core/_settings/development.py.bak @@ -0,0 +1,8 @@ +LOCAL_SETTINGS = True # avoid recursive imports + +from core._settings.development_generated import * + +import logging + +LOCAL_LOGGING_PREFIX = "%s %%(message)s" % BRANCH +logging.basicConfig(format=LOCAL_LOGGING_PREFIX, level=logging.DEBUG) diff --git a/code/core/_settings/development_generated.py b/code/core/_settings/development_generated.py new file mode 100644 index 0000000..8b4d77b --- /dev/null +++ b/code/core/_settings/development_generated.py @@ -0,0 +1,169 @@ +# this file contains settings that are automatically generated +# put custom commands/ imports in a separate file! + +LOCAL_SETTINGS = True # avoid recursive imports +BRANCH = 'development' + +from core.settings import * + +import logging + +LOCAL_LOGGING_PREFIX = "%s %%(message)s" % BRANCH +logging.basicConfig(format=LOCAL_LOGGING_PREFIX, level=logging.DEBUG) + +SITE_ID = 1 + +TEMPLATES[0]['DIRS'].append( + "/Users/ronny/projects/django/api-sandbox.prj/share/templates") + +# +# NOTE: a lot of the code in these local settings files are automated and you +# might be inclined to take them out and move them into the main settings.py +# file. That would be a mistake. These automatic files AT THE VERY LEAST have +# one variable, and that is WHICH BRANCH CONFIGURATION FILE ARE WE LOOKING AT. +# Once I set that file, THEN all the rest of the information can be automated. +# So all these automated info needs to be here. + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql', + 'NAME': 'api-sandbox_dvp', + 'USER': 'ronny', + 'PASSWORD': 'admin', + 'HOST': 'localhost', + 'PORT': '49041', + } +} + + +# +# directory from which we serve static files +# +# NOTE: both STATIC and MEDIA roots are getting their values from the +# initialization files that are set up above. Also, MEDIA_ROOT is being set +# to something called "paths.server.media.dynamic" - the names are different, +# but it means the same thing. +# +# MEDIA_ROOT is the dynamic media information that the web server, user or +# admin # will be adding and taking out. It's why I call it "dynamic" + +STATIC_ROOT = '/usr/local/var/www/api-sandbox.dvp/public/media/static' +MEDIA_ROOT = '/usr/local/var/www/api-sandbox.dvp/public/media/dynamic' + +# directories from which we search for static files to place in STATIC_ROOT +# these static files are located within the project root as opposed to the +# server root location + +STATICFILES_DIRS = ( + os.path.join("/Users/ronny/projects/django/api-sandbox.prj", "share", "media"), +) + +# debug and debug toolbar settings +DEBUG = True +TEMPLATES[0]['OPTIONS']['debug'] = DEBUG +USE_DEBUG_TOOLBAR = DEBUG + +# allow template debug outputs on development environment +INTERNAL_IPS = ['127.0.0.1', '127.0.0.2', '127.0.0.3', ] + +ALLOWED_HOSTS = ['api-sandbox.dvp', 'PROJECT_NAME.BRANCH_EXT', 'localhost', '127.0.0.1'] + +# ----------------------------------------- +# Debug logging to the console + +LOGGING = { + 'version': 1, + 'disable_existing_loggers': False, + + 'formatters': { + 'verbose': { + 'format': "%(levelname)s %(asctime)s %(module)s %(process)d" + " %(thread)d %(message)s" + }, + 'simple': { + 'format': '%(levelname)s:%(module)s - %(message)s' + }, + + 'code': { + 'format': "%(module)s:%(funcName)s:%(lineno)d - %(message)s" + }, + + 'code.file': { + 'format': "%(levelname)s %(module)s:%(funcName)s - %(message)s\n" + }, + }, + + 'handlers': { + 'file.log': { + 'class': 'logging.FileHandler', + + 'filename': + '/Users/ronny/projects/django/api-sandbox.prj/var/log/django.log', + + 'formatter': 'code.file' + }, + + 'file.log.debug': { + 'class': 'logging.FileHandler', + + 'filename': + '/Users/ronny/projects/django/api-sandbox.prj/var/log/django.log.debug', + + 'formatter': 'code.file' + }, + + 'server.file.log.debug': { + 'level': 'DEBUG', + 'class': 'logging.FileHandler', + + 'filename': + '/usr/local/var/www/api-sandbox.dvp/logs/django/django.log.debug', + + 'formatter': 'code.file' + }, + + 'console': { + 'class': 'logging.StreamHandler', + 'formatter': 'simple' + }, + + 'console.code': { + 'class': 'logging.StreamHandler', + 'formatter': 'code', + }, + + 'null': { + 'class': 'logging.NullHandler', + } + }, + + 'root': { + # automatically set to level WARNING + + 'handlers': ['console.code', 'file.log', 'server.file.log.debug' ], + 'propagate': True, + }, + + 'loggers': { + 'django.info': { + 'handlers': + [ + 'console', + 'file.log' + ], + 'level': 'INFO', + 'propagate': False, + }, + + 'django.debug': { + 'handlers': + [ + 'console.code', + 'file.log.debug', + 'server.file.log.debug', + ], + 'level': 'DEBUG', + 'propagate': True, + }, + } +} diff --git a/code/core/_settings/development_generated.py.bak b/code/core/_settings/development_generated.py.bak new file mode 100644 index 0000000..8b4d77b --- /dev/null +++ b/code/core/_settings/development_generated.py.bak @@ -0,0 +1,169 @@ +# this file contains settings that are automatically generated +# put custom commands/ imports in a separate file! + +LOCAL_SETTINGS = True # avoid recursive imports +BRANCH = 'development' + +from core.settings import * + +import logging + +LOCAL_LOGGING_PREFIX = "%s %%(message)s" % BRANCH +logging.basicConfig(format=LOCAL_LOGGING_PREFIX, level=logging.DEBUG) + +SITE_ID = 1 + +TEMPLATES[0]['DIRS'].append( + "/Users/ronny/projects/django/api-sandbox.prj/share/templates") + +# +# NOTE: a lot of the code in these local settings files are automated and you +# might be inclined to take them out and move them into the main settings.py +# file. That would be a mistake. These automatic files AT THE VERY LEAST have +# one variable, and that is WHICH BRANCH CONFIGURATION FILE ARE WE LOOKING AT. +# Once I set that file, THEN all the rest of the information can be automated. +# So all these automated info needs to be here. + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql', + 'NAME': 'api-sandbox_dvp', + 'USER': 'ronny', + 'PASSWORD': 'admin', + 'HOST': 'localhost', + 'PORT': '49041', + } +} + + +# +# directory from which we serve static files +# +# NOTE: both STATIC and MEDIA roots are getting their values from the +# initialization files that are set up above. Also, MEDIA_ROOT is being set +# to something called "paths.server.media.dynamic" - the names are different, +# but it means the same thing. +# +# MEDIA_ROOT is the dynamic media information that the web server, user or +# admin # will be adding and taking out. It's why I call it "dynamic" + +STATIC_ROOT = '/usr/local/var/www/api-sandbox.dvp/public/media/static' +MEDIA_ROOT = '/usr/local/var/www/api-sandbox.dvp/public/media/dynamic' + +# directories from which we search for static files to place in STATIC_ROOT +# these static files are located within the project root as opposed to the +# server root location + +STATICFILES_DIRS = ( + os.path.join("/Users/ronny/projects/django/api-sandbox.prj", "share", "media"), +) + +# debug and debug toolbar settings +DEBUG = True +TEMPLATES[0]['OPTIONS']['debug'] = DEBUG +USE_DEBUG_TOOLBAR = DEBUG + +# allow template debug outputs on development environment +INTERNAL_IPS = ['127.0.0.1', '127.0.0.2', '127.0.0.3', ] + +ALLOWED_HOSTS = ['api-sandbox.dvp', 'PROJECT_NAME.BRANCH_EXT', 'localhost', '127.0.0.1'] + +# ----------------------------------------- +# Debug logging to the console + +LOGGING = { + 'version': 1, + 'disable_existing_loggers': False, + + 'formatters': { + 'verbose': { + 'format': "%(levelname)s %(asctime)s %(module)s %(process)d" + " %(thread)d %(message)s" + }, + 'simple': { + 'format': '%(levelname)s:%(module)s - %(message)s' + }, + + 'code': { + 'format': "%(module)s:%(funcName)s:%(lineno)d - %(message)s" + }, + + 'code.file': { + 'format': "%(levelname)s %(module)s:%(funcName)s - %(message)s\n" + }, + }, + + 'handlers': { + 'file.log': { + 'class': 'logging.FileHandler', + + 'filename': + '/Users/ronny/projects/django/api-sandbox.prj/var/log/django.log', + + 'formatter': 'code.file' + }, + + 'file.log.debug': { + 'class': 'logging.FileHandler', + + 'filename': + '/Users/ronny/projects/django/api-sandbox.prj/var/log/django.log.debug', + + 'formatter': 'code.file' + }, + + 'server.file.log.debug': { + 'level': 'DEBUG', + 'class': 'logging.FileHandler', + + 'filename': + '/usr/local/var/www/api-sandbox.dvp/logs/django/django.log.debug', + + 'formatter': 'code.file' + }, + + 'console': { + 'class': 'logging.StreamHandler', + 'formatter': 'simple' + }, + + 'console.code': { + 'class': 'logging.StreamHandler', + 'formatter': 'code', + }, + + 'null': { + 'class': 'logging.NullHandler', + } + }, + + 'root': { + # automatically set to level WARNING + + 'handlers': ['console.code', 'file.log', 'server.file.log.debug' ], + 'propagate': True, + }, + + 'loggers': { + 'django.info': { + 'handlers': + [ + 'console', + 'file.log' + ], + 'level': 'INFO', + 'propagate': False, + }, + + 'django.debug': { + 'handlers': + [ + 'console.code', + 'file.log.debug', + 'server.file.log.debug', + ], + 'level': 'DEBUG', + 'propagate': True, + }, + } +} diff --git a/code/core/asgi.py b/code/core/asgi.py new file mode 100644 index 0000000..e36e2c8 --- /dev/null +++ b/code/core/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for core project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/5.2/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings') + +application = get_asgi_application() diff --git a/code/core/settings.py b/code/core/settings.py new file mode 100644 index 0000000..21337e2 --- /dev/null +++ b/code/core/settings.py @@ -0,0 +1,145 @@ +""" +Django settings for api-sandbox project. + +Generated by 'django-admin startproject' using Django 4.2.1. + +For more information on this file, see +https://docs.djangoproject.com/en/4.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/4.2/ref/settings/ +""" + +import os +import sys + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +PROJECT_ROOT = os.path.abspath(os.path.join(BASE_DIR, os.pardir)) + +# +# add the directory that has the intialize.py module which contains the +# get_config function definition which will pull out all the configuraiton +# infomration for the settings file + +sys.path.insert(0, os.path.join( + PROJECT_ROOT, 'usr/bin/customfabric')) + +# +# add an "apps" directory to this project, which is where all the apps +# ought to be in the first place. + +sys.path.insert(0, os.path.join(BASE_DIR, 'apps')) + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'Q*B7#Of9xYNaR<$V02?rLnWHz@K;Vy,q9Y=9[Wd%jbasic + +###### app domains + +add the top level domain and the full domain. should look like + + drftesting.net + oauth.drftesting.net + +go a little further down and click on the button that says "add platform" + +###### Site URL +put the full site url in with "https" + + https://oauth.drftesting.net/ + +##### under products + +products->facebook login->configure (dropdown) -> settings + +set Embedded Browser OAuth Login to yes + +##### in Valid OAuth Redirect URIs add the callback url: + +example url: + + https://oauth.drftesting.net/accounts/facebook/login/callback/ + +######source on creating and setting up a facebook app + [configure facebook login](https://help.sharetribe.com/en/articles/666072-configure-facebook-login) + +######django alluth doc on how to configure callback + [django allauth callback](https://django-allauth.readthedocs.io/en/latest/socialaccount/providers/index.html?highlight=callback) + +## how to get a test authentication token + +https://developers.facebook.com/docs/marketing-apis/overview/authentication/ + + + + diff --git a/share/readmes/authorization_oauth_social_auth_facebook.md b/share/readmes/authorization_oauth_social_auth_facebook.md new file mode 100644 index 0000000..d2562ec --- /dev/null +++ b/share/readmes/authorization_oauth_social_auth_facebook.md @@ -0,0 +1,32 @@ +in order to use the facebook login with our DRF we need to first get an access token from facebook + +then we must login to an OAuth2 application to get an authorization token from our system + +so we must have an OAuth Application set up before we can use the facebook token with the DRF + +1. install [Django OAuth Toolkit](https://django-oauth-toolkit.readthedocs.io/en/latest/) +2. read and apply [Step 3: Register an application](https://django-oauth-toolkit.readthedocs.io/en/latest/rest-framework/getting_started.html#step-3-register-an-application) + +note: step 2 can be done in the admin under Django OAuth Toolkit > Application + +1. install the [Django rest-framework Social OAuth2](https://github.com/RealmTeam/django-rest-framework-social-oauth2) package +2. go to the facebook developers [debug access token](https://developers.facebook.com/tools/accesstoken/) page, and get a fake user access token +3. test it using the shell script *facebook_convert.sh* which is located in **/opt/shell-commands/social_rest** +4. or just run the command + +`curl -X POST -d "grant_type=convert_token` +`&client_id=$CLIENT_ID` +`&client_secret=$CLIENT_SECRET` +`&backend=facebook` +`&token=$FACEBOOK_USER_TOKEN"` +` $baseurl/auth/convert-token` + +where CLIENT\_ID, CLIENT\_SECRET, AND FACEBOOK\_USER\_TOKEN are all either variables or direct values put in the proper places + +CLIENT\_ID and CLIENT_SECRET you get from the OAuth application you created before. That application manages authorized user tokens to let users make DRF requests on authorization only parts of the system + +FACEBOOK\_USER\_TOKEN is a value you get **AFTER** you've logged into facebook. at the facebook developers [debug access token page](https://developers.facebook.com/tools/accesstoken/) you look up the Facebook app you are trying to log into, and get a debug user access token. + +In production, this means that you ahve to log into facebook **only** via web or by ios, you **absolutely cannot** log into facebook by the command line. No way. + +So in production you will have to retrieve the access token facebook provides after login, *then* make the call to retrieve *yet another* access token from the Django OAuth Application you set up on your web server. \ No newline at end of file diff --git a/share/readmes/authorization_tokens_testing.md b/share/readmes/authorization_tokens_testing.md new file mode 100644 index 0000000..908503f --- /dev/null +++ b/share/readmes/authorization_tokens_testing.md @@ -0,0 +1,103 @@ + +# getting testing authorization tokens for the django rest framework + +The purpose of this readme is to explain how to retrieve testing tokens that can be passed into the django rest framework's oauth authorization to retrieve a user token + +currently, this document will list how to get testing tokens for the following platforms: + +- facebook +- google + +## facebook + +### getting an access token for testing + +to get a testing token, go to graph api explorer + +1. under "meta app", select the application you want a token for +2. under "user or page", select "user token" from the dropdown +3. under "add a permission", select "email" from the dropdown +4. then hit "generate access token" button, and you're good to go + +[graph api explorer](https://developers.facebook.com/tools/explorer/) + + +#### sources +[configure facebook login](https://help.sharetribe.com/en/articles/666072-configure-facebook-login) + +[getting a testing token for authentication](https://developers.facebook.com/docs/marketing-apis/overview/authentication/) + + +## google + + +### notes + +in the case of the google provider we don't actually want the +access token what we want is the ID TOKEN that is returned + +#### setting up credentials + +To use OAuth playground to get the id token, you have to first set +the Authorized Redirect URLs in the oauth credential section to at least have: + https://developers.google.com/oauthplayground + +#### oauth playground + +next in OAuth Playground, set it up to use your client + +1. click the settings wheel in the upper left corner +2. click on 'use your own OAUTH credentials' +3. enter the client id and client secret + +##### Step1 + +go to Step1 Select & authorize APIs + +1. find Google OAuth2 API v2 +2. select unserinfo.email and userinfo.profile +3. click Authorize APIs + +##### Step2 + +go to Step 2 Exchange authorization code for tokens + +1. click Exchange authorization code for tokens +2. IGNORE access and refresh token!!! they are not relevant! +3. go to the right panel Request / Response + - in the json data, find 'id_token' +4. paste the id token in the field for auth_token in swagger + + +#### sources + +[Using OAuth 2.0 to access Google APIs](https://medium.com/@anupama.pathirage/using-oauth-2-0-to-access-google-apis-1dbd01edea9a#:~:text=In%20a%20separate%20browser%20window,obtained%20in%20the%20previous%20step.) + +[django allauth callback](https://django-allauth.readthedocs.io/en/latest/socialaccount/providers/index.html?highlight=callback) + + + +# old info in this page + +### Notes + +facebook authorization requests are different than straight user/pass requests. One requires the user and pass registered with the django app when they signed in, etc. The other is via the users facebook account. + +So the user must paas in his facebook account name and password + +#### try using standard api get token method + +Unlike the facebook request,this one passes the username and password that is already stored in Django + +http http://127.0.0.1:8026/api-token-auth/ username=someuser1 password=testpass1 + + +got to [facebook dev apps](https://developers.facebook.com/apps/) + +get the + +facebook test user name/pass +get client id and client secret from settings + +apply: +`curl -X POST -d "client_id=&client_secret=&grant_type=password&username=&password=" http://localhost:8000/auth/token diff --git a/share/readmes/aws.md b/share/readmes/aws.md new file mode 100644 index 0000000..5070c38 --- /dev/null +++ b/share/readmes/aws.md @@ -0,0 +1,386 @@ + + +## links + + +#### visudo + +[configuring visudo](http://askubuntu.com/questions/539243/how-to-change-visudo-editor-from-nano-to-vim) + +#### users + +[tecmint.com complete guide to users](http://www.tecmint.com/add-users-in-linux/) + +[How To Configure SSH Key-Based Authentication on a Linux Server](https://www.digitalocean.com/community/tutorials/how-to-configure-ssh-key-based-authentication-on-a-linux-server) + +#### postgres + +[ubuntu community postgres docs](https://help.ubuntu.com/community/PostgreSQL) + +#### certbot + +[certbot webpage to install ssl certificates](https://certbot.eff.org) + +#### docker +[ubuntu docker ce install](https://docs.docker.com/install/linux/docker-ce/ubuntu/) + +[ubuntu docker compose install](https://docs.docker.com/compose/install/) + + +## adding/deleting users + +#### adding a user: + +*("www-data" is the group name for website stuff on gandi)* + +> *sudo useradd -G* ***www-data*** *-d /home/****username*** *-m -s /bin/bash* ***username*** + +***-G group*** adds the groups in a comma separated + +***-d /home/username*** specifies the home directory to be created (necessary on ubuntu) + +***-m*** flag to create scripts (necessary) + +***-s /bin/bash*** what shell is to be used (default is none) + +#### deleting a user + + userdel -r {username} + +## IMPORTANT +### set users primary group + +**this is critical** + + sudo usermod -g www-data + + +### setting up ssh authentication + +cat ~/.ssh/id\_rsa.pub | ssh **username@remote\_host** "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized\_keys" + +## apt-get commands + +**to see the package version:** + + dpkg -s postgresql | grep Version + +# setting up aws server + +## creating the server instance + +[aws instance](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EC2_GetStarted.html) + +1. Open the [amazon EC2 console](https://console.aws.amazon.com/ec2/) +2. Choose **Launch Instance** +3. The *Choose an Amazon Machine Image (AMI)* page has basic configuration, so pick the first *ubuntu* configuration +4. This will take you to the *Choose an Instance Type* page, this chooses the hardware configuration, you want to pick **t2.micro** +5. Hit **Review and Launch** +6. This will take you to *Review Instance Launch* page, and that has an option for **Security Groups**, hit **Edit security groups**, on the page that pops up, pick the options you want to allow for your instance +7. When finished, hit "done" or whatever and you'll be taken back to the *Review Instance Launch* page, from here hit the **Launch** key +8. this will prompt you for a key pair. There are a few options. Create a new Pair and choose an existing key pair + +####key pair info: +[aws info on key pairs](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html) + +[importing id_rsa](http://www.admin-magazine.com/CloudAge/Blogs/Dan-Frost-s-Blog/Importing-SSH-keys-on-AWS) + +[add_ssh](http://stackoverflow.com/questions/8193768/trying-to-ssh-into-an-amazon-ec2-instance-permission-error) + +1. mv /path/to/myname.pem ~/.ssh +2. ssh-add ~/.ssh/myname.pem +3. ssh ubuntu@INSTANCE_IP_ADDRESS + +Remember that the IP ADDRESS changes whenever you restart the instance + +on your computer + +1. vim /etc/hosts +2. add a line with the server name and IP ADDRESS for that insntace +3. ssh ubuntu@SERVERNAME + +## updating the hostname + +[aws ubuntu hostname](https://aws.amazon.com/premiumsupport/knowledge-center/linux-static-hostname/) + +[scroll down to find the "echo" comment](https://forums.aws.amazon.com/message.jspa?messageID=495274) + +there is an issue with ubuntu instances on AWS, the name given in /etc/hostname doesn't match what exist in /etc/hosts. So if you try using sudo you'll get an error. + +To fix this, you need to change those files, to get into sudo type in: + + sudo su - + echo "127.0.0.1 $(hostname)" >> /etc/hosts + +This will update /etc/hosts with the default hostname generated by amazon. Alternatively you can do what it says in the first link [aws ubuntu hostname](https://aws.amazon.com/premiumsupport/knowledge-center/linux-static-hostname/) + + +### setup visudo + + sudo update-alternatives --config editor + + su -c 'visudo' + +find this line: + + USERNAME ALL=(ALL) NOPASSWD: ALL + +replace it with: + + admin ALL=(ALL) ALL + + +## add new user + +[adding a user on linux AWS](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/managing-users.html) + +[how to get an add the public key to the new user](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html#retrieving-the-public-key) + +1. *sudo useradd -G* ***www-data*** *-d /home/****username*** *-m -s /bin/bash* ***username*** +2. *mkdir projectdir* + +### set users primary group + +**this is critical** +- The primary group is the group applied to you when you log in using the usual methods (TTYs, GUI, SSH, etc.). + + sudo usermod -g www-data + +### set password + + sudo passwd + +### setting up ssh authentication + +1. get the public key: + + ssh-keygen -y -f /path/to/myinstance.pem + +2. copy the above results + +3. log in to the ubuntu instance using default ubuntu user + +4. change users to the custom username + + sudo su - username + +5. create the ssh directory and auth file + + cd /home/username + mkdir .ssh + touch .ssh/authorized_keys + vim ~/.ssh/authorized_keys + +6. change the permissions + + chown -R username:username_gropus .ssh + chmod 700 .ssh + chmod 600 .ssh/authorized_keys + +7. now paste in the public_key you got in step 1 +8. log out and test with the username + + ssh username@instance.domain + +### add username to the sudo group +AWS has a sudo group that allows a user sudo priveleges + + usermod -a -G sudo username + +### apt-get setup + + sudo apt-get update + sudo apt-get install aptitude + + +## postgres + +### note: +if you are using docker for postgres, skip this and go to the docker section. It is completely unnecessary and you don't even need to install postgres + + +#### links fix locale error with postgres + +[could not connect to server solution](http://askubuntu.com/questions/50621/cannot-connect-to-postgresql-on-port-5432) + +[locale solution](http://ubuntuforums.org/showthread.php?t=1346581) + +[remote connecting](http://www.railszilla.com/postgresql-tcpip-connections-port-5432/coffee-break) + + sudo apt-get install postgresql + sudo apt-get install postgresql-contrib + sudo locale-gen en_US en_US.UTF-8 hu_HU hu_HU.UTF-8 + sudo dpkg-reconfigure locales + sudo service postgresql restart + sudo -u postgres psql postgres + sudo -u postgres createdb **website_dbname** + + sudo apt-get install postgresql-server-dev-X.Y + sudo apt-get install postgresql-server-dev-9.3 + +#### change password for db user "postgres" + sudo -u postgres psql postgres + + ALTER USER Postgres WITH PASSWORD ''; + +#### set up postgresql to remote access + +######(see "remote connecting" link above) + +#####Note: be careful with this, because **anyone** will be able to mess around with it + +1. sudo vim /etc/postgresql/9.3/main/postgresql.conf +2. find **listen\_addresses** and change it to **listen\_addresses = '\*'** +3. sudo vim /etc/postgresql/9.3/main/pg_hba.conf +4. find **host all all 127.0.0.1/32 trust** and change **127.0.0.1/32** to **0.0.0.0/0** +5. sudo service postgresql restart +6. test it by running: *psql -h* ***ip\_address*** *-U* ***username*** *-d* ***database*** +7. e.g. psql -h 173.246.107.96 -U postgres postgres + + + +## setup the /var/www directory + + cd /var + sudo mkdir www + sudo chgrp www-data www -R + sudo chmod g+w www -R + +## install python packages + + sudo apt-get install python-dev + sudo apt-get install python3-dev + sudo apt-get install libjpeg-dev + + +## install and set up supervisor + + sudo apt-get install supervisor + +make sure www-data is a group for the main user + + vim /etc/supervisor/supervisord.conf + +add the following: + + [unix_http_server] + file=/var/run/supervisor.sock + chmod=0770 + chown=nobody:www-data + + [supervisorctl] + serverurl=unix:///var/run//supervisor.sock + chmod=0770 + chown=nobody:www-data + +#### run the following commands: + + sudo service supervisor stop + sudo service supervisor start + +### install pip and virtualenv + +[virtualenv install](http://roundhere.net/journal/virtualenv-ubuntu-12-10/) + + sudo apt-get install python-pip + sudo pip install virtualenv + sudo pip install virtualenvwrapper + + echo "WORKON_HOME=~/.virtualenvs" >> .bashrc + echo ". /usr/local/bin/virtualenvwrapper.sh" >> .bashrc + +## Docker + +### docker + +##### uninstall old (if necessary) + sudo apt-get remove docker docker-engine docker.io containerd runc + +##### set up apt-get + + sudo apt-get update + sudo apt-get install \ + apt-transport-https \ + ca-certificates \ + curl \ + gnupg-agent \ + software-properties-common + +##### verify install + +check that fingerprint key "9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88" is the same + + curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - + + sudo apt-key fingerprint 0EBFCD88 + +##### install repository + sudo add-apt-repository \ + "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ + $(lsb_release -cs) \ + stable" + +##### install docker + + sudo apt-get update + sudo apt-get install docker-ce docker-ce-cli containerd.io + +### docker-compose + sudo curl -L "https://github.com/docker/compose/releases/download/1.25.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose + + sudo chmod +x /usr/local/bin/docker-compose + + +## nginx + + sudo apt-get install nginx + + +## certbot + +In order to use ssl/https it is necessary to install a certificate. This is especially true if the nginx config file has *already* been set up to use ssl. (for example, you are reinstalling an environment, or creating production based on staging, etc) + +[certbot.eff.org](certbot.eff.org) allows you to install a free certificate + +#### add certbot ppa + + sudo apt-get update + sudo apt-get install software-properties-common + sudo add-apt-repository universe + sudo add-apt-repository ppa:certbot/certbot + sudo apt-get update + +#### install certbot + + sudo apt-get install certbot python-certbot-nginx + +#### Choose how you'd like to run certbot +##### OPTION1: get and install your certificates + sudo apt-get install certbot python-certbot-nginx +##### OPTION2: just get the certificate (already configured) + sudo certbot --nginx + +Use Option1 when you are just starting a project, but you know you are going to be using SSL + +Use Option2 when you have already set up nginx to work with https, for example, you are reinstalling an existing project, etc. + +## set up vim remote editing +this just means adding the server pem file location to .ssh/config + +in ~/.ssh/config add the following info + + Host minionfinder.com + HostName minionfinder.com + IdentityFile /Users/ronny/projects/django/minyanfinder.prj/share/ssh/minionfinder.pem + +where *minionfinder.com* refers to the host name +and the **IdentityFile** section is the fully qualified pathname of the pem file + +# bootstrap server + + fab (prod|rel) deploy.bootstrap + + + + + diff --git a/share/readmes/certbot.md b/share/readmes/certbot.md new file mode 100644 index 0000000..b2462cd --- /dev/null +++ b/share/readmes/certbot.md @@ -0,0 +1 @@ +certbot looks through all configuration files and modifies them for ssl diff --git a/share/readmes/curl.md b/share/readmes/curl.md new file mode 100644 index 0000000..64a9220 --- /dev/null +++ b/share/readmes/curl.md @@ -0,0 +1,46 @@ +## Multiple header values +when you have more than one header value, ie you want to pass the authentication token **and** you want to pass json values + +simply state each header value separately while preceeding it with the -H/--header prefix + +e.g. + +`-H "Authentication: Bearer 2342343" \` +`-H "Content-Type: application/json" ` + +note the forward slash \ is used to separate between lines for readability + +## Passing the Authentication token + +get an authentication token from the server +then pass it in through the header + +`--header "Authorization: Bearer ` + + + +## Passing Json Values Through Curl + +##### step 1 - set the header +`--header "Content-Type: application/json"` + +##### step 2 - encode the values +`-d "{\"name\":\"$2\", \"code\":\"$3\"}"` + +the bracketed area must be enclose with double quotes (single could work, but we need to change the parameters into strings, and bash does not seem to do that with singles) + +the parameter names and values must also be enclosed in **backslashed** double quotes + +`\"` + +this means the entire string has to be enclosed in normal doubles instead of singles to interpolate the values + + +## various + +[how can i set the request header for curl](https://stackoverflow.com/questions/4212503/how-can-i-set-the-request-header-for-curl/45313572) + +[curl snippets](https://gist.github.com/subfuzion/08c5d85437d5d4f00e58) + +###### interpolate +*insert (something of a different nature) into something else.* \ No newline at end of file diff --git a/share/readmes/debug_toolbar.md b/share/readmes/debug_toolbar.md new file mode 100644 index 0000000..a6eaa5f --- /dev/null +++ b/share/readmes/debug_toolbar.md @@ -0,0 +1,13 @@ + +# Problem with Django Debug Toolbar + +If the Django Debug Toolbar runs on the admin but not on your apps, this might be the issue and solution: + +The problem turned out to be that the ` ... ` tags were not rendered in the template. Adding them to my template fixed the issue. + +It's interesting that the Django tutorial doesn't use a template with a complete HTML document, yet it specifically mentions following the installation directions for the Django Debug Toolbar, even though the app won't work with it as presented. + +Anyway, many thanks to u/reallydarkcloud for the insightful response. + + +https://www.reddit.com/r/django/comments/15k68fa/djangodebugtoolbar_works_in_the_admin_but_not_in/ diff --git a/share/readmes/fontawesome.md b/share/readmes/fontawesome.md new file mode 100644 index 0000000..556e0c9 --- /dev/null +++ b/share/readmes/fontawesome.md @@ -0,0 +1,35 @@ +###specify the font path to the "webfonts directory" + +$fa-font-path: "../node_modules/@fortawesome/fontawesome-free/webfonts" !default; + +###when importing from an app-local installation: + +in this case "coffesshop" is the name of the app + +`@import 'coffeeshop/node_modules/\@fortawesome/fontawesome-free/scss/fontawesome'` +`@import 'coffeeshop/node_modules/\@fortawesome/fontawesome-free/scss/solid'` +`@import 'coffeeshop/node_modules/\@fortawesome/fontawesome-free/scss/brands'` + +### when importing from a shared directory + +#### set the location in static and sass + +`STATICFILES_DIRS = [ + os.path.join( + PROJECT_ROOT, + 'share/media/node_modules/@fortawesome'), +]` + +`SASS_PROCESSOR_INCLUDE_DIRS = [ + os.path.join( + PROJECT_ROOT, + 'share/media/node_modules/@fortawesome'), +]` + +#### now import directly from where you set loc above + +`@import 'fontawesome-free/scss/fontawesome'` +`@import 'fontawesome-free/scss/solid'` +`@import 'fontawesome-free/scss/brands'` + + diff --git a/share/readmes/foundation.md b/share/readmes/foundation.md new file mode 100644 index 0000000..1d069c1 --- /dev/null +++ b/share/readmes/foundation.md @@ -0,0 +1,132 @@ +# How to install Foundation Zurb + +## Resources +* [node js](https://nodejs.org/en/download/) +* [foundation zurb](foundation.zurb.com) + + +## install nodeenv + +[how to install nodeenv](https://calvinx.com/2013/07/11/python-virtualenv-with-node-environment-via-nodeenv/) + +1. mkvirtualenv myproject1 +2. pip install nodeenv +3. nodeenv -p +4. deactivate; workon myproject1 +5. npm install -g foundation-cli +6. npm install -g autoprefixer +7. npm install -g generate +8. npm install -g postcss-cli + +## install django sass processor + +github url [django sass processor](https://github.com/jrief/django-sass-processor) + + pip install django-sass-processor + +### add to installed apps + + sass_processor + +### additional configuration settings + +#### set extensions to look for + +sass processor searches template files to find links to sass stylesheets. If using templates with a .django extension, you have to set the ext types you want the processor to search + + SASS_TEMPLATE_EXTS = ['.django', '.html'] + +#### file search root directory + +set the root value for which sass processor will search for sass files (set to the same value as static root) + + SASS_PROCESSOR_ROOT = STATIC_ROOT + +#### add cssfinder to static file finders + +we need to tell the static finders thingie to use sass_processor + + STATICFILES_FINDERS = [ + 'django.contrib.staticfiles.finders.FileSystemFinder', + 'django.contrib.staticfiles.finders.AppDirectoriesFinder', + 'sass_processor.finders.CssFinder', + ] + +#### directories to look through + +you must tell django wher eto find static files that you want to look through if you want to use them in a template + +you must also tell the sass processor where those files are if you want the sass processor to be able to do anything with it + + STATICFILES_DIRS = [ + ('node_modules', + os.path.join( + PROJECT_ROOT, + 'share/media/node_modules/')), + + os.path.join( + PROJECT_ROOT, + 'share/media/node_modules/foundation-sites/scss'), + ] + + SASS_PROCESSOR_INCLUDE_DIRS = [ + os.path.join(PROJECT_ROOT, 'share/media/node_modules'), + os.path.join(PROJECT_ROOT, + 'share/media/node_modules/foundation-sites/scss'), + ] + +Notice how "node modules" is attached without a prefix. + +also, I add direct links to the scss of the underlying packages so I can import them with a direct command + + @import foundation + +_instead of_ + + @import foundation-sites/scss/foundation + +When you want to import sass modules underneath the "node_modules" directory you must refer to the directory structure _underneath_ the node modules structure: + + @import foundation-sites/scss/foundation + +however, to directly import the foundation sass library, you must do so through the "assets" directory referenced in static. + +so foundation-sites/assets refers to what will be used in static, and foundation-sites/scss/foundation refers to compiling + +### Usage + + {% load sass_tags %} + + + + +## installing Zurb Foundation Template + +[how to install foundation with django](https://www.physics.utoronto.ca/~icom/workshop/django-install/foundation.html) + +either open up the virtualenv that contains foundation-cli or create one, or just install foundation-cli + +create a new template + + foundation new + +## installing via foundation-sites + + npm install foundation-sites + +# Alternate way of loading Foundation + +install foundation-sites +link to foundation-sites parent directory + + ln -s /pathto/node_modules/foundation-sites /pathto/sass/foundation-sites + +inside the sass file import foundation as + + @import foundation-sites/scss + + + + + diff --git a/share/readmes/gandi.md b/share/readmes/gandi.md new file mode 100644 index 0000000..e6a598e --- /dev/null +++ b/share/readmes/gandi.md @@ -0,0 +1,233 @@ + + +## links + +#### gandi + +[connecting to gandi server](https://wiki.gandi.net/en/hosting/using-linux/how_to_connect_ai) + +[accessing the server via ssh](https://wiki.gandi.net/en/hosting/using-linux/server-access) + +[first steps with gandi server](https://wiki.gandi.net/en/hosting/gandi-expert/setup) + +#### visudo + +[configuring visudo](http://askubuntu.com/questions/539243/how-to-change-visudo-editor-from-nano-to-vim) + +#### users + +[tecmint.com complete guide to users](http://www.tecmint.com/add-users-in-linux/) + +[How To Configure SSH Key-Based Authentication on a Linux Server](https://www.digitalocean.com/community/tutorials/how-to-configure-ssh-key-based-authentication-on-a-linux-server) + +#### postgres + +[ubuntu community postgres docs](https://help.ubuntu.com/community/PostgreSQL) + + +## adding/deleting users + +#### adding a user: + +*("www-data" is the group name for website stuff on gandi)* + +> *sudo useradd -G* ***www-data*** *-d /home/****username*** *-m -s /bin/bash* ***username*** + +***-G group*** adds the groups in a comma separated + +***-d /home/username*** specifies the home directory to be created (necessary on ubuntu) + +***-m*** flag to create scripts (necessary) + +***-s /bin/bash*** what shell is to be used (default is none) + +#### deleting a user + + userdel -r {username} + +## IMPORTANT +### set users primary group + +**this is critical** + + sudo usermod -g www-data + + +### setting up ssh authentication + +cat ~/.ssh/id\_rsa.pub | ssh **username@remote\_host** "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized\_keys" + +## apt-get commands + +**to see the package version:** + + dpkg -s postgresql | grep Version + +# setting up gandi server + +## creating the server instance + +after logging in, go to the virtual machine setup tab under *services* -> *servers* + +[virtual machine](https://www.gandi.net/admin/iaas/vm) + +under "servers" click "create a server". At the setup page you will have the option of either using an public ssh key, a password, or both. Pick both. + +1. generate a password +2. go to ~/.ssh and look for something like *id_rsa.pub* +3. to put in on the clipboard, on OSX type *cat ~/.ssh/id_rsa.pub | pbcopy* +4. paste what's in the clipboard into the ssh input section +5. copy all this information down and start it up + + +## first steps with server + +next follow the links under "gandi" + +while you are doing the commands link *"first steps with gandi server"* you may want to do this command: + + su -c 'apt-get install sudo' + su -c 'apt-get install vim' + +after setting up "first steps with gandi server" above, you will want to configure visudo to use vim + +### setup visudo + + su -c 'update-alternatives --config editor' + + su -c 'visudo' + +find this line: + + USERNAME ALL=(ALL) NOPASSWD: ALL + +replace it with: + + admin ALL=(ALL) ALL + +(or whatever user name you are mainly using) + +## add new user + +1. *sudo useradd -G* ***www-data*** *-d /home/****username*** *-m -s /bin/bash* ***username*** +2. *mkdir projectdir* + +### set users primary group + +**this is critical** + + sudo usermod -g www-data + +### set password + + sudo passwd + +### setting up ssh authentication + +cat ~/.ssh/id\_rsa.pub | ssh **username@remote\_host** "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized\_keys" + +### apt-get setup + + sudo apt-get update + sudo apt-get install aptitude + +## postgres + + +#### links fix locale error with postgres + +[could not connect to server solution](http://askubuntu.com/questions/50621/cannot-connect-to-postgresql-on-port-5432) + +[locale solution](http://ubuntuforums.org/showthread.php?t=1346581) + +[remote connecting](http://www.railszilla.com/postgresql-tcpip-connections-port-5432/coffee-break) + + sudo apt-get install postgresql + sudo apt-get install postgresql-contrib + sudo locale-gen en_US en_US.UTF-8 hu_HU hu_HU.UTF-8 + sudo dpkg-reconfigure locales + sudo service postgresql restart + sudo -u postgres psql postgres + sudo -u postgres createdb **website_dbname** + + sudo apt-get install postgresql-server-dev-X.Y + sudo apt-get install postgresql-server-dev-9.3 + +#### change password for db user "postgres" + sudo -u postgres psql postgres + + ALTER USER Postgres WITH PASSWORD ''; + +#### set up postgresql to remote access + +######(see "remote connecting" link above) + +#####Note: be careful with this, because **anyone** will be able to mess around with it + +1. sudo vim /etc/postgresql/9.3/main/postgresql.conf +2. find **listen\_addresses** and change it to **listen\_addresses = '\*'** +3. sudo vim /etc/postgresql/9.3/main/pg_hba.conf +4. find **host all all 127.0.0.1/32 trust** and change **127.0.0.1/32** to **0.0.0.0/0** +5. sudo service postgresql restart +6. test it by running: *psql -h* ***ip\_address*** *-U* ***username*** *-d* ***database*** +7. e.g. psql -h 173.246.107.96 -U postgres postgres + +### setup the /var/www directory + + cd /var + sudo mkdir www + sudo chgrp www-data www -R + sudo chmod g+w www -R + +### install python packages + + sudo apt-get install python-dev + sudo apt-get install libjpeg-dev + + +## install and set up supervisor + + sudo apt-get install supervisor + +make sure www-data is a group for the main user + + vim /etc/supervisor/supervisord.conf + +add the following: + + [unix_http_server] + file=/var/run//supervisor.sock + chmod=0770 + chown=nobody:www-data + + [supervisorctl] + serverurl=unix:///var/run//supervisor.sock + chmod=0770 + chown=nobody:www-data + +#### run the following commands: + + sudo service supervisor stop + sudo service supervisor start + +### install pip and virtualenv + +[virtualenv install](http://roundhere.net/journal/virtualenv-ubuntu-12-10/) + + sudo apt-get install python-pip + sudo pip install virtualenv + sudo pip install virtualenvwrapper + +### install nginx + + sudo apt-get install nginx + + +# bootstrap server + + fab (prod|rel) deploy.bootstrap + + + + + diff --git a/share/readmes/geo.md b/share/readmes/geo.md new file mode 100644 index 0000000..9984965 --- /dev/null +++ b/share/readmes/geo.md @@ -0,0 +1,25 @@ +##if you get the following error: + +django.core.exceptions.ImproperlyConfigured: Could not find the GDAL library (tried "gdal", "GDAL", "gdal2.2.0", "gdal2.1.0", "gdal2.0.0", "gdal1.11.0", "gdal1.10.0", "gdal1.9.0"). Is GDAL installed? If it is, try setting GDAL_LIBRARY_PATH in your settings. + +you must install on the host machine the following packages: +`sudo apt-get install binutils libproj-dev gdal-bin` + +next you must update POstgres to use POSTGIS + +[https://docs.djangoproject.com/en/2.1/ref/contrib/gis/install/postgis/](https://docs.djangoproject.com/en/2.1/ref/contrib/gis/install/postgis/) + +## update postgres + +### the following packages must be installed: +(x.x matching the PostgreSQL version you want to install) + +postgresql-x.x +postgresql-x.x-postgis +postgresql-server-dev-x.x +python-psycopg2 + +find out the postgres server number: + +`apt list --installed | grep 'post'` + diff --git a/share/readmes/gunicorn_error.md b/share/readmes/gunicorn_error.md new file mode 100644 index 0000000..70bd197 --- /dev/null +++ b/share/readmes/gunicorn_error.md @@ -0,0 +1,9 @@ + +## important gunicorn error + +https://stackoverflow.com/questions/53570850/djangogunicorn-operation-not-permitted; + +the problem is that if supervisor sets both user and group, and then gunicvorn does it, you can +get a blow up. + +so comment it out in one conf or the other diff --git a/share/readmes/nginx.md b/share/readmes/nginx.md new file mode 100644 index 0000000..a10e69d --- /dev/null +++ b/share/readmes/nginx.md @@ -0,0 +1,6 @@ +if you get a Django ERROR (EXTERNAL IP): Invalid HTTP_HOST header: '*.domain.com' + + +https://notabela.hashnode.dev/how-to-solve-the-domain-name-provided-is-not-valid-according-to-rfc-10341035-in-django-during-development + + diff --git a/share/readmes/paramiko.md b/share/readmes/paramiko.md new file mode 100644 index 0000000..919e08f --- /dev/null +++ b/share/readmes/paramiko.md @@ -0,0 +1 @@ +env LDFLAGS="-L$(brew --prefix openssl)/lib" CFLAGS="-I$(brew --prefix openssl)/include" pip install cryptography diff --git a/share/readmes/postgis.md b/share/readmes/postgis.md new file mode 100644 index 0000000..0c506a9 --- /dev/null +++ b/share/readmes/postgis.md @@ -0,0 +1,36 @@ +## how to set up postgis + + +use [docker-postgis](https://github.com/kartoza/docker-postgis) + + +#### setting docker-postgis to use django unit testing + + +1. get into the running docker shell +2. open postgresql client as postgres user (you have to do this from the command line in the container as you cannot do it remotely) +3. ALTER ROLE \ SUPERUSER; +4. set \ as admin + +now the admin can run the tests + +`sudo docker exec -it minyanfinder_development_db bash` + +#### another more elegant solution to the problem + +[create extension without superuser role](https://stackoverflow.com/questions/16527806/cannot-create-extension-without-superuser-role) + +[potential problem if it's not working](https://stackoverflow.com/questions/39556719/django-test-error-creating-the-test-database-permission-denied-to-copy-databas) + +createdb template_postgis; # create a new database +psql -U postgres -c "UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template_postgis';" # make it a template psql -U postpsql -U postgres -d template_postgis -c "CREATE EXTENSION postgis;" # install postgis in it + +example: +createdb -h localhost -p 49032 -U admin template_postgis +psql -h localhost -p 49032 -U admin minyanfinder_dev -c "UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template_postgis';" +psql -h localhost -p 49032 -U admin -d template_gis -c "CREATE EXTENSION postgis;" + +in local settings file: + +DATABASES['default']['TEST'] = dict() +DATABASES['default']['TEST']['TEMPLATE'] = 'template_postgis' diff --git a/share/readmes/psycopg2_problem.md b/share/readmes/psycopg2_problem.md new file mode 100644 index 0000000..8003250 --- /dev/null +++ b/share/readmes/psycopg2_problem.md @@ -0,0 +1 @@ + xcode-select --install diff --git a/share/readmes/regex.md b/share/readmes/regex.md new file mode 100644 index 0000000..379a19d --- /dev/null +++ b/share/readmes/regex.md @@ -0,0 +1,9 @@ +# useful regex commands + +## convert href to static + +`.s/href="\([^"]\+\)"/href="{% static '\1' %}"` + +use when **href="/some/link/file.css"** if the + +quotes are single quotes, then convert them to double \ No newline at end of file diff --git a/share/readmes/reset_migrations.md b/share/readmes/reset_migrations.md new file mode 100644 index 0000000..6598671 --- /dev/null +++ b/share/readmes/reset_migrations.md @@ -0,0 +1,49 @@ +I try different commands and some of the answers help me. Only this sequence in my case fixed both broken dependencies in migrations in MYAPP and clean all past migrations starting from scratch. + +Before doing this ensure that database is already synced (e.g. do not add a new Model field here or change Meta options). + +rm -Rf MYAPP/migrations/* +python manage.py makemigrations --empty MYAPP +python manage.py makemigrations +python manage.py migrate --fake MYAPP 0002 +Where 0002 is the migration number returned by the last makemigrations command. + +Now you can run makemigrations / migrate again normally because migration 0002 is stored but not reflected in the already-synced database. + +if you really want to go crazy delete all the tables in teh database related to the app and then + +DELETE FROM django_migrations WHERE app='registry' + + + +------- + + +this is what I do + +first I clear out everything: + +rm -Rf appname/migrations + +fab database.drop_all +fab database.init +fab django.manage:migrate +fab django.manage:syncdb + + +then I re-add the app + +fab django.manage:"makemigrations appname" +fab django.manage:migrate + + +at that point I have working table +so again + +rm -Rf {ON HOST}/appname/migrations +fab ONHOST database.drop_all +fab ONHOST database.init +fab ONHOST deploy.sync <--- CRITICAL STEP DO NOT FORGET +fab ONHOST django.manage:migrate +fab ONHOST django.manage:syncdb + diff --git a/share/readmes/sass.md b/share/readmes/sass.md new file mode 100644 index 0000000..ce517ae --- /dev/null +++ b/share/readmes/sass.md @@ -0,0 +1,22 @@ +##Sass + +### How to set up sass watch with multiple directories + +```` +sass -I share/media/projectwide_sass_files + --watch code/apps/sassdir:code/apps/cssdir +```` + + +### How to get vim to work with a sass file include + +```` +let g:syntastic_sass_sass_args=" + -I /Full/share/media/projectwide_sass_files" +```` + +you can also add multiple directories to the -I directive. Separate them with a space + +[fixing syntastic check args](http://stackoverflow.com/questions/29041876/fixing-syntasticcheck-bootstrap-error-vim-syntastic-plugin) + +[syntastic manual](https://github.com/vim-syntastic/syntastic/blob/master/doc/syntastic.txt) \ No newline at end of file diff --git a/share/readmes/set_the_key_file_on_local.md b/share/readmes/set_the_key_file_on_local.md new file mode 100644 index 0000000..2af0f1a --- /dev/null +++ b/share/readmes/set_the_key_file_on_local.md @@ -0,0 +1,15 @@ +`Host **my-remote-server**` *a symbolic name of your choice* + + +`Hostname **server-IP-or-DNS**` *the real name* + +`User **username**` *the username you use for login* + +`IdentityFile ~/.ssh/a_suitable_ssh_key_if_any` *for authentication purposes* + +`ControlMaster auto` + +`ControlPath ~/.ssh/%C` +*or* `~/.ssh/%h-%p-%r` *for older versions* + +`ControlPersist 5m` *or* `yes` *for never expiring persistent connection* \ No newline at end of file diff --git a/share/readmes/setup_foundation.md b/share/readmes/setup_foundation.md new file mode 100644 index 0000000..c0903dd --- /dev/null +++ b/share/readmes/setup_foundation.md @@ -0,0 +1,2 @@ +node.js +https://lincolnloop.com/blog/installing-nodejs-and-npm-python-virtualenv/ diff --git a/share/readmes/setup_gandi.md b/share/readmes/setup_gandi.md new file mode 100644 index 0000000..cab0ded --- /dev/null +++ b/share/readmes/setup_gandi.md @@ -0,0 +1,54 @@ +* set up using docker + +## setup the /var/www directory + + cd /var + sudo mkdir www + sudo chgrp www-data www -R + sudo chmod g+w www -R + +## install python packages + + sudo apt-get install python-dev + sudo apt-get install libjpeg-dev + +## install supervisor +sudo apt-get install supervisor + +make sure www-data is a group for *user* + +modify /etc/supervisor/supervisord.conf + +add the following: + +[unix_http_server] +file=/var/run//supervisor.sock ; (the path to the socket file) +chmod=0770 ; sockef file mode (default 0700) +chown=nobody:www-data + +[supervisorctl] +serverurl=unix:///var/run//supervisor.sock ; use a unix:// URL for a unix socket +chmod=0770 +chown=nobody:www-data + +#### run the following commands: + + sudo service supervisor stop + sudo service supervisor start + +## install postgres + + sudo apt-get install postgresql postgresql-contrib + sudo apt-get install postgresql-server-dev-X.Y + sudo apt-get install postgresql-server-dev-9.1 + +## install pip and virtualenv + +http://roundhere.net/journal/virtualenv-ubuntu-12-10/ + + sudo apt-get install python-pip + sudo pip install virtualenv + sudo pip install virtualenvwrapper + +1. setup scripts/meta/configuration/branch.yml +1. setup scripts/meta/virtualenv/branch.txt diff --git a/share/readmes/social_auth.md b/share/readmes/social_auth.md new file mode 100644 index 0000000..defab85 --- /dev/null +++ b/share/readmes/social_auth.md @@ -0,0 +1,96 @@ +# Social Auth notes + +## basic python_social_auth + +### How to Add Social Login to Django +[How to Add Social Login to Django](https://simpleisbetterthancomplex.com/tutorial/2016/10/24/how-to-add-social-login-to-django.html) + +#### pre test notes +1. disable 'test_social.middleware.ForwardHQMiddleware' +2. reset LOGIN_REDIRECT_URL = '/tsoc' or to wherever you want it to land +3. set SOCIAL_AUTH_URL_NAMESPACE = 'social' +4. DON'T use localhost if you plan on using twitter, twitter doesn't like it + +#### error in login +[stackoverflow desc](https://stackoverflow.com/questions/46975657/attributeerror-module-django-contrib-auth-views-has-no-attribute-login) + +change: +`path('login/', views.login, name='login')` +`path('login/', views.LoginView.as_view(template_name="registration/login.django"), name='login')` + +#### when making callback urls +- you can use localhost +- you can also specify a port on localhost, e.g. http://localhost:8026 +- you can also use minyanfinder.stg or any .stg + +- make sure to specify the "u" letter in oauth +- make sure to add the final forward slash "/" at the end of the callback url + +`minyanfinder.stg/oauth/complete/twitter/` + + + +## global variables +global variables should be in settings.py + +local info like the specific client id/secret key, etc, should be in the local setting sfiles + +test_social should only be activated in the local setting files + + +### twitter notes +1. you want to either use http or https, be specific +2. twitter does not use localhost and forwardhq is buggy +3. twitter DOES register 127.0.0.1:8026 as a callback + + +### facebook notes + +1. can use localhost +2. minaynfinder.stg is not working, need a certificate of some kind +3. forwardhq also not working + +#### using a domain + +##### create registered users + +Go to Roles->Test Users + +##### create the ssl +1. set a registered domain name to point at the ip address (ie ronnyabraham.com) +2. create a [https://www.digitalocean.com/community/tutorials/openssl-essentials-working-with-ssl-certificates-private-keys-and-csrs#generating-ssl-certificates](crt certificate) + +3. `Settings->Basic-> App Domains` add `ronnyabraham.com` +4. `Settings->Basic->Website/Site URL` add `https://ronnyabraham.com` +5. in Products->FacebookLogin->Settings add the following to "VAlid OAuth Redirect URIs" + +- https://ronnyabraham.com +- https://ronnyabraham.com/oauth/complete/facebook/ + +6. use letsencrypt to create ssl keys + + +### setting up facebook + +1. if used for testing make sure you set the app FOR TESTING you have to do this in the create app stage + +2. [select create test app from the app you like](https://imgur.com/RzK3pS3) + +3. go to settings->basic get the app-id and app-secret + +4. go to Settings-Basic-App Domains and add your FQDN (ie. mycrustyass.com) + +5. go to Settings-Basic-Website (it's near the bottom, add website if it isn't there), add the site URL with it's prefix ie http or https. + +Step 5 is VERY IMPORTANT b/c facebook doesn't recognize http prefix. +You must have SSL set up. But this is NOT the caes with localhost! + +6. in Settings-Products add Facebook Login then set Web OAuth Login to true +7. Settings-Products-Facebook Login add Valid OAuth redirect calls. + +Important! You must find out what the specific redirect call looks like. Once again, facebook doesn't require this for localhost, but for a named host it does + +e.g. https://mycrustyass.com/oauth/complete/facebook/ + +8. test this URL in the Settings-Products-FAcebook Login-Redirect URL Validator + diff --git a/share/readmes/sphinx.md b/share/readmes/sphinx.md new file mode 100644 index 0000000..7df0d64 --- /dev/null +++ b/share/readmes/sphinx.md @@ -0,0 +1,51 @@ +## to set up a project for documentation + +assuming we are using someproject: + + sphinx-apidoc -o /PATH-TO/someproject/docs/source/ /PATH-TO/someproject/ + + sphinx-build -b html /PATH-TO/someproject/docs/source /PATH-TO/someproject/docs/build/html + + cd /PATH-TO/someproject/docs + make html + +/PATH-TO/someproject - contains all the source files that we are looking at +/PATH-TO/someproject/docs - wherever the sphinx doc files, build, conf, etc are located +/PATH-TO/someproject/docs/source - contains the SPHINX configuration info for how to read the source + + +### when setting up sphinx for use with a django app + +if you get an error that looks like: + sphinx raise AppRegistryNotReady("Apps aren't loaded yet.") django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet. + +from https://stackoverflow.com/questions/34461088/sphinx-apidoc-on-django-build-html-failure-on-django-core-exceptions-appregistr + + import django + sys.path.insert(0, os.path.abspath('..')) + os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings' + django.setup() + +what I did in the drfcryce project for apps.todos: + + import os + import sys + import django + sys.path.insert(0, os.path.abspath('../../../')) + sys.path.insert(0, os.path.abspath('../../../../')) + + os.environ['DJANGO_SETTINGS_MODULE'] = 'drfcryce._settings.development' + django.setup() + +the first two sys.path fixes are to add the apps/todos to do the python path, and +to add the drfcryce settings directory to the python path + + +### to set up vim + let g:syntastic_rst_checkers=['sphinx'] + let g:syntastic_rst_sphinx_source_dir="/path/to/docs/source" + let g:syntastic_rst_sphinx_config_dir="/path/to/docs/source" + +the first path must lead to where ever index.rst is located +the second path must lead to where ever conf.py is located + diff --git a/share/readmes/translations.md b/share/readmes/translations.md new file mode 100644 index 0000000..c0894d8 --- /dev/null +++ b/share/readmes/translations.md @@ -0,0 +1,32 @@ +# how to do django translation + +[https://docs.djangoproject.com/es/1.9/topics/i18n/translation/]() + + +#### translation for templates + +[https://docs.djangoproject.com/es/1.9/topics/i18n/translation/#translator-comments-in-templates]() + +#### language switching + +[https://docs.djangoproject.com/es/1.9/topics/i18n/translation/#switching-language-in-templates]() + +#### how to create language files + +[https://docs.djangoproject.com/es/1.9/topics/i18n/translation/#localization-how-to-create-language-files]() + + +you have to set the -e extension to specify files you want to use. e.g. + +`django-admin makemessages -e django` + +`fab django.admin:"makemessages -l en -e django"` + +after creating the .po files you have to compile them for use + +`django-admin compilemessages` + +`fab django.admin:"compilemessages"` + +### set langauge redirect +[https://docs.djangoproject.com/es/1.9/topics/i18n/translation/#the-set-language-redirect-view]() \ No newline at end of file diff --git a/share/readmes/update_images.md b/share/readmes/update_images.md new file mode 100644 index 0000000..ddd5db9 --- /dev/null +++ b/share/readmes/update_images.md @@ -0,0 +1,20 @@ +in order to update the images + +1. make fixtures - fab django.create_fixtures:appname +2. copy fixtures - cp extras/backups/fixtures/appname/appname.json + code/app/appname/fixtures/appname.json +3. deploy - fab deploy.sync +4. copy images - cp extras/path/to/images/* /var/www/project.branch/public/media/dynamic + +5. check pip - make sure virtualenv txt is updated to development +6. syncdb - fab django.manage:syncdb + +5. ?flush - fab django.manage:flush +6. ?superuser - fab django.manage:createsuperuser +7. load fixture - fab django.manage:"loaddata fixture appname" + +if first time: +-? fab django.manage:"makemigrations thumbnail" +-? fab django.manage:migrate + +8. ?clear thumbs - fab django.manage:"thumbnail clear" diff --git a/share/readmes/ycm.md b/share/readmes/ycm.md new file mode 100644 index 0000000..321f414 --- /dev/null +++ b/share/readmes/ycm.md @@ -0,0 +1,37 @@ +# YCM Setup with Python 3.11.9 + +## Overview + +Due to issues with getting YCM (YouCompleteMe) to work with Python 3.12, it's recommended to create all virtual environments using Python version 3.11.9. This guide will walk you through setting up YCM with Python 3.11.9. + +## Creating a Virtual Environment + +To create a virtual environment using Python 3.11.9, run the following command: + +```bash +mkvirtualenv -p $(pyenv which python3.11) environment_name +``` + +Replace environment_name with your desired virtual environment name. + +## Recompiling YCM +If you encounter issues with YCM, you may need to recompile it. Follow these steps: + +``` +cd ~/.vim/bundle/YouCompleteMe +git pull origin master +python3 install.py --all +``` + +This will pull the latest changes from the YCM repository and recompile it with the necessary support. + +## Setting Up YCM +To configure YCM for your project, create a .ycm_extra_conf.py file in the root directory of your project. The file should contain the following Python code: + +```python +def Settings(**kwargs): + return { + 'interpreter_path': "/Users/ronny/.virtualenvs/PROJECT_NAME/bin/python" + } +``` + diff --git a/usr/etc/django/files/gunicorn.jinja2 b/usr/etc/django/files/gunicorn.jinja2 new file mode 100644 index 0000000..66b7c53 --- /dev/null +++ b/usr/etc/django/files/gunicorn.jinja2 @@ -0,0 +1,21 @@ +# gunicorn script file + +bind = '{{host}}:{{port}}' + +raw_env = ["DJANGO_SETTINGS_MODULE={{settings_module}}"] + +worker_tmp_dir = "/tmp" + +# +# uncomment only if supervisor does not set these! +# see https://stackoverflow.com/questions/53570850/djangogunicorn-operation-not-permitted + +# user = '{{user}}' +# group = '{{group}}' + +access_logfile = \ + '{{logging_access}}' + +error_logfile = \ + '{{logging_error}}' + diff --git a/usr/etc/django/files/gunicorn.unixsocket.jinja2 b/usr/etc/django/files/gunicorn.unixsocket.jinja2 new file mode 100644 index 0000000..5fe0f46 --- /dev/null +++ b/usr/etc/django/files/gunicorn.unixsocket.jinja2 @@ -0,0 +1,21 @@ +# gunicorn script file + +bind = 'unix:/tmp/gunicorn.{{ extended_name }}.sock' + +raw_env = ["DJANGO_SETTINGS_MODULE={{settings_module}}"] + +worker_tmp_dir = "/tmp" + +# +# uncomment only if supervisor does not already set these! +# see https://stackoverflow.com/questions/53570850/djangogunicorn-operation-not-permitted + +# user = '{{user}}' +# group = '{{group}}' + +access_logfile = \ + '{{logging_access}}' + +error_logfile = \ + '{{logging_error}}' + diff --git a/usr/etc/django/files/local.generated.jinja2 b/usr/etc/django/files/local.generated.jinja2 new file mode 100644 index 0000000..efd5275 --- /dev/null +++ b/usr/etc/django/files/local.generated.jinja2 @@ -0,0 +1,170 @@ +# this file contains settings that are automatically generated +# put custom commands/ imports in a separate file! + +LOCAL_SETTINGS = True # avoid recursive imports +BRANCH = '{{ project_branch }}' + +from {{ project_base }}.settings import * + +import logging + +LOCAL_LOGGING_PREFIX = "%s %%(message)s" % BRANCH +logging.basicConfig(format=LOCAL_LOGGING_PREFIX, level=logging.DEBUG) + +SITE_ID = 1 + +TEMPLATES[0]['DIRS'].append( + "{{paths_django_templates}}") + +# +# NOTE: a lot of the code in these local settings files are automated and you +# might be inclined to take them out and move them into the main settings.py +# file. That would be a mistake. These automatic files AT THE VERY LEAST have +# one variable, and that is WHICH BRANCH CONFIGURATION FILE ARE WE LOOKING AT. +# Once I set that file, THEN all the rest of the information can be automated. +# So all these automated info needs to be here. + +DATABASES = { + 'default': { + 'ENGINE': '{{server_database_backend}}', + 'NAME': '{{server_database_name}}', + 'USER': '{{server_database_user}}', + 'PASSWORD': '{{server_database_password}}', + 'HOST': '{{server_database_host}}', + 'PORT': '{{server_database_port}}', + } +} + + +# +# directory from which we serve static files +# +# NOTE: both STATIC and MEDIA roots are getting their values from the +# initialization files that are set up above. Also, MEDIA_ROOT is being set +# to something called "paths.server.media.dynamic" - the names are different, +# but it means the same thing. +# +# MEDIA_ROOT is the dynamic media information that the web server, user or +# admin # will be adding and taking out. It's why I call it "dynamic" + +STATIC_ROOT = '{{paths_server_media_static}}' +MEDIA_ROOT = '{{paths_server_media_dynamic}}' + +# directories from which we search for static files to place in STATIC_ROOT +# these static files are located within the project root as opposed to the +# server root location + +STATICFILES_DIRS = ( + os.path.join("{{paths_project_root}}", "share", "media"), +) + +# debug and debug toolbar settings +DEBUG = True +TEMPLATES[0]['OPTIONS']['debug'] = DEBUG +USE_DEBUG_TOOLBAR = DEBUG + +# allow template debug outputs on {{ project_branch }} environment +INTERNAL_IPS = ['127.0.0.1', '127.0.0.2', '127.0.0.3', ] + +ALLOWED_HOSTS = {{ project_django_allowedhosts }} + +# ----------------------------------------- +# Debug logging to the console + +LOGGING = { + 'version': 1, + 'disable_existing_loggers': False, + + 'formatters': { + 'verbose': { + 'format': "%(levelname)s %(asctime)s %(module)s %(process)d" + " %(thread)d %(message)s" + }, + 'simple': { + 'format': '%(levelname)s:%(module)s - %(message)s' + }, + + 'code': { + 'format': "%(module)s:%(funcName)s:%(lineno)d - %(message)s" + }, + + 'code.file': { + 'format': "%(levelname)s %(module)s:%(funcName)s - %(message)s\n" + }, + }, + + 'handlers': { + '{{ file_log_handler__name_project }}': { + 'class': 'logging.FileHandler', + + 'filename': + '{{file_log_handler__path_project}}', + + 'formatter': 'code.file' + }, + + '{{ file_debug_handler__name_project }}': { + 'class': 'logging.FileHandler', + + 'filename': + '{{file_debug_handler__path_project}}', + + 'formatter': 'code.file' + }, + + '{{ file_debug_handler__name_server }}': { + 'level': 'DEBUG', + 'class': 'logging.FileHandler', + + 'filename': + '{{file_debug_handler__path_server}}', + + 'formatter': 'code.file' + }, + + 'console': { + 'class': 'logging.StreamHandler', + 'formatter': 'simple' + }, + + 'console.code': { + 'class': 'logging.StreamHandler', + 'formatter': 'code', + }, + + 'null': { + 'class': 'logging.NullHandler', + } + }, + + 'root': { + # automatically set to level WARNING + + 'handlers': ['console.code', '{{ file_log_handler__name_project }}', '{{ file_debug_handler__name_server }}' ], + 'propagate': True, + }, + + 'loggers': { + 'django.info': { + 'handlers': + [ + 'console', + '{{ file_log_handler__name_project }}' + ], + 'level': 'INFO', + 'propagate': False, + }, + + 'django.debug': { + 'handlers': + [ + 'console.code', + '{{ file_debug_handler__name_project }}', + '{{ file_debug_handler__name_server }}', + ], + 'level': 'DEBUG', + 'propagate': True, + }, + } +} + diff --git a/usr/etc/django/files/local.jinja2 b/usr/etc/django/files/local.jinja2 new file mode 100644 index 0000000..2e3baec --- /dev/null +++ b/usr/etc/django/files/local.jinja2 @@ -0,0 +1,9 @@ +LOCAL_SETTINGS = True # avoid recursive imports + +from {{ project_base }}._settings.{{ project_branch }}_generated import * + +import logging + +LOCAL_LOGGING_PREFIX = "%s %%(message)s" % BRANCH +logging.basicConfig(format=LOCAL_LOGGING_PREFIX, level=logging.DEBUG) + diff --git a/usr/etc/django/files/settings.jinja2 b/usr/etc/django/files/settings.jinja2 new file mode 100644 index 0000000..7170f44 --- /dev/null +++ b/usr/etc/django/files/settings.jinja2 @@ -0,0 +1,145 @@ +""" +Django settings for {{ project_name }} project. + +Generated by 'django-admin startproject' using Django 4.2.1. + +For more information on this file, see +https://docs.djangoproject.com/en/4.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/4.2/ref/settings/ +""" + +import os +import sys + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +PROJECT_ROOT = os.path.abspath(os.path.join(BASE_DIR, os.pardir)) + +# +# add the directory that has the intialize.py module which contains the +# get_config function definition which will pull out all the configuraiton +# infomration for the settings file + +sys.path.insert(0, os.path.join( + PROJECT_ROOT, '{{ paths_tools_fabric }}')) + +# +# add an "apps" directory to this project, which is where all the apps +# ought to be in the first place. + +sys.path.insert(0, os.path.join(BASE_DIR, 'apps')) + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = '{{ secret_key }}' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', +] + +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 = '{{ project_base }}.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [os.path.join(PROJECT_ROOT, '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 = '{{ project_base }}.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/4.2/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + + +# Password validation +# https://docs.djangoproject.com/en/4.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/4.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/4.2/howto/static-files/ + +STATIC_URL = '/static/' +MEDIA_URL = '/media/' + +# Default primary key field type +# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' diff --git a/usr/etc/django/files/wsgi.jinja2 b/usr/etc/django/files/wsgi.jinja2 new file mode 100644 index 0000000..d8e4918 --- /dev/null +++ b/usr/etc/django/files/wsgi.jinja2 @@ -0,0 +1,17 @@ +""" +WSGI config for estate 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.8/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{ project_base }}._settings") + +application = get_wsgi_application() + diff --git a/usr/etc/django/files/wsgi.py b/usr/etc/django/files/wsgi.py new file mode 100644 index 0000000..b95c9ab --- /dev/null +++ b/usr/etc/django/files/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for testit 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.9/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testit.settings") + +application = get_wsgi_application() diff --git a/usr/etc/docker/files/database.jinja2 b/usr/etc/docker/files/database.jinja2 new file mode 100644 index 0000000..a9fcaec --- /dev/null +++ b/usr/etc/docker/files/database.jinja2 @@ -0,0 +1,25 @@ +version: "3.7" + +services: + {{ docker_service_name }}: + image: {{ docker_database_image }} + + ports: + - "{{ docker_database_port_external }}:{{ docker_database_port_internal }}" + + environment: + {{ docker_database_env_user }} : "{{ database_user }}" + {{ docker_database_env_pass }} : "{{ database_pass }}" + {{ docker_database_env_db }} : "{{ database_name }}" + + # this is bc compose will time out on remotes + COMPOSE_HTTP_TIMEOUT: 180 + + container_name: {{ docker_container_name }} + + {%- if docker_volume_data_external is defined %} + {% if docker_volume_data_internal is defined %} + volumes: + - {{ docker_volume_data_external }}:{{ docker_volume_data_internal }} + {% endif %} + {% endif %} diff --git a/usr/etc/nginx/files/default.conf.jinja2 b/usr/etc/nginx/files/default.conf.jinja2 new file mode 100644 index 0000000..62f309f --- /dev/null +++ b/usr/etc/nginx/files/default.conf.jinja2 @@ -0,0 +1,48 @@ +upstream app_server_{{extended_name}} { + + # for UNIX domain socket setups + server unix:/tmp/gunicorn.{{ extended_name }}.sock fail_timeout=0; + + # server {{django_host}}:{{django_port}} fail_timeout=0; +} + +server { + listen {{port}}; + server_name .{{server_name}} + + charset utf-8; + + client_max_body_size 75M; + + access_log {{access_log}}; + error_log {{error_log}}; + + location /media { + alias {{ server_media_dynamic }}; + } + + location /static/debug_toolbar { + alias {{virtualenv_sitepackages}}/debug_toolbar/static/debug_toolbar; + } + + location /static { + alias {{ server_media_static}}; + } + + location / { + proxy_pass_header Server; + proxy_set_header Host $http_host; + proxy_redirect off; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Scheme $scheme; + proxy_connect_timeout 10; + proxy_read_timeout 10; + # proxy_pass http://{{django_host}}:{{django_port}}/; + proxy_pass http://app_server_{{extended_name}}; + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root html; + } +} diff --git a/usr/etc/nginx/files/ssl_socket.jinja2 b/usr/etc/nginx/files/ssl_socket.jinja2 new file mode 100644 index 0000000..0322bbb --- /dev/null +++ b/usr/etc/nginx/files/ssl_socket.jinja2 @@ -0,0 +1,73 @@ + +upstream app_server_{{ extended_name }} { + # fail_timeout=0 means we always retry an upstream even if it failed + # to return a good HTTP response + + # for UNIX domain socket setups + server unix:/tmp/gunicorn.{{ extended_name }}.sock fail_timeout=0; + + # for a TCP configuration + # server 192.168.0.7:8000 fail_timeout=0; + # server {{django_host}}:{{django_port}} fail_timeout=0; +} + +server { + server_name .{{server_name}} + + charset utf-8; + + client_max_body_size 4G; + + access_log {{access_log}}; + error_log {{error_log}}; + + location /media { + alias {{ server_media_dynamic }}; + } + + location /static/debug_toolbar { + alias {{virtualenv_sitepackages}}/debug_toolbar/static/debug_toolbar; + } + + location /static { + alias {{ server_media_static}}; + } + + location / { + proxy_pass_header Server; + proxy_set_header Host $http_host; + proxy_redirect off; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Scheme $scheme; + proxy_connect_timeout 10; + proxy_read_timeout 10; + proxy_pass http://app_server_{{extended_name}}; + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root html; + } + + # this breaks down with multiple domains using ssl + # so I'm commenting it out + # listen [::]:443 ssl ipv6only=on; # managed by Certbot + + listen 443 ssl; # managed by Certbot + ssl_certificate /etc/letsencrypt/live/{{server_name}}/fullchain.pem; # managed by Certbot + ssl_certificate_key /etc/letsencrypt/live/{{server_name}}/privkey.pem; # managed by Certbot + include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot + ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot +} + +server { + if ($host = {{server_name}}) { + return 301 https://$host$request_uri; + } # managed by Certbot + + listen {{port}}; + listen [::]:{{port}}; + + server_name {{server_name}}; + return 404; # managed by Certbot +} diff --git a/usr/etc/nginx/files/unixsocket.jinja2 b/usr/etc/nginx/files/unixsocket.jinja2 new file mode 100644 index 0000000..18ed70a --- /dev/null +++ b/usr/etc/nginx/files/unixsocket.jinja2 @@ -0,0 +1,56 @@ +upstream app_server_{{ extended_name }} { + # fail_timeout=0 means we always retry an upstream even if it failed + # to return a good HTTP response + + # for UNIX domain socket setups + server unix:/tmp/gunicorn.{{ extended_name }}.sock fail_timeout=0; + + # for a TCP configuration + # server 192.168.0.7:8000 fail_timeout=0; + # server {{django_host}}:{{django_port}} fail_timeout=0; +} + +server { + listen {{port}}; + server_name .{{server_name}} + + charset utf-8; + + client_max_body_size 75M; + + access_log {{access_log}}; + error_log {{error_log}}; + + location /media { + alias {{ server_media_dynamic }}; + } + + location /static/debug_toolbar { + alias {{virtualenv_sitepackages}}/debug_toolbar/static/debug_toolbar; + } + + location /static { + alias {{ server_media_static}}; + } + + location / { + proxy_pass_header Server; + proxy_set_header Host $http_host; + proxy_redirect off; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Scheme $scheme; + proxy_connect_timeout 10; + proxy_read_timeout 10; + proxy_pass http://app_server_{{ extended_name }}; + + # uwsgi_pass django; + # include /Users/ronny/projects/django/replyall.dev/uwsgi_params; + # #root /usr/local/var/www/test; + # #index index.html index.htm; + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root html; + } +} diff --git a/usr/etc/postgres/files/db.drop_all.sql.jinja2 b/usr/etc/postgres/files/db.drop_all.sql.jinja2 new file mode 100644 index 0000000..53408cc --- /dev/null +++ b/usr/etc/postgres/files/db.drop_all.sql.jinja2 @@ -0,0 +1,2 @@ +DROP DATABASE {{db_name}}; +DROP USER {{db_user}}; diff --git a/usr/etc/postgres/files/db.drop_db.sql.jinja2 b/usr/etc/postgres/files/db.drop_db.sql.jinja2 new file mode 100644 index 0000000..e368f19 --- /dev/null +++ b/usr/etc/postgres/files/db.drop_db.sql.jinja2 @@ -0,0 +1 @@ +DROP DATABASE {{db_name}}; diff --git a/usr/etc/postgres/files/db.init.sql.jinja2 b/usr/etc/postgres/files/db.init.sql.jinja2 new file mode 100644 index 0000000..c8bc93a --- /dev/null +++ b/usr/etc/postgres/files/db.init.sql.jinja2 @@ -0,0 +1,5 @@ +CREATE USER {{db_user}} WITH PASSWORD '{{db_password}}'; +ALTER USER {{db_user}} CREATEDB; +CREATE DATABASE {{db_name}} WITH ENCODING='UTF8'; +ALTER DATABASE {{db_name}} OWNER TO {{db_user}}; +GRANT ALL PRIVILEGES ON DATABASE {{db_name}} TO {{db_user}}; diff --git a/usr/etc/postgres/files/db.re_init.sql.jinja2 b/usr/etc/postgres/files/db.re_init.sql.jinja2 new file mode 100644 index 0000000..e1b4261 --- /dev/null +++ b/usr/etc/postgres/files/db.re_init.sql.jinja2 @@ -0,0 +1,4 @@ +DROP DATABASE {{db_name}}; +CREATE DATABASE {{db_name}} WITH ENCODING='UTF8'; +ALTER DATABASE {{db_name}} OWNER TO {{db_user}}; +GRANT ALL PRIVILEGES ON DATABASE {{db_name}} TO {{db_user}}; diff --git a/usr/etc/supervisor/files/conf_old b/usr/etc/supervisor/files/conf_old new file mode 100644 index 0000000..1cea239 --- /dev/null +++ b/usr/etc/supervisor/files/conf_old @@ -0,0 +1,8 @@ +[program:{{project}}.{{branch}}] +user=root +command=bash {{rootpath}}/{{project}}.{{domain}}/scripts/gunicorn.sh +stdout_logfile={{rootpath}}/{{project}}.{{domain}}/logs/supervisor/out.log +stderr_logfile={{rootpath}}/{{project}}.{{domain}}/logs/supervisor/err.log + +stdout_logfile={{projectroot}}/logs/supervisor/out.log +stderr_logfile={{projectroot}}/logs/supervisor/err.log diff --git a/usr/etc/supervisor/files/supervisor.jinja2 b/usr/etc/supervisor/files/supervisor.jinja2 new file mode 100644 index 0000000..3864abc --- /dev/null +++ b/usr/etc/supervisor/files/supervisor.jinja2 @@ -0,0 +1,10 @@ +; this is the supervisor {{project_name}}.{{project_branch}} configuration file + +[program:{{project_name}}.{{project_branch}}] +command={{server_path_virtualenv_bin}}/gunicorn {{django_settings_folder}}.wsgi:application -c {{server_path_scripts}}/{{ gunicorn_conf_file }} +directory={{ server_path_code }} +user={{project_user}} +group={{project_group}} + +stdout_logfile={{supervisor_logs_out}} +stderr_logfile={{supervisor_logs_err}} diff --git a/usr/meta/project/development.yml b/usr/meta/project/development.yml new file mode 100644 index 0000000..10ef960 --- /dev/null +++ b/usr/meta/project/development.yml @@ -0,0 +1,91 @@ +coverage: + config: setup.cfg + paths: + html: htmlcov + root: share/coverage +database: + backend: django.db.backends.postgresql + host: docker + name: api-sandbox_dvp + port: 49041 + users: + admin: + name: admin + pass: admin + default: + name: ronny + pass: admin +django: + allowed_hosts: + - 127.0.0.1 + - PROJECT_NAME.BRANCH_EXT + host: 127.0.0.1 + paths: + settings: + base: core + port: 8076 +docker: + database: + env: + name: POSTGRES_DB + pass: POSTGRES_PASSWORD + user: POSTGRES_USER + extension: db + host: local + image: postgres + name: null + port: 5432 + machine: default + name: null +logging: + paths: + - null +maintenance: + nginx: + commands: + start: brew services start nginx + status: brew services list | grep nginx + stop: brew services stop nginx + editor: mvim + execute: local + supervisor: + commands: + reload: supervisorctl reload + start: supervisorctl start + status: supervisorctl status + stop: supervisorctl stop + update: supervisorctl update + execute: local +media: + paths: + dynamic: dynamic + root: public/media + static: static +nginx: + paths: + available: null + enabled: servers + root: /usr/local/etc/nginx + port: 80 + socket: false +overrides: +- null +project: + branch: development + extension: dvp + group: wheel + host: localhost + name: api-sandbox + paths: + home: api-sandbox.prj + root: /Users/ronny/projects/django + sudo: false + user: ronny +rootpath: /usr/local/var/www +supervisor: + paths: + conf: /usr/local/etc/supervisor/conf.d +virtualenv: + name: api-sandbox + python-version: 3.11 + workon: /Users/ronny/.virtualenvs diff --git a/usr/meta/project/layout.yml b/usr/meta/project/layout.yml new file mode 100644 index 0000000..7d69a50 --- /dev/null +++ b/usr/meta/project/layout.yml @@ -0,0 +1,137 @@ + + +imports: + settings.main: "settings" + +paths: + # paths and subdirectories relevent to django + django: + root: "code" + apps: "apps" + settings.local: "_settings" + + tools: + fabric: + home: "customfabric" + root: "usr/bin" + templates: + conf: "share/templates/conf" + meta: "share/templates/meta" + readmes: "share/templates/readmes" + + backups: + root: "backups" + database: "database" + media: "media" + fixtures: "django/fixtures" + + extras: + code: "extras/scripts/code" + fixtures: "var/fixtures" + ssh: "share/ssh" + + templates: + conf: "usr/etc" + + logging: + django: + project: "var/log" + server: "django" + +logging: + django: + handlers: + file_log: + name: 'file.log' + file: 'django.log' + + file_debug: + name: 'file.log.debug' + file: 'django.log.debug' + + +modules: + override: "override" + +virtualenv: + requirements: "usr/meta/virtualenv" + + # directories containing templates +templates: + nginx: + path: "nginx" + file: "default.conf.jinja2" + + conf: + source: "default.conf.jinja2" + output: "nginx.conf" + + ssl: + source: "ssl_socket.jinja2" + output: "nginx.conf" + + django: + path: "django" + + settings: + source: "settings.jinja2" + output: "settings.py" + + local: + source: "local.jinja2" + output: "local.py" + + local.generated: + source: "local.generated.jinja2" + output: "local_generated.py" + + wsgi: + source: "wsgi.jinja2" + output: "wsgi.py" + + + docker: + path: "docker" + + database: + source: "database.jinja2" + output: "database.yml" + + gunicorn: + path: "django" + + conf: + source: "gunicorn.jinja2" + output: "gunicorn.conf.py" + + supervisor: + path: "supervisor" + + conf: + source: "supervisor.jinja2" + output: "supervisor.conf" + + database: + path: "postgres" + + init: + source: "db.init.sql.jinja2" + output: "db.init.sql" + + re_init: + source: "db.re_init.sql.jinja2" + output: "db.re_init.sql" + + drop_all: + source: "db.drop_all.sql.jinja2" + output: "db.drop_all.sql" + + drop_db: + source: "db.drop_db.sql.jinja2" + output: "db.drop_db.sql" + + overrides: + path: "overrides" + +database: + default_admin: 'postgres' diff --git a/usr/meta/virtualenv/bootstrap.txt b/usr/meta/virtualenv/bootstrap.txt new file mode 100644 index 0000000..8aff9ff --- /dev/null +++ b/usr/meta/virtualenv/bootstrap.txt @@ -0,0 +1,6 @@ +Django +PyYAML +psycopg2 +pycryptodome +gunicorn +Jinja2 diff --git a/usr/meta/virtualenv/development.txt b/usr/meta/virtualenv/development.txt new file mode 100644 index 0000000..8aff9ff --- /dev/null +++ b/usr/meta/virtualenv/development.txt @@ -0,0 +1,6 @@ +Django +PyYAML +psycopg2 +pycryptodome +gunicorn +Jinja2 diff --git a/var/log/django.log b/var/log/django.log new file mode 100644 index 0000000..f4365b1 --- /dev/null +++ b/var/log/django.log @@ -0,0 +1,6 @@ +INFO autoreload:run_with_reloader - Watching for file changes with StatReloader + +WARNING log:log_response - Not Found: /favicon.ico + +WARNING log:log_response - Not Found: /favicon.ico + diff --git a/var/log/django.log.debug b/var/log/django.log.debug new file mode 100644 index 0000000..e69de29