Skip to content

Commit 2c88649

Browse files
committed
provide deployment with containers
1 parent 6af1455 commit 2c88649

File tree

11 files changed

+739
-12
lines changed

11 files changed

+739
-12
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ dist
1313
/testdir2
1414
/testdir*
1515
/caroline/temp
16-
/test_new_dev
16+
/test_new_dev
17+
*.tar
18+
my_deploy.sh

Dockerfile_proxy

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM nginx
2+
COPY caroline/html_dist /usr/share/nginx/html/caroline/
3+
COPY caroline/html_dist/index.html /usr/share/nginx/html/.
4+
COPY roundtable.conf /etc/nginx/conf.d/default.conf

build_containers.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#! /bin/bash
2+
3+
echo "Build proxy image"
4+
podman build -f Dockerfile_proxy -t roundtable_proxy
5+
6+
echo "Build application server"
7+
podman build -f caroline/server/Dockerfile -t roundtable_application

caroline/server/.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.11

caroline/server/Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM ghcr.io/astral-sh/uv:python3.11-bookworm-slim AS build-env
2+
3+
ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy
4+
WORKDIR /app
5+
RUN --mount=type=cache,target=/root/.cache/uv \
6+
--mount=type=bind,source=uv.lock,target=uv.lock \
7+
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
8+
uv sync --frozen --no-install-project --no-dev
9+
# ADD caroline_relay_server.py /app
10+
# ENV PATH="/app/.venv/bin:$PATH"
11+
# CMD ["gunicorn", "-k", "gevent", "-w", "1", "caroline_relay_server:app", "--bind", "0.0.0.0:8000"]
12+
13+
FROM python:3.11-slim-bookworm
14+
COPY --from=build-env /app /app
15+
ENV PATH="/app/.venv/bin:$PATH"
16+
WORKDIR /app
17+
ADD caroline_relay_server.py /app
18+
CMD ["gunicorn", "-k", "gevent", "-w", "1", "caroline_relay_server:app", "--bind", "0.0.0.0:8000"]

caroline/server/caroline_relay_server.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@
1010
)
1111
import requests
1212
import jwt
13-
import json
1413
import qrcode
1514
import io
16-
from PIL import Image
1715
import datetime
1816
import time
17+
import os
1918

2019
app = Flask(__name__)
2120
CORS(app)
22-
app.config["SECRET_KEY"] = "ADD_YOUR_OWN_SECRET_KEY"
21+
app.config["SECRET_KEY"] = os.environ.get('SECRET_KEY')
2322
socketio = SocketIO(app, cors_allowed_origins="*")
2423
apiPrefix = "/api"
25-
subscriberKey = "ADD_YOUR_OWN_SUBSCRIBER_KEY_FOR_AUTHENTICATION"
26-
24+
app.config["SUBSCRIBER_KEY"] = os.environ.get('SUBSCRIBER_KEY')
25+
app.config["GOOGLE_RECAPTCHA_SECRET"] = os.environ.get('GOOGLE_RECAPTCHA_SECRET')
26+
app.config["SERVER_DOMAIN_NAME"] = os.environ.get('SERVER_DOMAIN_NAME')
2727

2828
@app.route(apiPrefix + "/")
2929
def hello():
@@ -33,7 +33,7 @@ def hello():
3333
@app.route(apiPrefix + "/qrcode/<path>", methods=["GET"])
3434
def returnQRcode(path):
3535
qr = qrcode.QRCode()
36-
qr.add_data("https://roundtable.researchx3d.com/#" + path)
36+
qr.add_data(f"{app.config['SERVER_DOMAIN_NAME'] }/#" + path)
3737

3838
qr.make(fit=True)
3939
img = qr.make_image()
@@ -71,12 +71,12 @@ def presentationQRcode():
7171
def test_connection():
7272
# Uncomment next two lines to allow everyone to connect
7373
# That is useful for local development purposes
74-
# print("ok")
75-
# return
74+
#print("ok")
75+
#return
7676

