Skip to content

Commit d708d5c

Browse files
authored
Merge pull request #20 from scribear/docker-deployment
Docker deployment
2 parents 1f300a9 + ce4715c commit d708d5c

14 files changed

Lines changed: 113 additions & 65 deletions

File tree

File renamed without changes.
Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
#!/bin/bash
22
set -e
33

4+
NODE_PORT=8080
5+
FRONTEND_PORT=3000
6+
SOURCE_TOKEN="CHANGEME"
7+
SCRIBEAR_URL="http://192.168.10.160:${FRONTEND_PORT}"
8+
49
SCRIPT_DIR=$(dirname $0)
510
cd $SCRIPT_DIR
611
BASE_DIR=$(pwd)
@@ -21,18 +26,23 @@ mkdir -p $BASE_DIR/logs
2126

2227

2328
echo "Starting Whisper Service"
24-
cd $BASE_DIR/whisper-service;
29+
cd $BASE_DIR/../whisper-service;
2530
source .venv/bin/activate;
2631
python index.py 2>> $BASE_DIR/logs/whisper-service.log &
2732
PYTHON_PID=$!
2833

2934

3035
echo "Starting Node Server"
31-
cd $BASE_DIR/node-server;
36+
cd $BASE_DIR/../node-server;
3237
node ./build/src/index.js >> $BASE_DIR/logs/node-server.log &
3338
NODE_PID=$!
3439
sleep 15
3540

41+
until [ "$(curl --max-time 1 -s -w '%{http_code}' -o /dev/null "${SCRIBEAR_URL}")" -eq 200 ]
42+
do
43+
echo "Can't reach frontend at ${SCRIBEAR_URL}. Waiting for frontend to be ready..."
44+
sleep 1
45+
done
3646

3747
echo "Launching Chrome"
38-
google-chrome "https://scribear.illinois.edu/v/latest/?mode=kiosk&serverAddress=127.0.0.1:8080" --start-fullscreen
48+
google-chrome "http://localhost:${FRONTEND_PORT}/?mode=kiosk&kioskServerAddress=localhost:${NODE_PORT}&sourceToken=${SOURCE_TOKEN}&scribearURL=${SCRIBEAR_URL}" --start-fullscreen
Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
name: 'scribear-server'
22
services:
3+
whisper-service:
4+
image: scribear/whisper-service-cpu:main
5+
environment:
6+
- LOG_LEVEL=${LOG_LEVEL}
7+
- API_KEY=${API_KEY}
8+
expose:
9+
- 80
10+
restart: unless-stopped
11+
312
node-server:
4-
build:
5-
context: ./node-server
6-
dockerfile: Dockerfile
13+
image: scribear/node-server:main
714
environment:
815
- NODE_ENV=${NODE_ENV}
916
- LOG_LEVEL=${LOG_LEVEL}
10-
- HOST=0.0.0.0
11-
- PORT=8080
1217
- USE_HTTPS=${USE_HTTPS}
1318
- CORS_ORIGIN=${CORS_ORIGIN}
1419
- SERVER_ADDRESS=${SERVER_ADDRESS}
15-
- WHISPER_SERVICE_ENDPOINT=ws://whisper-service:8000/whisper?api_key=${API_KEY}&model_key=${MODEL_KEY}
20+
- WHISPER_SERVICE_ENDPOINT=ws://whisper-service:80/whisper?api_key=${API_KEY}&model_key=${MODEL_KEY}
1621
- WHISPER_RECONNECT_INTERVAL_SEC=${WHISPER_RECONNECT_INTERVAL_SEC}
1722
- REQUIRE_AUTH=${REQUIRE_AUTH}
1823
- SOURCE_TOKEN=${SOURCE_TOKEN}
@@ -22,21 +27,18 @@ services:
2227
- SESSION_TOKEN_BYTES=${SESSION_TOKEN_BYTES}
2328
- SESSION_LENGTH_SEC=${SESSION_LENGTH_SEC}
2429
ports:
25-
- ${PORT}:8080
30+
- ${NODE_PORT}:80
2631
volumes:
2732
- ${KEY_FILEPATH:-/dev/null}:/app/cert/key.pem
2833
- ${CERTIFICATE_FILEPATH:-/dev/null}:/app/cert/key.pem
2934
restart: unless-stopped
3035

