Skip to content

Commit c46fe62

Browse files
committed
Merge branch 'main' into davidfischer/additional-youtube-sandboxing
2 parents 9fb432f + f233681 commit c46fe62

File tree

25 files changed

+7635
-893
lines changed

25 files changed

+7635
-893
lines changed

.env/local.sample

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# This is a sample of environment variables which are used only to run Docker locally.
2+
# These are never used in production.
3+
4+
# Use a strong secret in production
5+
SECRET_KEY="this-is-a-bad-secret"
6+
7+
# In production, we use postgres but for testing a deployment, using SQLite is fine
8+
DATABASE_URL="sqlite:///db.sqlite3"

.github/workflows/ci.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions
12
name: Continuous Integration Checks
23

3-
# All branches
4-
on: push
4+
# All PRs as well as pushes to main
5+
on:
6+
push:
7+
branches:
8+
- main
9+
pull_request:
510

611
jobs:
712
build:
@@ -13,9 +18,9 @@ jobs:
1318
- uses: actions/checkout@v3
1419
- uses: actions/setup-python@v4
1520
with:
16-
python-version: "3.7"
21+
python-version: "3.10"
1722

1823
- name: Run CI
1924
run: |
20-
pip install "tox<4.0"
25+
pip install "tox>=4.0,<5.0"
2126
tox

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ repos:
66
- id: end-of-file-fixer
77
- id: trailing-whitespace
88
- repo: https://github.com/ambv/black
9-
rev: 22.8.0
9+
rev: 24.4.2
1010
hooks:
1111
- id: black
1212
# Since the pre-commit runs on a file by file basis rather than a whole project,
1313
# The excludes in pyproject.toml are ignored
1414
exclude: migrations
15-
language_version: python3.7
15+
language_version: python3.10

Dockerfile

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@ LABEL maintainer="https://github.com/sandiegopython"
77
ENV PYTHONDONTWRITEBYTECODE 1
88
ENV PYTHONUNBUFFERED 1
99

10-
1110
RUN apt-get update
11+
RUN apt-get install -y --no-install-recommends curl
12+
13+
# Install Node v20
14+
# This should be run before apt-get install nodejs
15+
# https://github.com/nodesource/distributions
16+
RUN curl -sL https://deb.nodesource.com/setup_20.x | bash -
17+
1218
RUN apt-get install -y --no-install-recommends \
13-
nodejs npm \
19+
nodejs \
1420
make \
1521
build-essential \
1622
g++ \
@@ -22,12 +28,13 @@ WORKDIR /code
2228

2329
COPY . /code/
2430

25-
RUN set -ex && \
31+
# Cache dependencies when building which should result in faster docker builds
32+
RUN --mount=type=cache,target=/root/.cache/pip set -ex && \
2633
pip install --upgrade --no-cache-dir pip && \
27-
pip install --no-cache-dir -r /code/requirements.txt && \
28-
pip install --no-cache-dir -r /code/requirements/local.txt
34+
pip install -r /code/requirements.txt && \
35+
pip install -r /code/requirements/local.txt
2936

30-
# Build static assets
37+
# Build JS/static assets
3138
RUN npm install
3239
RUN npm run build
3340

