Skip to content

Commit fe554dc

Browse files
committed
maybe this works
1 parent a3ca362 commit fe554dc

6 files changed

Lines changed: 140 additions & 2 deletions

File tree

‎Dockerfile‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
FROM python:3.10-bookworm
2+
3+
ENV PYTHONUNBUFFERED=1
4+
ENV PYTHONDONTWRITEBYTECODE=1
5+
6+
# Do this _early_ so that we have the lowest chance of needing to "reseed" the clone
7+
# on every build.
8+
RUN git clone https://github.com/python/cpython.git /srv/data/repos/cpython
9+
10+
# By default, Docker has special steps to avoid keeping APT caches in the layers, which
11+
# is good, but in our case, we're going to mount a special cache volume (kept between
12+
# builds), so we WANT the cache to persist.
13+
RUN set -eux; \
14+
rm -f /etc/apt/apt.conf.d/docker-clean; \
15+
echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache;
16+
17+
# Install System level build requirements, this is done before
18+
# everything else because these are rarely ever going to change.
19+
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
20+
--mount=type=cache,target=/var/lib/apt,sharing=locked \
21+
set -x \
22+
&& apt-get update \
23+
&& apt-get install --no-install-recommends -y \
24+
build-essential git \
25+
&& apt-get clean \
26+
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
27+
28+
RUN mkdir /srv/src
29+
WORKDIR /srv/src
30+
COPY requirements.txt /srv/src/
31+
COPY deploy-requirements.txt /srv/src/
32+
RUN pip install -r deploy-requirements.txt
33+
COPY . /srv/src/
34+
RUN touch /srv/src/speed_python/local_settings.py
35+
RUN \
36+
DATABASE_URL=None \
37+
DJANGO_SECRET_KEY=None \
38+
DJANGO_SETTINGS_MODULE=speed_python.cabotage_settings \
39+
python manage.py collectstatic --noinput

‎Procfile‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
release: python manage.py migrate
2+
web: gunicorn -c gunicorn.conf.py speed_python.wsgi:application -w 4

‎gunicorn.conf.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
bind = "unix:/var/run/cabotage/cabotage.sock"
2+
backlog = 2048
3+
preload_app = True
4+
max_requests = 2048
5+
max_requests_jitter = 128
6+
7+
worker_connections = 1000
8+
timeout = 60
9+
keepalive = 2
10+
11+
errorlog = "-"
12+
loglevel = "info"
13+
accesslog = "-"
14+
15+
16+
def when_ready(server):
17+
open("/tmp/app-initialized", "w").close()

‎requirements.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
django<4
2+
django-environ==0.11.2
23
isodate==0.6.1
34
matplotlib<3.8

‎speed_python/cabotage_settings.py‎

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import environ
4+
5+
from speed_python.settings import *
6+
7+
env = environ.Env()
8+
9+
# Note: This is imported by the main settings file, so only changes to
10+
# what's there need to be included here.
11+
12+
DEBUG = TEMPLATE_DEBUG = False
13+
14+
# TODO: configure via "DATABASE_URL" env var
15+
DATABASES = {"default": env.db()}
16+
17+
ALLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS", "localhost").split(",")
18+
19+
SECRET_KEY = os.environ.get("DJANGO_SECRET_KEY")
20+
21+
22+
ADMINS = (
23+
(
24+
os.environ.get("CODESPEED_ADMIN_TEAM_NAME", "Codespeed"),
25+
os.environ.get("CODESPEED_ADMIN_TEAM_EMAIL", "codespeed@example.com"),
26+
),
27+
)
28+
29+
SERVER_EMAIL = os.environ.get("DJANGO_SERVER_EMAIL", "noreply@example.com")
30+
31+
DEFAULT_FROM_EMAIL = os.environ.get("DJANGO_DEFAULT_FROM_EMAIL", "noreply@example.com")
32+
33+
MANAGERS = ADMINS
34+
35+
COMPRESS_ENABLED = True
36+
37+
_DATA_ROOT = os.environ.get("DJANGO_DATA_ROOT", "/srv/data")
38+
MEDIA_ROOT = _DATA_ROOT + "/media"
39+
STATIC_ROOT = _DATA_ROOT + "/site_media/static"
40+
REPOSITORY_BASE_PATH = _DATA_ROOT + "/repos/"
41+
42+
LOGGING = {
43+
"version": 1,
44+
"disable_existing_loggers": False,
45+
"formatters": {
46+
"verbose": {
47+
"format": "{levelname} {asctime} {module} {process:d} {thread:d} {message}",
48+
"style": "{",
49+
},
50+
"simple": {
51+
"format": "{levelname} {message}",
52+
"style": "{",
53+
},
54+
},
55+
"filters": {},
56+
"handlers": {
57+
"console": {
58+
"level": "INFO",
59+
"filters": [],
60+
"class": "logging.StreamHandler",
61+
"formatter": "simple",
62+
},
63+
"mail_admins": {
64+
"level": "ERROR",
65+
"class": "django.utils.log.AdminEmailHandler",
66+
"filters": [],
67+
},
68+
},
69+
"loggers": {
70+
"django": {
71+
"handlers": ["console"],
72+
"propagate": True,
73+
},
74+
"myproject.custom": {
75+
"handlers": ["console", "mail_admins"],
76+
"level": "INFO",
77+
"filters": [],
78+
},
79+
},
80+
}

‎speed_python/settings.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
# XXX Set SECRET_KEY in local_settings.py
4242
#with open(os.path.join(BASEDIR, 'secret_key')) as f:
4343
# SECRET_KEY = f.read().strip()
44+
SECRET_KEY = os.environ.get("DJANGO_SECRET_KEY")
4445

4546
TEMPLATE_LOADERS = (
4647
'django.template.loaders.filesystem.Loader',
@@ -117,5 +118,3 @@ def process_exception(self, request, exception):
117118

118119
# Codespeed settings that can be overwritten here.
119120
from codespeed.settings import *
120-
121-
from .local_settings import *

0 commit comments

Comments
 (0)