Skip to content

Update python and node #143

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

Merged
merged 1 commit into from
May 18, 2024
Merged
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
8 changes: 8 additions & 0 deletions .env/local.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This is a sample of environment variables which are used only to run Docker locally.
# These are never used in production.

# Use a strong secret in production
SECRET_KEY="this-is-a-bad-secret"

# In production, we use postgres but for testing a deployment, using SQLite is fine
DATABASE_URL="sqlite:///db.sqlite3"
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.7"
python-version: "3.10"

- name: Run CI
run: |
pip install "tox<4.0"
pip install "tox>=4.0,<5.0"
tox
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/ambv/black
rev: 22.8.0
rev: 24.4.2
hooks:
- id: black
# Since the pre-commit runs on a file by file basis rather than a whole project,
# The excludes in pyproject.toml are ignored
exclude: migrations
language_version: python3.7
language_version: python3.10
19 changes: 13 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ LABEL maintainer="https://github.com/sandiegopython"
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1


RUN apt-get update
RUN apt-get install -y --no-install-recommends curl

# Install Node v20
# This should be run before apt-get install nodejs
# https://github.com/nodesource/distributions
RUN curl -sL https://deb.nodesource.com/setup_20.x | bash -

RUN apt-get install -y --no-install-recommends \
nodejs npm \
nodejs \
make \
build-essential \
g++ \
Expand All @@ -22,12 +28,13 @@ WORKDIR /code

COPY . /code/

RUN set -ex && \
# Cache dependencies when building which should result in faster docker builds
RUN --mount=type=cache,target=/root/.cache/pip set -ex && \
pip install --upgrade --no-cache-dir pip && \
pip install --no-cache-dir -r /code/requirements.txt && \
pip install --no-cache-dir -r /code/requirements/local.txt
pip install -r /code/requirements.txt && \
pip install -r /code/requirements/local.txt

# Build static assets
# Build JS/static assets
RUN npm install
RUN npm run build

Expand Down
30 changes: 27 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ This is the repository for the San Diego Python website at [sandiegopython.org](

### Prerequisites

* Python 3.7+
* Node (12.x recommended)
* Python v3.10
* Node v20

### Getting started

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


## Testing

The entire test suite can be run with tox:
Expand All @@ -33,10 +34,33 @@ The entire test suite can be run with tox:
tox
```

To test the Dockerfile that is used for deployment,
you can build the container and run it locally:

```shell
# Setup your local environment variables used with Docker
# This only needs to be run once
cp .env/local.sample .env/local

# Build the docker image for sandiegopython.org
docker buildx build -t sandiegopython.org .

# Start a development server on http://localhost:8000
docker run --env-file=".env/local" --publish=8000:8000 sandiegopython.org

# You can start a shell to the container with the following:
docker run --env-file=".env/local" -it sandiegopython.org /bin/bash
```


## Deploying

This site is deployed to [Fly.io](https://fly.io/).
You will need to be a member of the San Diego Python team on Fly to deploy.
It is deployed automatically when code is merged to the `main` branch
via GitHub Actions.


To deploy manually, you will need to be a member of the San Diego Python team on Fly.
Once you're a member of the team, you can deploy with:

```shell
Expand Down
1 change: 1 addition & 0 deletions config/context_processors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Custom context processors that inject certain settings values into all templates."""

from django.conf import settings


Expand Down
1 change: 1 addition & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.2/ref/settings/
"""

import json
import os

Expand Down
48 changes: 26 additions & 22 deletions config/settings/prod.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
DEBUG = False
SECRET_KEY = os.environ["SECRET_KEY"]
ALLOWED_HOSTS = [
"0.0.0.0",
"127.0.0.1",
"localhost",
"pythonsd.org",
"www.pythonsd.org",
"pythonsd.com",
Expand Down Expand Up @@ -45,35 +47,37 @@
# https://docs.djangoproject.com/en/3.2/ref/settings/#caches
# http://niwinz.github.io/django-redis/
# --------------------------------------------------------------------------
CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": os.environ["REDIS_URL"],
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
"IGNORE_EXCEPTIONS": True,
},
if "REDIS_URL" in os.environ:
CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": os.environ["REDIS_URL"],
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
"IGNORE_EXCEPTIONS": True,
},
}
}
}


# Security
# https://docs.djangoproject.com/en/3.2/topics/security/
# https://devcenter.heroku.com/articles/http-routing#heroku-headers
# --------------------------------------------------------------------------
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
SECURE_SSL_HOST = os.environ.get("SECURE_SSL_HOST")
SECURE_SSL_REDIRECT = True
SESSION_COOKIE_SECURE = True
SESSION_COOKIE_HTTPONLY = True
CSRF_COOKIE_SECURE = True
CSRF_COOKIE_HTTPONLY = True
SECURE_HSTS_SECONDS = 60 * 60 * 24 * 365
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
SECURE_HSTS_PRELOAD = True
SECURE_CONTENT_TYPE_NOSNIFF = True
SECURE_BROWSER_XSS_FILTER = True
X_FRAME_OPTIONS = "DENY"
if "SECURE_SSL_HOST" in os.environ:
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
SECURE_SSL_HOST = os.environ.get("SECURE_SSL_HOST")
SECURE_SSL_REDIRECT = True
SESSION_COOKIE_SECURE = True
SESSION_COOKIE_HTTPONLY = True
CSRF_COOKIE_SECURE = True
CSRF_COOKIE_HTTPONLY = True
SECURE_HSTS_SECONDS = 60 * 60 * 24 * 365
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
SECURE_HSTS_PRELOAD = True
SECURE_CONTENT_TYPE_NOSNIFF = True
SECURE_BROWSER_XSS_FILTER = True
X_FRAME_OPTIONS = "DENY"

# If set, all requests to other domains redirect to this one
# https://github.com/dabapps/django-enforce-host
Expand Down
1 change: 1 addition & 0 deletions config/settings/test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Settings used in testing."""

import warnings

from .dev import * # noqa
Expand Down
Loading
Loading