Skip to content

Commit dd6f0be

Browse files
committed
🚀(scalingo) add Scalingo deployment scripts and fix frontend build
This commit, with contributions from Sylvain Grizard, adds support for PaaS deployment platforms such as Scalingo, which build the project on commit. It uses the La Suite Buildpack, which compiles the frontend first as static files, and serves them along with the backend with nginx.
1 parent f77d287 commit dd6f0be

File tree

11 files changed

+146
-8
lines changed

11 files changed

+146
-8
lines changed

Procfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
web: bin/scalingo_run_web
2+
postdeploy: python manage.py migrate

bin/scalingo_postcompile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
set -o errexit # always exit on error
4+
set -o pipefail # don't ignore exit codes when piping output
5+
6+
echo "-----> Running post-compile script"
7+
8+
# Remove all the files we don't need
9+
rm -rf src docker env.d .cursor .github compose.yaml README.md .cache
10+
11+
chmod +x bin/scalingo_run_web

bin/scalingo_postfrontend

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
set -o errexit # always exit on error
4+
set -o pipefail # don't ignore exit codes when piping output
5+
6+
echo "-----> Running post-frontend script"
7+
8+
# Move the frontend build to the nginx root and clean up
9+
mkdir -p build/
10+
mv src/frontend/apps/drive/out build/frontend-out
11+
12+
mv src/backend/* ./
13+
mv src/nginx/* ./
14+
15+
echo "3.13" > .python-version

bin/scalingo_run_web

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
# Start the Django backend
4+
gunicorn -b :8000 drive.wsgi:application --log-file - &
5+
6+
# Start the Nginx server
7+
bin/run &
8+
9+
# if the current shell is killed, also terminate all its children
10+
trap "pkill SIGTERM -P $$" SIGTERM
11+
12+
# wait for a single child to finish,
13+
wait -n
14+
# then kill all the other tasks
15+
pkill -P $$

docker/files/production/etc/nginx/conf.d/default.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ server {
6565
}
6666

6767
location /media-auth {
68-
proxy_pass http://docs_backend/api/v1.0/documents/media-auth/;
68+
proxy_pass http://docs_backend/api/v1.0/items/media-auth/;
6969
proxy_set_header X-Forwarded-Proto https;
7070
proxy_set_header Host $host;
7171
proxy_set_header X-Real-IP $remote_addr;

src/backend/drive/settings.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@
1616

1717
from django.utils.translation import gettext_lazy as _
1818

19+
import dj_database_url
1920
import posthog
2021
import sentry_sdk
2122
from configurations import Configuration, values
2223
from sentry_sdk.integrations.django import DjangoIntegration
2324

2425
# Build paths inside the project like this: BASE_DIR / 'subdir'.
2526
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
26-
DATA_DIR = os.path.join("/", "data")
27+
DATA_DIR = os.environ.get("DATA_DIR", os.path.join("/", "data"))
2728

2829

2930
def get_release():
@@ -74,7 +75,9 @@ class Base(Configuration):
7475

7576
# Database
7677
DATABASES = {
77-
"default": {
78+
"default": dj_database_url.config()
79+
if os.environ.get("DATABASE_URL")
80+
else {
7881
"ENGINE": values.Value(
7982
"django.db.backends.postgresql_psycopg2",
8083
environ_name="DB_ENGINE",

src/backend/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ requires-python = ">=3.12"
2727
dependencies = [
2828
"boto3==1.36.7",
2929
"Brotli==1.1.0",
30+
"dj-database-url==2.3.0",
3031
"celery[redis]==5.5.0",
3132
"django==5.1.9",
3233
"django-configurations==2.5.1",

src/frontend/apps/drive/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
"private": true,
55
"scripts": {
66
"dev": "next dev",
7-
"build": "next build",
7+
"build": "next build --no-lint",
88
"start": "next start",
99
"lint": "next lint",
1010
"build-theme": "cunningham -g css,scss -o src/styles && mv src/styles/cunningham-tokens.scss src/styles/cunningham-tokens-sass.scss"
1111
},
12+
"engines": {
13+
"node": ">=22.0.0 <23.0.0"
14+
},
1215
"dependencies": {
1316
"@gouvfr-lasuite/ui-kit": "0.5.0",
1417
"@openfun/cunningham-react": "3.0.0",

src/frontend/apps/drive/src/features/explorer/components/Explorer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ export interface ExplorerProps {
1010
childrenItems?: Item[];
1111
gridActionsCell?: (params: ExplorerGridActionsCellProps) => React.ReactNode;
1212
disableItemDragAndDrop?: boolean;
13-
gridHeader?: JSX.Element;
14-
selectionBarActions?: JSX.Element;
13+
gridHeader?: React.ReactNode;
14+
selectionBarActions?: React.ReactNode;
1515
filters?: ItemFilters;
1616
onFiltersChange?: (filters: ItemFilters) => void;
1717
// Override the default onNavigate from ExplorerContext

src/frontend/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
"packages/*"
88
],
99
"scripts": {
10-
"lint": "yarn workspaces run lint"
10+
"dev": "turbo run dev",
11+
"build": "cd apps/drive && yarn build"
1112
},
1213
"resolutions": {},
1314
"devDependencies": {
1415
"turbo": "2.0.10"
1516
},
1617
"packageManager": "yarn@1.22.22"
17-
}
18+
}

0 commit comments

Comments
 (0)