Skip to content

Commit 6b0a37f

Browse files
committed
Change python server port and add nginx to services for proxying
1 parent 71a85bc commit 6b0a37f

File tree

6 files changed

+36
-63
lines changed

6 files changed

+36
-63
lines changed

.run/devserver.run.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<option name="ADD_SOURCE_ROOTS" value="false" />
1414
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
1515
<option name="SCRIPT_NAME" value="contentcuration/manage.py" />
16-
<option name="PARAMETERS" value="runserver --settings=contentcuration.dev_settings 0.0.0.0:8080" />
16+
<option name="PARAMETERS" value="runserver --settings=contentcuration.dev_settings 0.0.0.0:8081" />
1717
<option name="SHOW_COMMAND_LINE" value="false" />
1818
<option name="EMULATE_TERMINAL" value="false" />
1919
<option name="MODULE_MODE" value="false" />

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ dctest: .docker/minio .docker/postgres
200200

201201
dcservicesup: .docker/minio .docker/postgres
202202
# launch all studio's dependent services using docker-compose
203-
$(DOCKER_COMPOSE) -f docker-compose.yml -f docker-compose.alt.yml up minio postgres redis
203+
$(DOCKER_COMPOSE) -f docker-compose.yml -f docker-compose.alt.yml up minio postgres redis studio-nginx
204204

205205
dcservicesdown:
206206
# stop services that were started using dcservicesup

contentcuration/contentcuration/models.py

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import json
33
import logging
44
import os
5-
import urllib.parse
65
import uuid
76
from datetime import datetime
87

@@ -671,44 +670,10 @@ def generate_storage_url(filename, request=None, *args):
671670

672671
path = generate_object_storage_name(os.path.splitext(filename)[0], filename)
673672

674-
# There are three scenarios where Studio might be run as:
675-
#
676-
# 1. In normal kubernetes, nginx will proxy for us. We'll know we're in kubernetes when the
677-
# environment variable RUN_MODE=k8s
678-
#
679-
# 2. In Docker Compose and bare metal runserver, we'll be running in runserver, and minio
680-
# will be exposed in port 9000 in the host's localhost network.
681-
682-
# Note (aron): returning the true storage URL (e.g. https://storage.googleapis.com/storage/a.mp4)
683-
# isn't too important, because we have CDN in front of our servers, so it should be cached.
684-
# But change the logic here in case there is a potential for bandwidth and latency improvement.
685-
686-
# Detect our current state first
687-
run_mode = os.getenv("RUN_MODE")
688-
689-
# if we're running inside k8s, then just serve the normal /content/{storage,databases} URL,
690-
# and let nginx handle proper proxying.
691-
if run_mode == "k8s":
692-
url = "/content/{path}".format(
693-
path=path,
694-
)
695-
696-
# if we're in docker-compose or in baremetal, just return the object storage URL as localhost:9000
697-
elif run_mode == "docker-compose" or run_mode is None:
698-
# generate the minio storage URL, so we can get the GET parameters that give everyone
699-
# access even if they don't need to log in
700-
params = urllib.parse.urlparse(default_storage.url(path)).query
701-
host = "localhost"
702-
port = 9000 # hardcoded to the default minio IP address
703-
url = "http://{host}:{port}/{bucket}/{path}?{params}".format(
704-
host=host,
705-
port=port,
706-
bucket=settings.AWS_S3_BUCKET_NAME,
707-
path=path,
708-
params=params,
709-
)
710-
711-
return url
673+
# requires that we always have a proxy of /content to storage bucket, handled by nginx in dev
674+
return "/content/{path}".format(
675+
path=path,
676+
)
712677

713678

714679
class FileOnDiskStorage(FileSystemStorage):

docker-compose.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ x-studio-environment:
1414
CELERY_BROKER_ENDPOINT: redis
1515
CELERY_RESULT_BACKEND_ENDPOINT: redis
1616
CELERY_REDIS_PASSWORD: ""
17-
PROBER_STUDIO_BASE_URL: http://studio-app:8080/{path}
17+
PROBER_STUDIO_BASE_URL: http://studio-app:8081/{path}
18+
WEBPACK_DEV_HOST: 0.0.0.0
1819