31-
whisper-service:
32-
build:
33-
context: ./whisper-service
34-
dockerfile: Dockerfile_CPU
35-
environment:
36-
- LOG_LEVEL=${LOG_LEVEL}
37-
- API_KEY=${API_KEY}
38-
- HOST=0.0.0.0
39-
- PORT=8000
40-
expose:
41-
- 8000
42-
restart: unless-stopped
36+
frontend:
37+
depends_on:
38+
whisper-service:
39+
condition: service_healthy
40+
node-server:
41+
condition: service_healthy
42+
ports:
43+
- ${FRONTEND_PORT}:80
44+
image: scribear/frontend:master
Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
name: 'scribear-server'
22
services:
3+
whisper-service:
4+
image: scribear/whisper-service-cuda:main
5+
environment:
6+
- LOG_LEVEL=${LOG_LEVEL}
7+
- API_KEY=${API_KEY}
8+
expose:
9+
- 80
10+
restart: unless-stopped
11+
312
node-server:
13+
image: scribear/node-server:main
414
build:
515
context: ./node-server
616
dockerfile: Dockerfile
717
environment:
818
- NODE_ENV=${NODE_ENV}
919
- LOG_LEVEL=${LOG_LEVEL}
10-
- HOST=0.0.0.0
11-
- PORT=8080
1220
- USE_HTTPS=${USE_HTTPS}
1321
- CORS_ORIGIN=${CORS_ORIGIN}
1422
- SERVER_ADDRESS=${SERVER_ADDRESS}
15-
- WHISPER_SERVICE_ENDPOINT=ws://whisper-service:8000/whisper?api_key=${API_KEY}&model_key=${MODEL_KEY}
23+
- WHISPER_SERVICE_ENDPOINT=ws://whisper-service:80/whisper?api_key=${API_KEY}&model_key=${MODEL_KEY}
1624
- WHISPER_RECONNECT_INTERVAL_SEC=${WHISPER_RECONNECT_INTERVAL_SEC}
1725
- REQUIRE_AUTH=${REQUIRE_AUTH}
1826
- SOURCE_TOKEN=${SOURCE_TOKEN}
@@ -22,21 +30,18 @@ services:
2230
- SESSION_TOKEN_BYTES=${SESSION_TOKEN_BYTES}
2331
- SESSION_LENGTH_SEC=${SESSION_LENGTH_SEC}
2432
ports:
25-
- ${PORT}:8080
33+
- ${NODE_PORT}:80
2634
volumes:
2735
- ${KEY_FILEPATH:-/dev/null}:/app/cert/key.pem
2836
- ${CERTIFICATE_FILEPATH:-/dev/null}:/app/cert/key.pem
2937
restart: unless-stopped
3038

31-
whisper-service:
32-
build:
33-
context: ./whisper-service
34-
dockerfile: Dockerfile_CUDA
35-
environment:
36-
- LOG_LEVEL=${LOG_LEVEL}
37-
- API_KEY=${API_KEY}
38-
- HOST=0.0.0.0
39-
- PORT=8000
40-
expose:
41-
- 8000
42-
restart: unless-stopped
39+
frontend:
40+
depends_on:
41+
whisper-service:
42+
condition: service_healthy
43+
node-server:
44+
condition: service_healthy
45+
ports:
46+
- ${FRONTEND_PORT}:80
47+
image: scribear/frontend:master

