Skip to content

Commit 246f58e

Browse files
committed
Change python server port and add nginx to services for proxying
1 parent 7a370cf commit 246f58e

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
@@ -196,7 +196,7 @@ dctest: .docker/minio .docker/postgres
196196

197197
dcservicesup: .docker/minio .docker/postgres
198198
# launch all studio's dependent services using docker-compose
199-
$(DOCKER_COMPOSE) -f docker-compose.yml -f docker-compose.alt.yml up minio postgres redis
199+
$(DOCKER_COMPOSE) -f docker-compose.yml -f docker-compose.alt.yml up minio postgres redis studio-nginx
200200

201201
dcservicesdown:
202202
# 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

@@ -769,44 +768,10 @@ def generate_storage_url(filename, request=None, *args):
769768

770769
path = generate_object_storage_name(os.path.splitext(filename)[0], filename)
771770

772-
# There are three scenarios where Studio might be run as:
773-
#
774-
# 1. In normal kubernetes, nginx will proxy for us. We'll know we're in kubernetes when the
775-
# environment variable RUN_MODE=k8s
776-
#
777-
# 2. In Docker Compose and bare metal runserver, we'll be running in runserver, and minio
778-
# will be exposed in port 9000 in the host's localhost network.
779-
780-
# Note (aron): returning the true storage URL (e.g. https://storage.googleapis.com/storage/a.mp4)
781-
# isn't too important, because we have CDN in front of our servers, so it should be cached.
782-
# But change the logic here in case there is a potential for bandwidth and latency improvement.
783-
784-
# Detect our current state first
785-
run_mode = os.getenv("RUN_MODE")
786-
787-
# if we're running inside k8s, then just serve the normal /content/{storage,databases} URL,
788-
# and let nginx handle proper proxying.
789-
if run_mode == "k8s":
790-
url = "/content/{path}".format(
791-
path=path,
792-
)
793-
794-
# if we're in docker-compose or in baremetal, just return the object storage URL as localhost:9000
795-
elif run_mode == "docker-compose" or run_mode is None:
796-
# generate the minio storage URL, so we can get the GET parameters that give everyone
797-
# access even if they don't need to log in
798-
params = urllib.parse.urlparse(default_storage.url(path)).query
799-
host = "localhost"
800-
port = 9000 # hardcoded to the default minio IP address
801-
url = "http://{host}:{port}/{bucket}/{path}?{params}".format(
802-
host=host,
803-
port=port,
804-
bucket=settings.AWS_S3_BUCKET_NAME,
805-
path=path,
806-
params=params,
807-
)
808-
809-
return url
771+
# requires that we always have a proxy of /content to storage bucket, handled by nginx in dev
772+
return "/content/{path}".format(
773+
path=path,
774+
)
810775

811776

812777
class FileOnDiskStorage(FileSystemStorage):

docker-compose.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ x-studio-environment:
1515
CELERY_RESULT_BACKEND_ENDPOINT: redis
1616
CELERY_REDIS_PASSWORD: ""
1717
REMAP_SIGTERM: "SIGQUIT"
18-
PROBER_STUDIO_BASE_URL: http://studio-app:8080/{path}
18+
PROBER_STUDIO_BASE_URL: http://studio-app:8081/{path}
19+
WEBPACK_DEV_HOST: 0.0.0.0
1920

2021
x-studio-worker:
2122
&studio-worker
@@ -37,18 +38,15 @@ services:
3738
build:
3839
context: .
3940
dockerfile: docker/Dockerfile.nginx.prod
40-
ports:
41-
- "8081:8080"
42-
depends_on:
43-
- studio-app
41+
network_mode: host
4442
environment: *studio-environment
4543

4644
studio-app:
4745
<<: *studio-worker
4846
entrypoint: python docker/studio-dev/entrypoint.py
4947
command: pnpm run devserver
5048
ports:
51-
- "8080:8080"
49+
- "8081:8081"
5250
- "4000:4000"
5351

5452
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)