1920
x-studio-worker:
2021
&studio-worker
@@ -36,18 +37,15 @@ services:
3637
build:
3738
context: .
3839
dockerfile: k8s/images/nginx/Dockerfile
39-
ports:
40-
- "8081:8080"
41-
depends_on:
42-
- studio-app
40+
network_mode: host
4341
environment: *studio-environment
4442

4543
studio-app:
4644
<<: *studio-worker
4745
entrypoint: python docker/entrypoint.py
4846
command: pnpm run devserver
4947
ports:
50-
- "8080:8080"
48+
- "8081:8081"
5149
- "4000:4000"
5250

5351
celery-worker:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"test-jest": "pnpm run test",
2626
"test-jest:debug": "node --inspect node_modules/.bin/jest --runInBand --watch",
2727
"minio": "MINIO_API_CORS_ALLOW_ORIGIN='http://localhost:8080,http://127.0.0.1:8080' MINIO_ACCESS_KEY=development MINIO_SECRET_KEY=development minio server ~/.minio_data/ || true",
28-
"runserver": "cd contentcuration && python manage.py runserver --settings=contentcuration.dev_settings 0.0.0.0:8080",
28+
"runserver": "cd contentcuration && python manage.py runserver --settings=contentcuration.dev_settings 0.0.0.0:8081",
2929
"devserver": "npm-run-all --parallel build:dev runserver",
3030
"devserver:hot": "npm-run-all --parallel build:dev:hot runserver",
3131
"devserver-hot": "pnpm run devserver:hot",

webpack.config.js

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ const WebpackRTLPlugin = require('kolibri-tools/lib/webpackRtlPlugin');
1616

1717
const { InjectManifest } = require('workbox-webpack-plugin');
1818

19-
// Function to detect if running in WSL
19+
const DEFAULT_WEBPACK_DEV_HOST = '127.0.0.1';
20+
21+
/**
22+
* Function to detect if running in WSL
23+
* @return {boolean}
24+
*/
2025
function isWSL() {
2126
try {
2227
const version = fs.readFileSync('/proc/version', 'utf8');
@@ -26,14 +31,24 @@ function isWSL() {
2631
}
2732
}
2833

29-
// Function to get WSL IP address
30-
function getWSLIP() {
34+
/**
35+
* Get the host for the webpack dev server.
36+
* @return {string}
37+
*/
38+
function getWebpackDevHost() {
39+
if (process.env.WEBPACK_DEV_HOST) {
40+
return process.env.WEBPACK_DEV_HOST;
41+
}
42+
43+
if (!isWSL()) {
44+
return DEFAULT_WEBPACK_DEV_HOST;
45+
}
46+
3147
try {
32-
const ip = execSync('hostname -I').toString().trim().split(' ')[0];
33-
return ip;
48+
return execSync('hostname -I').toString().trim().split(' ')[0];
3449
} catch (err) {
3550
console.warn('Failed to get WSL IP address:', err);
36-
return '127.0.0.1';
51+
return DEFAULT_WEBPACK_DEV_HOST;
3752
}
3853
}
3954

@@ -60,11 +75,8 @@ module.exports = (env = {}) => {
6075
const pnpmNodeModules = path.join(rootDir, 'node_modules', '.pnpm', 'node_modules');
6176

6277
// Determine the appropriate dev server host and public path based on environment
63-
const isWSLEnvironment = isWSL();
64-
const devServerHost = isWSLEnvironment ? '0.0.0.0' : '127.0.0.1';
65-
const devPublicPath = isWSLEnvironment ?
66-
`http://${getWSLIP()}:4000/dist/` :
67-
'http://127.0.0.1:4000/dist/';
78+
const devServerHost = getWebpackDevHost();
79+
const devPublicPath = `http://${devServerHost}:4000/dist/`;
6880

6981
const workboxPlugin = new InjectManifest({
7082
swSrc: path.resolve(srcDir, 'serviceWorker/index.js'),
@@ -120,10 +132,8 @@ module.exports = (env = {}) => {
120132
allowedHosts: [
121133
'127.0.0.1',
122134
'localhost',
123-
].concat(
124-
// For WSL, allow the WSL IP address
125-
isWSLEnvironment ? [getWSLIP()] : []
126-
),
135+
getWebpackDevHost(),
136+
]
127137
},
128138
module: {
129139
rules: [

0 commit comments

Comments
 (0)