Skip to content

Commit c6aafdb

Browse files
committed
Update python and node
- Upgrade Python to 3.10 (used in prod) - Upgrade Node to v20 - Upgrade dependencies many of which required updates for updates for the new version of Node and Python. - Add instructions for testing the Docker container used in prod. I needed this to be sure things would work in prod as well as dev.
1 parent 1cb1e33 commit c6aafdb

File tree

19 files changed

+7589
-865
lines changed

19 files changed

+7589
-865
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ jobs:
1313
- uses: actions/checkout@v3
1414
- uses: actions/setup-python@v4
1515
with:
16-
python-version: "3.7"
16+
python-version: "3.10"
1717

1818
- name: Run CI
1919
run: |
20-
pip install "tox<4.0"
20+
pip install "tox>=4.0,<5.0"
2121
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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ This is the repository for the San Diego Python website at [sandiegopython.org](
1010

1111
### Prerequisites
1212

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

1616
### Getting started
1717

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

28+
2829
## Testing
2930

3031
The entire test suite can be run with tox:
@@ -33,10 +34,33 @@ The entire test suite can be run with tox:
3334
tox
3435
```
3536

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

3858
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.
59+
It is deployed automatically when code is merged to the `main` branch
60+
via GitHub Actions.
61+
62+
63+
To deploy manually, you will need to be a member of the San Diego Python team on Fly.
4064
Once you're a member of the team, you can deploy with:
4165

4266
```shell

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)