Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elastic Beanstalk Support #1867

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .ebextensions/01_packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
packages:
yum:
git: []
libpq-devel: []
libjpeg-turbo-devel: []
pango: []
13 changes: 13 additions & 0 deletions .ebextensions/02_python.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
option_settings:
"aws:elasticbeanstalk:application:environment":
DJANGO_SETTINGS_MODULE: "newamericadotorg.settings.eb_production"
"aws:elasticbeanstalk:container:python":
WSGIPath: newamericadotorg/wsgi.py
NumProcesses: 3
NumThreads: 20
# "aws:elasticbeanstalk:container:python:staticfiles":
# "/static/": "www/static/"
# container_commands:
# 01_migrate:
# command: "source /var/app/venv/*/bin/activate && python manage.py migrate --noinput"
# leader_only: true
26 changes: 26 additions & 0 deletions .ebignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,35 @@
*__pycache__/
*.pyc
*.DS_Store
*.rdb
fixture.json
/.vagrant

node_modules
bower_components
npm-debug.log
*.env

media/
static/

newamericadotorg/static/js/
newamericadotorg/templates/style.css
newamericadotorg/templates/styles.css
newamericadotorg/templates/style.css.map
newamericadotorg/templates/styles.css.map

venv
*.log

*.csv
*.crt
*.key
*.csr

home/management/api/article_images/
home/management/api/images/
home/management/api/documents/
report/utils/test.docx

.vscode
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,8 @@ report/utils/test.docx
links.py

.vscode

