Skip to content

Commit 1be8f13

Browse files
Added production docker image and preview domain support (#1627)
1 parent 5c038b8 commit 1be8f13

File tree

11 files changed

+145
-43
lines changed

11 files changed

+145
-43
lines changed

.github/workflows/docker-publish.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Create and publish a Docker image
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
7+
env:
8+
REGISTRY: ghcr.io
9+
IMAGE_NAME: ${{ github.repository }}
10+
11+
jobs:
12+
build-and-push-image:
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: read
16+
packages: write
17+
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v4
21+
22+
- name: Log in to the Container registry
23+
uses: docker/login-action@v3
24+
with:
25+
registry: ${{ env.REGISTRY }}
26+
username: ${{ github.actor }}
27+
password: ${{ secrets.GITHUB_TOKEN }}
28+
29+
- name: Extract metadata (tags, labels) for Docker
30+
id: meta
31+
uses: docker/metadata-action@v5
32+
with:
33+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
34+
flavor: |
35+
latest=true
36+
tags: |
37+
type=ref,event=branch
38+
type=sha
39+
40+
- name: Build and push Docker image
41+
uses: docker/build-push-action@v6
42+
with:
43+
context: .
44+
push: true
45+
tags: ${{ steps.meta.outputs.tags }}
46+
labels: ${{ steps.meta.outputs.labels }}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Docker test build
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
permissions:
14+
contents: read
15+
16+
jobs:
17+
build-image:
18+
runs-on: ubuntu-latest
19+
20+
strategy:
21+
matrix:
22+
req_file:
23+
- prod.txt
24+
- tests.txt
25+
26+
# steps taken (and trimmed) from docker-publish.yml
27+
steps:
28+
- name: Checkout repository
29+
uses: actions/checkout@v4
30+
31+
- name: Test docker image build (local development)
32+
uses: docker/build-push-action@v6
33+
with:
34+
context: .
35+
push: false
36+
build-args: |
37+
REQ_FILE=requirements/${{ matrix.req_file }}

.github/workflows/tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99

1010
jobs:
1111
tests:
12-
runs-on: ubuntu-20.04
12+
runs-on: ubuntu-24.04
1313
strategy:
1414
fail-fast: false
1515

@@ -29,9 +29,9 @@ jobs:
2929
steps:
3030
- uses: actions/checkout@v2
3131
- name: Set up Python
32-
uses: actions/setup-python@v2
32+
uses: actions/setup-python@v5
3333
with:
34-
python-version: 3.8
34+
python-version: "3.8"
3535
- name: Install dependencies
3636
run: |
3737
python -m pip install --upgrade pip setuptools coveralls "tox<4"

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ locale/*/LC_MESSAGES/django.mo
1010
*/locale/*/LC_MESSAGES/django.mo
1111
.sass-cache/
1212
.coverage
13+
.direnv
14+
.envrc
1315
.tox
1416
djangoproject/cache
1517
djangoproject/static/js/lib/jquery-flot/examples

Dockerfile

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@ RUN apt-get update \
1313
&& apt-get install --assume-yes --no-install-recommends \
1414
gettext \
1515
git \
16+
libpq5 \
1617
make \
1718
netcat-openbsd \
1819
npm \
1920
postgresql-client-13 \
2021
rsync \
22+
zlib1g \
2123
&& rm -rf /var/lib/apt/lists/*
2224

25+
ARG REQ_FILE=requirements/prod.txt
26+
2327
# install python dependencies
2428
COPY ./requirements ./requirements
2529
RUN apt-get update \
@@ -28,22 +32,21 @@ RUN apt-get update \
2832
gcc \
2933
libc6-dev \
3034
libpq-dev \
31-
&& python3 -m pip install --no-cache-dir -r requirements/tests.txt \
35+
zlib1g-dev \
36+
&& python3 -m pip install --no-cache-dir -r ${REQ_FILE} \
3237
&& apt-get purge --assume-yes --auto-remove \
3338
gcc \
3439
libc6-dev \
3540
libpq-dev \
41+
zlib1g-dev \
3642
&& rm -rf /var/lib/apt/lists/*
3743

3844
# install node dependencies
3945
COPY ./package.json ./package.json
4046
RUN npm install
4147

42-
# copy docker-entrypoint.sh
43-
COPY ./docker-entrypoint.sh ./docker-entrypoint.sh
44-
4548
# copy project
4649
COPY . .
4750

4851
# run docker-entrypoint.sh
49-
ENTRYPOINT ["./docker-entrypoint.sh"]
52+
ENTRYPOINT ["./docker-entrypoint.prod.sh"]

djangoproject/settings/prod.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
from .common import * # noqa
22

3+
DOMAIN_NAME = os.getenv("DOMAIN_NAME", "djangoproject.com")
4+
35
ALLOWED_HOSTS = [
4-
"www.djangoproject.com",
5-
"djangoproject.com",
6-
"docs.djangoproject.com",
7-
"dashboard.djangoproject.com",
6+
f"www.{DOMAIN_NAME}",
7+
DOMAIN_NAME,
8+
f"docs.{DOMAIN_NAME}",
9+
f"dashboard.{DOMAIN_NAME}",
810
] + SECRETS.get("allowed_hosts", [])
911

10-
LOCALE_MIDDLEWARE_EXCLUDED_HOSTS = ["docs.djangoproject.com"]
12+
LOCALE_MIDDLEWARE_EXCLUDED_HOSTS = [f"docs.{DOMAIN_NAME}"]
1113

12-
DEBUG = False
14+
DEBUG = os.getenv("DJANGO_DEBUG", "false").lower() == "true"
1315
THUMBNAIL_DEBUG = DEBUG
1416

1517
CACHES = {
@@ -37,7 +39,7 @@
3739

3840
MEDIA_ROOT = str(DATA_DIR.joinpath("media"))
3941

40-
MEDIA_URL = "https://media.djangoproject.com/"
42+
MEDIA_URL = f"https://media.{DOMAIN_NAME}/"
4143

4244
MIDDLEWARE = (
4345
["django.middleware.cache.UpdateCacheMiddleware"]
@@ -58,7 +60,7 @@
5860

5961
STATIC_ROOT = str(DATA_DIR.joinpath("static"))
6062

61-
STATIC_URL = "https://static.djangoproject.com/"
63+
STATIC_URL = f"https://static.{DOMAIN_NAME}/"
6264

6365
# Docs settings
6466
DOCS_BUILD_ROOT = DATA_DIR.joinpath("data", "docbuilds")
@@ -67,7 +69,7 @@
6769

6870
HOST_SCHEME = "https"
6971

70-
PARENT_HOST = "djangoproject.com"
72+
PARENT_HOST = DOMAIN_NAME
7173

7274
# django-push settings
7375

docker-compose.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ services:
55
build:
66
context: ./
77
dockerfile: Dockerfile
8+
args:
9+
- REQ_FILE=requirements/tests.txt
10+
entrypoint: docker-entrypoint.dev.sh
811
command: python manage.py runserver 0.0.0.0:8000
912
volumes:
1013
- .:/usr/src/app/

docker-entrypoint.dev.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/sh
2+
3+
echo "Waiting for postgres..."
4+
5+
while ! nc -z db 5432; do
6+
sleep 0.1
7+
done
8+
9+
echo "PostgreSQL started"
10+
11+
python -m manage flush --no-input
12+
# PGPASSWORD=djangoproject psql --host db --port 5432 --username=code.djangoproject --dbname=code.djangoproject < tracdb/trac.sql
13+
python -m manage migrate
14+
make compile-scss # must come before collectstatic
15+
python -m manage collectstatic --no-input --clear
16+
python -m manage loaddata dev_sites
17+
python -m manage loaddata doc_releases
18+
# git config --global url."https://".insteadOf git://
19+
# python -m manage update_docs
20+
python -m manage loaddata dashboard_production_metrics
21+
# python -m manage loaddata dashboard_example_data
22+
python -m manage update_metrics
23+
#python -m manage update_index
24+
25+
exec "$@"

docker-entrypoint.prod.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
3+
python -m manage migrate
4+
python -m manage compilemessages
5+
make compile-scss # must come before collectstatic
6+
python -m manage collectstatic --no-input --clear
7+
8+
exec "$@"

docker-entrypoint.sh

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)