deployment/docker-autostart.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
set -e
3+
4+
source .env
5+
if [ $WHISPER_SERVICE_CUDA = 'true' ]; then
6+
echo Starting services with CUDA enabled for whisper-service
7+
docker compose -f ./compose_cuda.yaml up -d
8+
else
9+
echo Starting services without CUDA
10+
docker compose -f ./compose_cpu.yaml up -d
11+
fi
12+
13+
until [ "$(curl --max-time 1 -s -w '%{http_code}' -o /dev/null "${SCRIBEAR_URL}")" -eq 200 ]
14+
do
15+
echo "Can't reach frontend at ${SCRIBEAR_URL}. Waiting for frontend to be ready..."
16+
sleep 1
17+
done
18+
19+
echo "Launching Chrome"
20+
google-chrome "http://localhost:${FRONTEND_PORT}/?mode=kiosk&kioskServerAddress=localhost:${NODE_PORT}&sourceToken=${SOURCE_TOKEN}&scribearURL=${SCRIBEAR_URL}" --start-fullscreen

template.env renamed to deployment/template.env

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ NODE_ENV="production"
22
LOG_LEVEL="info"
33

44
#### Host and port API webserver should listen on
5-
HOST="0.0.0.0"
6-
PORT=8080
5+
NODE_PORT=8080
76
CORS_ORIGIN='*'
87
SERVER_ADDRESS="192.168.10.160:8080"
98
# Enable or disable HTTPS
@@ -29,5 +28,8 @@ SESSION_TOKEN_BYTES=32
2928
# How long a single session token is valid for after generation in seconds
3029
SESSION_LENGTH_SEC=5400
3130

31+
WHISPER_SERVICE_CUDA=false
3232
MODEL_KEY="faster-whisper:cpu-tiny-en"
33-
API_KEY="CHANGEME"
33+
API_KEY="CHANGEME"
34+
FRONTEND_PORT=3000
35+
SCRIBEAR_URL="http://192.168.10.160:3000"

node-server/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ RUN npm run build
1212

1313
WORKDIR /app/build/src
1414

15+
ENV HOST=0.0.0.0
16+
ENV PORT=80
1517
ENV KEY_FILEPATH="/app/cert/key.pem"
1618
ENV CERTIFICATE_FILEPATH="/app/cert/cert.pem"
1719

20+
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --start-interval=1s --retries=3 CMD curl -f http://localhost:80/healthcheck || exit 1
21+
1822
CMD ["node", "index.js"]

node-server/src/index.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -42,25 +42,3 @@ async function init() {
4242
}
4343

4444
await init();
45-
46-
// import {Type} from '@sinclair/typebox';
47-
// import {Value} from '@sinclair/typebox/value';
48-
49-
// const TEST = Type.Intersect([
50-
// Type.Union([
51-
// Type.Object({
52-
// flag: Type.Literal(false),
53-
// }),
54-
// Type.Object({
55-
// flag: Type.Literal(true),
56-
// key: Type.String({minLength: 1}),
57-
// }),
58-
// ]),
59-
// Type.Object({
60-
// other: Type.String(),
61-
// }),
62-
// ]);
63-
64-
// const env = Value.Convert(TEST, {flag: false, key: '90', other: 'asdf'});
65-
66-
// console.log(env);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import {FastifyInstance} from 'fastify';
2+
3+
/**
4+
* Registers endpoint for checking if server is alive
5+
* @param fastify fastify webserver instance
6+
*/
7+
export default function healthcheckHandler(fastify: FastifyInstance) {
8+
fastify.get('/healthcheck', (req, reply) => {
9+
return reply.code(200).send('ok');
10+
});
11+
}

node-server/src/server/services/token_service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const MAX_TIMESTAMP = 8640000000000000;
77
export default class TokenService {
88
private _validAccessTokens: {[key: string]: Date} = {};
99
private _validSessionTokens: {[key: string]: Date} = {};
10-
private _currentAccessToken = '';
10+
private _currentAccessToken = ' ';
1111

1212
constructor(
1313
private _config: ConfigType,
@@ -134,7 +134,7 @@ export default class TokenService {
134134
*/
135135
createSessionToken() {
136136
if (!this._config.auth.required) {
137-
return {sessionToken: '', expires: this._computeNewSessionExpiry()};
137+
return {sessionToken: ' ', expires: this._computeNewSessionExpiry()};
138138
}
139139
let sessionToken = crypto.randomBytes(this._config.auth.sessionTokenBytes).toString('base64url');
140140
while (sessionToken in this._validSessionTokens) {

0 commit comments

Comments
 (0)