# Elastic Beanstalk Files
.elasticbeanstalk/*
!.elasticbeanstalk/*.cfg.yml
!.elasticbeanstalk/*.global.yml
3 changes: 0 additions & 3 deletions Procfile

This file was deleted.

186 changes: 186 additions & 0 deletions newamericadotorg/settings/eb_production.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
import os

from .base import * # noqa: F403

if 'RDS_DB_NAME' in os.environ:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': os.environ['RDS_DB_NAME'],
'USER': os.environ['RDS_USERNAME'],
'PASSWORD': os.environ['RDS_PASSWORD'],
'HOST': os.environ['RDS_HOSTNAME'],
'PORT': os.environ['RDS_PORT'],
}
}

# Timezone settings
TIME_ZONE = 'America/New_York'
USE_TZ = True


DEBUG = False

APPEND_SLASH = True

SECRET_KEY = os.getenv("SECRET_KEY")

# Will be changed to final host url
ALLOWED_HOSTS = [
'.newamerica.org',
# TODO: Eventually move to "dev" settings file. The below is not
# a production domain.
'newamerica-cms-dev.us-east-1.elasticbeanstalk.com',
'44.223.168.94',
# 'na-staging.herokuapp.com',
# 'na-develop.herokuapp.com',
]

SECURE_SSL_REDIRECT = True
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

SECURE_HSTS_INCLUDE_SUBDOMAINS = False
SECURE_HSTS_SECONDS = 63072000 # 2 years in seconds

AWS_QUERYSTRING_AUTH = False
AWS_IS_GZIPPED = True

# s3 bucket settings
AWS_ACCESS_KEY_ID = os.getenv('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = os.getenv('AWS_SECRET_ACCESS_KEY')

# media file settings
AWS_STORAGE_BUCKET_NAME = os.getenv('S3_BUCKET_NAME')
CLOUDFRONT_DOMAIN = os.getenv('CLOUDFRONT_DOMAIN')
CLOUDFRONT_ID = os.getenv('CLOUDFRONT_ID')
AWS_S3_CUSTOM_DOMAIN = CLOUDFRONT_DOMAIN
# AWS_S3_CUSTOM_DOMAIN = '%s.s3.amazonaws.com' % AWS_STORAGE_BUCKET_NAME

MEDIA_URL = "https://%s/" % AWS_S3_CUSTOM_DOMAIN
DEFAULT_FILE_STORAGE = 'custom_storages.MediaStorage'

AWS_S3_OBJECT_PARAMETERS = {
'Expires': 'Thu, 31 Dec 2099 20:00:00 GMT',
'CacheControl': 'max-age=94608000',
'ACL': 'public-read',
}
STATIC_BUCKET_NAME = os.getenv('STATIC_S3_BUCKET_NAME', None)

if STATIC_BUCKET_NAME is not None:
# Use S3 for static
STATICFILES_LOCATION = 'static'
STATICFILES_STORAGE = 'custom_storages.StaticStorage'
S3_STATIC_DOMAIN = '%s.s3.amazonaws.com' % STATIC_BUCKET_NAME
CLOUDFRONT_STATIC_URL = os.getenv('STATIC_URL')
#STATIC_URL = "https://%s/%s/" % (S3_STATIC_DOMAIN, STATICFILES_LOCATION)
STATIC_URL = "%s/%s/" % (CLOUDFRONT_STATIC_URL, STATICFILES_LOCATION)

# COMPRESS_URL = "https://%s/%s/" % (S3_STATIC_DOMAIN, STATICFILES_LOCATION)
# COMPRESS_STORAGE = STATICFILES_STORAGE

else:
# Serve static from the web server using Whitenoise
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
STATIC_URL = '/static/'

STATICFILES_LOCATION = ''
S3_STATIC_DOMAIN = 'notusingthis.s3.amazonaws.com'
CLOUDFRONT_STATIC_URL = ''


# Elastic Search setup
es_url = os.getenv('SEARCHBOX_URL', "http://localhost:9200/")

if es_url:
WAGTAILSEARCH_BACKENDS = {
'default': {
'BACKEND': 'search.backend',
'URLS': [es_url],
'INDEX': 'elasticsearch',
'TIMEOUT': 1500,
}
}

ANYMAIL = {
"MAILGUN_API_KEY": os.getenv('MAILGUN_API_KEY')
}

# Sentry

if 'SENTRY_DSN' in os.environ:
import sentry_sdk
from sentry_sdk.integrations.django import DjangoIntegration

sentry_sdk.init(
dsn=os.environ['SENTRY_DSN'],
integrations=[DjangoIntegration()],
environment=os.environ['SENTRY_ENVIRONMENT'],

# If you wish to associate users to errors (assuming you are using
# django.contrib.auth) you may enable sending PII data.
send_default_pii=True
)


# Email backend configuration
EMAIL_BACKEND = 'anymail.backends.mailgun.EmailBackend'
POSTMARK_SENDER = os.getenv("POSTMARK_SENDER")
DEFAULT_FROM_EMAIL = POSTMARK_SENDER
SERVER_EMAIL = POSTMARK_SENDER
WAGTAILADMIN_NOTIFICATION_USE_HTML = True
WAGTAILADMIN_NOTIFICATION_INCLUDE_SUPERUSERS = False
REDIS_URL = os.getenv(
'REDIS_TLS_URL',
os.getenv('REDIS_URL'),
)

# WAGTAILFRONTENDCACHE = {
# 'cloudfront': {
# 'BACKEND': 'wagtail.contrib.frontend_cache.backends.CloudfrontBackend',
# 'DISTRIBUTION_ID': 'E3IZZ8NUJMHTIF',
# },
# }

if REDIS_URL:
CACHES = {
'default': {
'BACKEND': 'django_redis.cache.RedisCache',
'LOCATION': REDIS_URL,
'OPTIONS': {
'CLIENT_CLASS': 'django_redis.client.DefaultClient',
'CONNECTION_POOL_KWARGS': {
'ssl_cert_reqs': None,
},
},
}
}
else:
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.dummy.DummyCache'
}
}

REST_FRAMEWORK = {
'DEFAULT_PAGINATION_CLASS': 'newamericadotorg.api.pagination.CustomPagination',
'DEFAULT_RENDERER_CLASSES': (
'rest_framework.renderers.JSONRenderer',
)
}

# PDF Generator
PDF_GENERATOR_URL = os.getenv('PDF_GENERATOR_URL')

try:
from .local import * # noqa: F403
except ImportError:
pass

# Wagtail settings

# Base URL to use when referring to full URLs within the Wagtail admin backend -
# e.g. in notification emails. Don't include '/admin' or a trailing slash
WAGTAILADMIN_BASE_URL = os.getenv('BASE_URL', None)

if WAGTAILADMIN_BASE_URL is None:
WAGTAILADMIN_BASE_URL = 'https://www.newamerica.org'
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dependencies = [
# Django related
'Django >= 3.2.6, < 4',
'Wagtail >= 5.2.2, < 5.3',
'Celery >= 4.4, < 5.0',
'Celery >= 5.4, < 6.0',
'dj-database-url >= 1.3.0, < 2',
'django-cors-headers >= 3.13.0, < 4',
'django-storages >= 1.13, < 2',
Expand Down
38 changes: 30 additions & 8 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
amqp==2.6.1
amqp==5.2.0
# via kombu
anyascii==0.3.2
# via wagtail
asgiref==3.6.0
# via django
beautifulsoup4==4.9.3
# via wagtail
billiard==3.6.4.0
billiard==4.2.0
# via celery
boto3==1.26.114
# via newamerica-cms (pyproject.toml)
Expand All @@ -20,7 +20,7 @@ cairocffi==1.5.0
# weasyprint
cairosvg==2.7.0
# via weasyprint
celery==4.4.7
celery==5.4.0
# via newamerica-cms (pyproject.toml)
certifi==2022.12.7
# via
Expand All @@ -32,6 +32,18 @@ cffi==1.15.1
# weasyprint
charset-normalizer==3.1.0
# via requests
click==8.1.7
# via
# celery
# click-didyoumean
# click-plugins
# click-repl
click-didyoumean==0.3.1
# via celery
click-plugins==1.1.1
# via celery
click-repl==0.3.0
# via celery
createsend==7.0.0
# via newamerica-cms (pyproject.toml)
cssselect2==0.7.0
Expand Down Expand Up @@ -117,7 +129,7 @@ jmespath==1.0.1
# via
# boto3
# botocore
kombu==4.6.11
kombu==5.3.7
# via celery
l18n==2021.3
# via wagtail
Expand All @@ -132,19 +144,22 @@ pillow==9.5.0
# wagtail
pillow-heif==0.14.0
# via willow
prompt-toolkit==3.0.43
# via click-repl
psycopg2==2.9.6
# via newamerica-cms (pyproject.toml)
pycparser==2.21
# via cffi
pyphen==0.14.0
# via weasyprint
python-dateutil==2.8.2
# via botocore
# via
# botocore
# celery
python-docx==0.8.11
# via newamerica-cms (pyproject.toml)
pytz==2023.3
# via
# celery
# django
# django-modelcluster
# djangorestframework
Expand Down Expand Up @@ -184,16 +199,19 @@ tinycss2==1.2.1
# weasyprint
typing-extensions==4.5.0
# via dj-database-url
tzdata==2024.1
# via celery
urllib3==1.26.15
# via
# botocore
# elasticsearch
# requests
# sentry-sdk
vine==1.3.0
vine==5.1.0
# via
# amqp
# celery
# kombu
wagtail==5.2.2
# via
# newamerica-cms (pyproject.toml)
Expand All @@ -205,6 +223,8 @@ wagtail-headless-preview==0.7.0
# via newamerica-cms (pyproject.toml)
wand==0.6.11
# via newamerica-cms (pyproject.toml)
wcwidth==0.2.13
# via prompt-toolkit
weasyprint==51
# via newamerica-cms (pyproject.toml)
webencodings==0.5.1
Expand All @@ -215,7 +235,9 @@ webencodings==0.5.1
whitenoise==6.4.0
# via newamerica-cms (pyproject.toml)
willow[heif]==1.6.2
# via wagtail
# via
# wagtail
# willow

# The following packages are considered to be unsafe in a requirements file:
setuptools==67.6.1
Expand Down
Loading
Loading