7777
# WAY FOR PRESENTER TO GENERATE TEMPORARY KEY
7878
if "pkey" in request.args and "site" in request.args:
79-
if request.args.get("pkey") == subscriberKey:
79+
if request.args.get("pkey") == app.config["SUBSCRIBER_KEY"]:
8080
payload = {
8181
"exp": datetime.datetime.utcnow()
8282
+ datetime.timedelta(days=0, seconds=2 * 60 * 60),
@@ -97,17 +97,20 @@ def test_connection():
9797
raise ConnectionRefusedError("Invalid token")
9898

9999
if "auth" in request.args:
100+
# HACK until we debug this
101+
return
100102
r = requests.post(
101103
"https://www.google.com/recaptcha/api/siteverify",
102104
data={
103-
"secret": "ADD_YOUR_OWN_GOOGLE_RECAPTCHA_SECRET",
105+
"secret": app.config["GOOGLE_RECAPTCHA_SECRET"],
104106
"response": request.args.get("auth"),
105107
},
106108
)
107-
109+
108110
if not r.json()["success"]:
109111
disconnect()
110112
raise ConnectionRefusedError("Recaptcha expired")
113+
111114

112115
elif "auth2" in request.args:
113116
try:
@@ -141,6 +144,7 @@ def test_connection():
141144
),
142145
},
143146
)
147+
return
144148

145149

146150
@socketio.on("disconnect")

caroline/server/pyproject.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[project]
2+
name = "server"
3+
version = "0.1.0"
4+
description = "Add your description here"
5+
readme = "README.md"
6+
requires-python = ">=3.11"
7+
dependencies = [
8+
"flask-cors>=5.0.0",
9+
"flask>=3.1.0",
10+
"flask-socketio>=5.5.0",
11+
"pillow>=11.0.0",
12+
"pyjwt>=2.10.1",
13+
"requests>=2.32.3",
14+
"qrcode[pil]>=8.0",
15+
"gunicorn>=23.0.0",
16+
"gevent>=24.11.1",
17+
]

caroline/server/uv.lock

Lines changed: 592 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deploy.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#! /bin/bash
2+
3+
echo "Create pod roundtable"
4+
podman pod create -p 127.0.0.1:8001:80 --replace roundtable
5+
6+
podman run -d --pod roundtable --replace --memory=2GB --cpus=2 \
7+
--name roundtable_proxy_instance1 \
8+
localhost/roundtable_proxy:latest
9+
10+
podman run -d --pod roundtable --replace --memory=2GB --cpus=2 \
11+
--name roundtable_application_instance1 \
12+
-e SECRET_KEY="YOUR_RANDOM_STIRNG*" \
13+
-e SUBSCRIBER_KEY="YOUR_SUBSCRIBER_TOKEN_RANDOM_STRING" \
14+
-e GOOGLE_RECAPTCHA_SECRET="FORM_GOOGLE" \
15+
-e SERVER_DOMAIN_NAME="DOMAIN_NAME" \
16+
localhost/roundtable_application:latest

roundtable.conf

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
server {
2+
listen 80;
3+
listen [::]:80;
4+
5+
server_name _;
6+
7+
root /usr/share/nginx/html;
8+
9+
include /etc/nginx/default.d/*.conf;
10+
11+
gzip on;
12+
gzip_vary on;
13+
gzip_min_length 10240;
14+
gzip_types text/css text/javascript application/x-javascript;
15+
16+
17+
location / {
18+
index index.html;
19+
gzip on;
20+
gzip_types application/json;
21+
gzip_static on;
22+
23+
}
24+
25+
location /socket.io {
26+
proxy_http_version 1.1;
27+
proxy_buffering off;
28+
proxy_set_header Upgrade $http_upgrade;
29+
proxy_set_header Connection "Upgrade";
30+
proxy_pass http://127.0.0.1:8000/socket.io;
31+
}
32+
33+
location /api {
34+
gzip on;
35+
gzip_types application/json;
36+
gzip_static on;
37+
38+
proxy_http_version 1.1;
39+
proxy_buffering off;
40+
proxy_set_header Upgrade $http_upgrade;
41+
proxy_set_header Connection "Upgrade";
42+
proxy_pass http://127.0.0.1:8000;
43+
}
44+
}

0 commit comments

Comments
 (0)