Skip to content

Commit

Permalink
add localdev mode env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
sirodoht committed Jun 30, 2024
1 parent 4265715 commit e0eb144
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 6 deletions.
25 changes: 22 additions & 3 deletions .envrc.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# Exceptions and tracebacks on errors
# 1: show
# 0: don't show
export DEBUG=1

# Stop real emails and turn https off
# 1: stop and off
# 0: do not stop and on
export LOCALDEV_MODE=1

# Session cookies secret
export SECRET_KEY=some-secret-key
export DATABASE_URL=postgres://mataroa:db-password@db:5432/mataroa
export EMAIL_HOST_USER=smtp-user
export EMAIL_HOST_PASSWORD=smtp-password

# Database connection
export DATABASE_URL=postgres://mataroa:xxx@localhost:5432/mataroa

# SMTP credentials
export EMAIL_HOST_USER=
export EMAIL_HOST_PASSWORD=

# Stripe payments details
export STRIPE_API_KEY=
export STRIPE_PUBLIC_KEY=
export STRIPE_PRICE_ID=
7 changes: 7 additions & 0 deletions ansible/.envrc.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,15 @@ export DOMAIN=mataroa.blog
export EMAIL=admin@mataroa.blog

# Show exceptions and tracebacks on errors
# 1: show
# 0: don't show
export DEBUG=1

# Stop real emails and turn https off
# 1: stop and off
# 0: do not stop and on
export LOCALDEV_MODE=1

# Session cookies secret
export SECRET_KEY=some-secret-key

Expand Down
3 changes: 3 additions & 0 deletions ansible/mataroa.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ Group=www-data
WorkingDirectory=/var/www/mataroa
ExecStart=/var/www/mataroa/.venv/bin/gunicorn -b 127.0.0.1:5000 -w 4 mataroa.wsgi
ExecReload=/bin/kill -HUP $MAINPID
Environment="DOMAIN={{ domain }}"
Environment="EMAIL={{ email }}"
Environment="DEBUG={{ debug }}"
Environment="LOCALDEV_MODE={{ localdev_mode }}"
Environment="SECRET_KEY={{ secret_key }}"
Environment="DATABASE_URL={{ database_url }}"
Environment="EMAIL_HOST_USER={{ email_host_user }}"
Expand Down
1 change: 1 addition & 0 deletions ansible/vars.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ domain: "{{ lookup('env', 'DOMAIN') }}"
email: "{{ lookup('env', 'EMAIL') }}"

debug: "{{ lookup('env', 'DEBUG') }}"
localdev_mode: "{{ lookup('env', 'LOCALDEV_MODE') }}"

secret_key: "{{ lookup('env', 'SECRET_KEY') }}"

Expand Down
8 changes: 5 additions & 3 deletions mataroa/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True if os.environ.get("DEBUG") == "1" else False

LOCALDEV_MODE = True if os.environ.get("LOCALDEV_MODE") == "1" else False

ALLOWED_HOSTS = [
"127.0.0.1",
"localhost",
Expand All @@ -38,7 +40,7 @@
ADMINS = [("Theodore Keloglou", "zf@sirodoht.com")]

CANONICAL_HOST = os.environ.get("DOMAIN", "mataroa.blog")
if DEBUG:
if LOCALDEV_MODE:
CANONICAL_HOST = "mataroalocal.blog:8000"


Expand Down Expand Up @@ -174,7 +176,7 @@
# Email

EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
if DEBUG:
if LOCALDEV_MODE:
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
EMAIL_USE_TLS = True
EMAIL_HOST = "smtp.postmarkapp.com"
Expand All @@ -192,7 +194,7 @@

# Security middleware

if not DEBUG:
if not LOCALDEV_MODE:
SECURE_CONTENT_TYPE_NOSNIFF = True
X_FRAME_OPTIONS = "DENY"
SESSION_COOKIE_SECURE = True
Expand Down

0 comments on commit e0eb144

Please sign in to comment.