Skip to content

Commit 721d313

Browse files
Merge branch 'main' into voicemute
2 parents 53bbaac + b9afaf7 commit 721d313

File tree

76 files changed

+1807
-406
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+1807
-406
lines changed

.github/CODEOWNERS

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,12 @@ pydis_site/apps/api/viewsets/bot/infraction.py @MarkKoz
66
pydis_site/apps/home/** @ks129
77

88
# Django ORM
9-
**/migrations/** @Akarys42
10-
**/models/** @Akarys42 @Den4200
9+
**/models/** @Den4200
1110

1211
# CI & Docker
13-
.github/workflows/** @MarkKoz @Akarys42 @SebastiaanZ @Den4200 @ks129
14-
Dockerfile @MarkKoz @Akarys42 @Den4200
15-
docker-compose.yml @MarkKoz @Akarys42 @Den4200
16-
17-
# Tools
18-
poetry.lock @Akarys42
19-
pyproject.toml @Akarys42
12+
.github/workflows/** @MarkKoz @SebastiaanZ @Den4200 @ks129
13+
Dockerfile @MarkKoz @Den4200
14+
docker-compose.yml @MarkKoz @Den4200
2015

2116
# Metricity
2217
pydis_site/apps/api/models/bot/metricity.py @jb3

.github/workflows/static-preview.yaml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Build & Publish Static Preview
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
build:
11+
name: Build Static Preview
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v2
16+
17+
# Create a commit SHA-based tag for the container repositories
18+
- name: Create SHA Container Tag
19+
id: sha_tag
20+
run: |
21+
tag=$(cut -c 1-7 <<< $GITHUB_SHA)
22+
echo "::set-output name=tag::$tag"
23+
24+
- name: Set up Docker Buildx
25+
uses: docker/setup-buildx-action@v1
26+
27+
- name: Login to Github Container Registry
28+
uses: docker/login-action@v1
29+
with:
30+
registry: ghcr.io
31+
username: ${{ github.repository_owner }}
32+
password: ${{ secrets.GITHUB_TOKEN }}
33+
34+
# Build the container, including an inline cache manifest to
35+
# allow us to use the registry as a cache source.
36+
- name: Build Docker Image (Main)
37+
uses: docker/build-push-action@v2
38+
if: github.ref == 'refs/heads/main'
39+
with:
40+
context: .
41+
push: true
42+
cache-from: type=registry,ref=ghcr.io/python-discord/static-site:latest
43+
cache-to: type=inline
44+
tags: |
45+
ghcr.io/python-discord/static-site:latest
46+
ghcr.io/python-discord/static-site:${{ steps.sha_tag.outputs.tag }}
47+
build-args: |
48+
git_sha=${{ github.sha }}
49+
STATIC_BUILD=TRUE
50+
51+
- name: Extract Build From Docker Image (Main)
52+
if: github.ref == 'refs/heads/main'
53+
run: |
54+
mkdir docker_build \
55+
&& docker run --entrypoint /bin/echo --name site \
56+
ghcr.io/python-discord/static-site:${{ steps.sha_tag.outputs.tag }} \
57+
&& docker cp site:/app docker_build/
58+
59+
# Build directly to a local folder
60+
- name: Build Docker Image (PR)
61+
uses: docker/build-push-action@v2
62+
if: github.ref != 'refs/heads/main'
63+
with:
64+
context: .
65+
push: false
66+
cache-from: type=registry,ref=ghcr.io/python-discord/static-site:latest
67+
outputs: type=local,dest=docker_build/
68+
build-args: |
69+
git_sha=${{ github.sha }}
70+
STATIC_BUILD=TRUE
71+
72+
- name: Upload Build
73+
uses: actions/upload-artifact@v2
74+
with:
75+
name: static-build
76+
path: docker_build/app/build/
77+
if-no-files-found: error

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,6 @@ staticfiles/
126126

127127
*.js.tmp
128128
log.*
129+
130+
# Local Netlify folder
131+
.netlify

Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ RUN \
3636
METRICITY_DB_URL=postgres://localhost \
3737
python manage.py collectstatic --noinput --clear
3838

39+
# Build static files if we are doing a static build
40+
ARG STATIC_BUILD=false
41+
RUN if [ $STATIC_BUILD = "TRUE" ] ; \
42+
then SECRET_KEY=dummy_value python manage.py distill-local build --traceback --force ; \
43+
fi
44+
3945
# Run web server through custom manager
4046
ENTRYPOINT ["python", "manage.py"]
4147
CMD ["run"]

manage.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env python
22
import os
3+
import platform
34
import sys
5+
from pathlib import Path
46

57
import django
68
from django.contrib.auth import get_user_model
@@ -147,6 +149,22 @@ def run_server(self) -> None:
147149
gunicorn.app.wsgiapp.run()
148150

149151

152+
def clean_up_static_files(build_folder: Path) -> None:
153+
"""Recursively loop over the build directory and fix links."""
154+
for file in build_folder.iterdir():
155+
if file.is_dir():
156+
clean_up_static_files(file)
157+
elif file.name.endswith(".html"):
158+
# Fix parent host url
159+
new = file.read_text(encoding="utf-8").replace(f"//{os.getenv('PARENT_HOST')}", "")
160+
161+
# Fix windows paths if on windows
162+
if platform.system() == "Windows":
163+
new = new.replace("%5C", "/")
164+
165+
file.write_text(new, encoding="utf-8")
166+
167+
150168
def main() -> None:
151169
"""Entry point for Django management script."""
152170
# Use the custom site manager for launching the server
@@ -155,8 +173,23 @@ def main() -> None:
155173

156174
# Pass any others directly to standard management commands
157175
else:
176+
_static_build = "distill" in sys.argv[1]
177+
178+
if _static_build:
179+
# Build a static version of the site with no databases and API support
180+
os.environ["STATIC_BUILD"] = "True"
181+
if not os.getenv("PARENT_HOST"):
182+
os.environ["PARENT_HOST"] = "REPLACE_THIS.HOST"
183+
158184
execute_from_command_line(sys.argv)
159185

186+
if _static_build:
187+
# Clean up parent host in generated files
188+
for arg in sys.argv[2:]:
189+
if not arg.startswith("-"):
190+
clean_up_static_files(Path(arg))
191+
break
192+
160193

161194
if __name__ == '__main__':
162195
main()

0 commit comments

Comments
 (0)