Skip to content

Commit

Permalink
Merge pull request #58 from jdeanwallace/django-ses
Browse files Browse the repository at this point in the history
Add django-ses and stuff.
  • Loading branch information
jdeanwallace authored Mar 12, 2024
2 parents 4548263 + 1cd3570 commit 2718880
Show file tree
Hide file tree
Showing 13 changed files with 182 additions and 58 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ venv
data/**/*
!data/**/.gitignore
fly.toml
.env*
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ __pycache__/
*.log
.DS_Store
node_modules/
.env*
35 changes: 33 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,44 @@
```bash
python -m venv venv && \
. venv/bin/activate && \
pip install pip-tools --upgrade && \
pip install pip pip-tools --upgrade && \
pip-sync requirements/dev.txt && \
npm install && \
python manage.py makemigrations && \
python manage.py migrate && \
python manage.py createsuperuser
```

## Run development server

```bash
npm run dev
```

## Deploy

### Launch fly.io app

```bash
fly launch --ha=false --volume-initial-size=1
```

python manage.py runserver
### Set fly.io secrets

```bash
cat .env.prod | xargs fly secrets set
```

### Build bundles

```bash
npm run build
```

### Deploy changes when needed

```bash
fly deploy
```

<!-- End. -->
67 changes: 51 additions & 16 deletions apps/site/templates/site/base.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,51 @@
<!DOCTYPE html>
<html lang="en" class="scroll-smooth">
{% block html %}
<head>
{% block head %}
<title>{% block title %}{% endblock title %}</title>
{% block meta %}
{% endblock meta %}
{% endblock head %}
</head>
<body>
{% block body %}
{% endblock body %}
</body>
{% endblock html %}
</html>
{% extends 'site/layouts/stacked.html' %}
{% load static %}
{% block title %}Example{% endblock title %}
{% block meta %}
{% include 'site/partials/meta.html' %}
{% endblock meta %}
{% block nav %}
<div class="flex flex-col h-full">
<div class="px-4 my-2 flex gap-2 items-center">
<label class="cursor-pointer p-2 hover:bg-slate-200 rounded-md" for="nav-toggle">
<svg class="w-8 h-8" fill="none" stroke="currentColor" stroke-width="1.5" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
<path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12"></path>
</svg>
</label>
<a class="flex items-center gap-1 p-2 rounded-md" href="{% url 'site:home' %}">
<img class="w-8 h-8" src="{% static 'site/img/logo.svg' %}" alt="logo"/>
<span class="text-2xl font-semibold">Example</span>
</a>
</div>
<ul class="px-4 flex flex-col">
<li><a class="block p-2 hover:bg-slate-200 rounded-md" href="#how-it-works" onclick="document.getElementById('nav-toggle').click();">How it works</a></li>
<li><a class="block p-2 hover:bg-slate-200 rounded-md" href="#pricing" onclick="document.getElementById('nav-toggle').click();">Pricing</a></li>
<li><a class="block p-2 hover:bg-slate-200 rounded-md" href="#questions" onclick="document.getElementById('nav-toggle').click();">Questions</a></li>
</ul>
</div>
{% endblock nav %}
{% block header %}
<div class="max-w-7xl mx-auto px-4 my-2 flex gap-2 items-center">
<label class="md:hidden cursor-pointer p-2 hover:bg-slate-200 rounded-md" for="nav-toggle">
<svg class="w-8 h-8" fill="none" stroke="currentColor" stroke-width="1.5" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
<path stroke-linecap="round" stroke-linejoin="round" d="M3.75 6.75h16.5M3.75 12h16.5m-16.5 5.25h16.5"></path>
</svg>
</label>
<a class="flex items-center gap-1 p-2 rounded-md" href="{% url 'site:home' %}">
<img class="w-8 h-8" src="{% static 'site/img/logo.svg' %}" alt="logo"/>
<span class="text-2xl font-semibold">Example</span>
</a>
<ul class="max-md:hidden flex gap-4 items-center">
<li><a class="hover:underline" href="#how-it-works">How it works</a></li>
<li><a class="hover:underline" href="#pricing">Pricing</a></li>
<li><a class="hover:underline" href="#questions">Questions</a></li>
</ul>
</div>
{% endblock header %}
{% block footer %}
<div class="max-w-7xl mx-auto px-4 my-12">
<p class="text-center text-gray-500">
© {% now 'Y' %} Example. All rights reserved.
</p>
</div>
{% endblock footer %}
33 changes: 1 addition & 32 deletions apps/site/templates/site/home.html
Original file line number Diff line number Diff line change
@@ -1,33 +1,9 @@
{% extends 'site/layouts/stacked.html' %}
{% extends 'site/base.html' %}
{% load static %}
{% block title %}Example{% endblock title %}
{% block meta %}
{% include 'site/partials/meta.html' %}
{% endblock meta %}
{% block body %}
{% include 'site/components/faq.html' %}
{{ block.super }}
{% endblock body %}
{% block nav %}
<div class="flex flex-col h-full">
<div class="px-4 my-2 flex gap-2 items-center">
<label class="cursor-pointer p-2 hover:bg-slate-200 rounded-md" for="nav-toggle">
<svg class="w-8 h-8" fill="none" stroke="currentColor" stroke-width="1.5" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
<path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12"></path>
</svg>
</label>
<a class="flex items-center gap-1 p-2 rounded-md" href="{% url 'site:home' %}">
<img class="w-8 h-8" src="{% static 'site/img/logo.svg' %}" alt="logo"/>
<span class="text-2xl font-semibold">Example</span>
</a>
</div>
<ul class="px-4 flex flex-col">
<li><a class="block p-2 hover:bg-slate-200 rounded-md" href="#how-it-works" onclick="document.getElementById('nav-toggle').click();">How it works</a></li>
<li><a class="block p-2 hover:bg-slate-200 rounded-md" href="#pricing" onclick="document.getElementById('nav-toggle').click();">Pricing</a></li>
<li><a class="block p-2 hover:bg-slate-200 rounded-md" href="#questions" onclick="document.getElementById('nav-toggle').click();">Questions</a></li>
</ul>
</div>
{% endblock nav %}
{% block header %}
<div class="max-w-7xl mx-auto px-4 my-2 flex gap-2 items-center">
<label class="md:hidden cursor-pointer p-2 hover:bg-slate-200 rounded-md" for="nav-toggle">
Expand Down Expand Up @@ -227,10 +203,3 @@ <h2 class="text-4xl font-bold text-center">
</section>
</div>
{% endblock main %}
{% block footer %}
<div class="max-w-7xl mx-auto px-4 my-12">
<p class="text-center text-gray-500">
© {% now 'Y' %} Example. All rights reserved.
</p>
</div>
{% endblock footer %}
16 changes: 16 additions & 0 deletions apps/site/templates/site/layouts/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en" class="scroll-smooth">
{% block html %}
<head>
{% block head %}
<title>{% block title %}{% endblock title %}</title>
{% block meta %}
{% endblock meta %}
{% endblock head %}
</head>
<body>
{% block body %}
{% endblock body %}
</body>
{% endblock html %}
</html>
2 changes: 1 addition & 1 deletion apps/site/templates/site/layouts/stacked.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends 'site/base.html' %}
{% extends 'site/layouts/base.html' %}
{% load static %}
{% block head %}
{{ block.super }}
Expand Down
1 change: 1 addition & 0 deletions example/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
"level": "ERROR",
"filters": ["require_debug_false"],
"class": "django.utils.log.AdminEmailHandler",
"include_html": True,
},
"file": {
"level": "DEBUG",
Expand Down
12 changes: 12 additions & 0 deletions example/settings/prod.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,16 @@

ALLOWED_HOSTS = [
"example.fly.dev",
"example.com",
]

EMAIL_BACKEND = "django_ses.SESBackend"

AWS_SES_ACCESS_KEY_ID = os.environ.get("AWS_SES_ACCESS_KEY_ID", "")
AWS_SES_SECRET_ACCESS_KEY = os.environ.get("AWS_SES_SECRET_ACCESS_KEY", "")
AWS_SES_REGION_NAME = os.environ.get("AWS_SES_REGION_NAME", "")
AWS_SES_REGION_ENDPOINT = os.environ.get("AWS_SES_REGION_ENDPOINT", "")

SERVER_EMAIL = "Example Server <[email protected]>"
DEFAULT_FROM_EMAIL = "Admin from Example <[email protected]>"
ADMINS = [("Admin", "[email protected]")]
17 changes: 11 additions & 6 deletions fly.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
app = 'example'

[build]

[env]
DJANGO_SETTINGS_MODULE = 'example.settings.dev'
PYTHONDONTWRITEBYTECODE = '1'
PYTHONUNBUFFERED = '1'

[[mounts]]
source = 'example_data'
destination = '/app/data'
processes = ['app']

[http_service]
internal_port = 8000
force_https = true
Expand All @@ -13,9 +20,7 @@ app = 'example'
min_machines_running = 1
processes = ['app']

[[http_service.checks]]
interval = '30s'
timeout = '5s'
grace_period = '5s'
method = 'GET'
path = '/'
[[vm]]
memory = '1gb'
cpu_kind = 'shared'
cpus = 1
1 change: 1 addition & 0 deletions requirements/base.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ celery
ipython
gunicorn
whitenoise
django-ses
24 changes: 23 additions & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ asttokens==2.4.1
# via stack-data
billiard==4.2.0
# via celery
boto3==1.34.61
# via django-ses
botocore==1.34.61
# via
# boto3
# s3transfer
celery==5.3.6
# via -r requirements/base.ini
click==8.1.7
Expand All @@ -29,6 +35,10 @@ click-repl==0.3.0
decorator==5.1.1
# via ipython
django==5.0.1
# via
# -r requirements/base.ini
# django-ses
django-ses==3.5.2
# via -r requirements/base.ini
executing==2.0.1
# via stack-data
Expand All @@ -38,6 +48,10 @@ ipython==8.20.0
# via -r requirements/base.ini
jedi==0.19.1
# via ipython
jmespath==1.0.1
# via
# boto3
# botocore
kombu==5.3.5
# via celery
matplotlib-inline==0.1.6
Expand All @@ -59,7 +73,13 @@ pure-eval==0.2.2
pygments==2.17.2
# via ipython
python-dateutil==2.8.2
# via celery
# via
# botocore
# celery
pytz==2024.1
# via django-ses
s3transfer==0.10.0
# via boto3
six==1.16.0
# via
# asttokens
Expand All @@ -74,6 +94,8 @@ traitlets==5.14.1
# matplotlib-inline
tzdata==2023.4
# via celery
urllib3==2.0.7
# via botocore
vine==5.1.0
# via
# amqp
Expand Down
30 changes: 30 additions & 0 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ billiard==4.2.0
# celery
black==24.1.0
# via -r requirements/dev.ini
boto3==1.34.61
# via
# -r requirements/base.txt
# django-ses
botocore==1.34.61
# via
# -r requirements/base.txt
# boto3
# s3transfer
celery==5.3.6
# via -r requirements/base.txt
click==8.1.7
Expand Down Expand Up @@ -51,7 +60,10 @@ decorator==5.1.1
django==5.0.1
# via
# -r requirements/base.txt
# django-ses
# model-bakery
django-ses==3.5.2
# via -r requirements/base.txt
executing==2.0.1
# via
# -r requirements/base.txt
Expand All @@ -64,6 +76,11 @@ jedi==0.19.1
# via
# -r requirements/base.txt
# ipython
jmespath==1.0.1
# via
# -r requirements/base.txt
# boto3
# botocore
kombu==5.3.5
# via
# -r requirements/base.txt
Expand Down Expand Up @@ -113,7 +130,16 @@ pygments==2.17.2
python-dateutil==2.8.2
# via
# -r requirements/base.txt
# botocore
# celery
pytz==2024.1
# via
# -r requirements/base.txt
# django-ses
s3transfer==0.10.0
# via
# -r requirements/base.txt
# boto3
six==1.16.0
# via
# -r requirements/base.txt
Expand All @@ -136,6 +162,10 @@ tzdata==2023.4
# via
# -r requirements/base.txt
# celery
urllib3==2.0.7
# via
# -r requirements/base.txt
# botocore
vine==5.1.0
# via
# -r requirements/base.txt
Expand Down

0 comments on commit 2718880

Please sign in to comment.