README.md

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
This is the repository for the San Diego Python website at [sandiegopython.org](https://sandiegopython.org).
44

55
[![AppVeyor](https://ci.appveyor.com/api/projects/status/184l9lc8y7av2fah?svg=true)](https://ci.appveyor.com/project/davidfischer/pythonsd-django)
6-
[![Requirements Status](https://requires.io/github/sandiegopython/pythonsd-django/requirements.svg?branch=main)](https://requires.io/github/sandiegopython/pythonsd-django/requirements/?branch=main)
76

87

98
## Developing
109

1110
### Prerequisites
1211

13-
* Python 3.7+
14-
* Node (12.x recommended)
12+
* Python v3.10
13+
* Node v20
1514

1615
### Getting started
1716

@@ -25,6 +24,7 @@ pre-commit install # Setup code standard pre-commit hook
2524
./manage.py runserver # Starts a local development server at http://localhost:8000
2625
```
2726

27+
2828
## Testing
2929

3030
The entire test suite can be run with tox:
@@ -33,10 +33,33 @@ The entire test suite can be run with tox:
3333
tox
3434
```
3535

36+
To test the Dockerfile that is used for deployment,
37+
you can build the container and run it locally:
38+
39+
```shell
40+
# Setup your local environment variables used with Docker
41+
# This only needs to be run once
42+
cp .env/local.sample .env/local
43+
44+
# Build the docker image for sandiegopython.org
45+
docker buildx build -t sandiegopython.org .
46+
47+
# Start a development server on http://localhost:8000
48+
docker run --env-file=".env/local" --publish=8000:8000 sandiegopython.org
49+
50+
# You can start a shell to the container with the following:
51+
docker run --env-file=".env/local" -it sandiegopython.org /bin/bash
52+
```
53+
54+
3655
## Deploying
3756

3857
This site is deployed to [Fly.io](https://fly.io/).
39-
You will need to be a member of the San Diego Python team on Fly to deploy.
58+
It is deployed automatically when code is merged to the `main` branch
59+
via GitHub Actions.
60+
61+
62+
To deploy manually, you will need to be a member of the San Diego Python team on Fly.
4063
Once you're a member of the team, you can deploy with:
4164

4265
```shell

assets/dist/.gitkeep

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This file silences a dev-only Django warning
2+
that occurs when the staticfiles directory doesn't exist.

config/context_processors.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Custom context processors that inject certain settings values into all templates."""
2+
23
from django.conf import settings
34

45

config/settings/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
For the full list of settings and their values, see
88
https://docs.djangoproject.com/en/3.2/ref/settings/
99
"""
10+
1011
import json
1112
import os
1213

config/settings/prod.py

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
DEBUG = False
1818
SECRET_KEY = os.environ["SECRET_KEY"]
1919
ALLOWED_HOSTS = [
20+
"0.0.0.0",
2021
"127.0.0.1",
22+
"localhost",
2123
"pythonsd.org",
2224
"www.pythonsd.org",
2325
"pythonsd.com",
@@ -45,35 +47,37 @@
4547
# https://docs.djangoproject.com/en/3.2/ref/settings/#caches
4648
# http://niwinz.github.io/django-redis/
4749
# --------------------------------------------------------------------------
48-
CACHES = {
49-
"default": {
50-
"BACKEND": "django_redis.cache.RedisCache",
51-
"LOCATION": os.environ["REDIS_URL"],
52-
"OPTIONS": {
53-
"CLIENT_CLASS": "django_redis.client.DefaultClient",
54-
"IGNORE_EXCEPTIONS": True,
55-
},
50+
if "REDIS_URL" in os.environ:
51+
CACHES = {
52+
"default": {
53+
"BACKEND": "django_redis.cache.RedisCache",
54+
"LOCATION": os.environ["REDIS_URL"],
55+
"OPTIONS": {
56+
"CLIENT_CLASS": "django_redis.client.DefaultClient",
57+
"IGNORE_EXCEPTIONS": True,
58+
},
59+
}
5660
}
57-
}
5861

5962

6063
# Security
6164
# https://docs.djangoproject.com/en/3.2/topics/security/
6265
# https://devcenter.heroku.com/articles/http-routing#heroku-headers
6366
# --------------------------------------------------------------------------
64-
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
65-
SECURE_SSL_HOST = os.environ.get("SECURE_SSL_HOST")
66-
SECURE_SSL_REDIRECT = True
67-
SESSION_COOKIE_SECURE = True
68-
SESSION_COOKIE_HTTPONLY = True
69-
CSRF_COOKIE_SECURE = True
70-
CSRF_COOKIE_HTTPONLY = True
71-
SECURE_HSTS_SECONDS = 60 * 60 * 24 * 365
72-
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
73-
SECURE_HSTS_PRELOAD = True
74-
SECURE_CONTENT_TYPE_NOSNIFF = True
75-
SECURE_BROWSER_XSS_FILTER = True
76-
X_FRAME_OPTIONS = "DENY"
67+
if "SECURE_SSL_HOST" in os.environ:
68+
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
69+
SECURE_SSL_HOST = os.environ.get("SECURE_SSL_HOST")
70+
SECURE_SSL_REDIRECT = True
71+
SESSION_COOKIE_SECURE = True
72+
SESSION_COOKIE_HTTPONLY = True
73+
CSRF_COOKIE_SECURE = True
74+
CSRF_COOKIE_HTTPONLY = True
75+
SECURE_HSTS_SECONDS = 60 * 60 * 24 * 365
76+
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
77+
SECURE_HSTS_PRELOAD = True
78+
SECURE_CONTENT_TYPE_NOSNIFF = True
79+
SECURE_BROWSER_XSS_FILTER = True
80+
X_FRAME_OPTIONS = "DENY"
7781

7882
# If set, all requests to other domains redirect to this one
7983
# https://github.com/dabapps/django-enforce-host

config/settings/test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Settings used in testing."""
2+
23
import warnings
34

45
from .dev import * # noqa

0 commit comments

Comments
 (0)