Skip to content

Commit 3c92a9f

Browse files
committed
add https support with self signed cert
1 parent c00edbb commit 3c92a9f

File tree

5 files changed

+63
-32
lines changed

5 files changed

+63
-32
lines changed

.env.example

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ ASKCOS_REGISTRY=registry.gitlab.com/mlpds_mit/askcosv2/askcos2_core
1717
# Module config path (change this to customize deployment)
1818
MODULE_CONFIG_PATH=configs/module_config_full.py
1919

20+
# App protocol (http or https) for deployment
21+
PROTOCOL=http
22+
2023
# Mongo DB configuration
2124
MONGO_HOST=0.0.0.0
2225
MONGO_PORT=27017
@@ -34,7 +37,7 @@ RABBITMQ_HOST=0.0.0.0
3437
RABBITMQ_PORT=5672
3538

3639
# Current ASKCOS version number
37-
VERSION_NUMBER=2023.10
40+
VERSION_NUMBER=2023.11
3841

3942
# If set, enables reaction precedent hyperlinks to direct to Pistachio web app
4043
PISTACHIO_WEB_URL=

compose.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ services:
88
- './askcos.ssl.cert:/etc/ssl/certs/askcos.ssl.cert'
99
- './askcos.ssl.key:/etc/ssl/private/askcos.ssl.key'
1010
ports:
11-
- '80:80'
12-
- '443:443'
11+
- "80:80"
12+
- "443:443"
1313
depends_on:
1414
- app
15+
- celery_workers
1516

1617
app:
1718
image: ${ASKCOS_REGISTRY}/app:2.0

deploy.sh

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -172,16 +172,30 @@ diff-env() {
172172
fi
173173
}
174174

175-
copy-https-conf() {
176-
echo "Using https nginx configuration."
177-
cp nginx.https.conf nginx.conf
178-
echo
179-
# Create SSL
175+
copy-nginx-conf() {
176+
# always create the cert if not exist, even for http
177+
# the cert and key files are volume mapped by docker compose, so creating them as files is more idiot-proof
178+
# otherwise they might be created as directories
180179
if [ ! -f "askcos.ssl.cert" ]; then
181-
echo "Creating SSL certificates."
180+
echo "Creating self-signed SSL certificates."
182181
openssl req -new -newkey rsa:4096 -days 3650 -nodes -x509 -subj "/C=US/ST=MA/L=BOS/O=askcos/CN=askcos.$RANDOM.com" -keyout askcos.ssl.key -out askcos.ssl.cert
183182
echo
184183
fi
184+
185+
if [ -f "nginx.conf" ]; then
186+
echo "Found nginx config at ./nginx.conf"
187+
return
188+
fi
189+
190+
if [ "$PROTOCOL" = "http" ]; then
191+
echo "Using default http nginx configuration."
192+
cp nginx.http.conf nginx.conf
193+
echo
194+
elif [ "$PROTOCOL" = "https" ]; then
195+
echo "Using default https nginx configuration."
196+
cp nginx.https.conf nginx.conf
197+
echo
198+
fi
185199
}
186200

187201
set-db-defaults() {
@@ -387,21 +401,6 @@ seed-db() {
387401
echo
388402
}
389403

390-
generate-deployment-scripts-in-docker() {
391-
if [ -z "${ASKCOS_REGISTRY}" ]; then
392-
export ASKCOS_REGISTRY=registry.gitlab.com/mlpds_mit/askcosv2
393-
fi
394-
395-
echo "Building image for askcos2_core, runtime: docker"
396-
docker build -f Dockerfile -t ${ASKCOS_REGISTRY}/askcos2_core:2.0 .
397-
398-
docker run --rm \
399-
-e ASKCOS2_CORE_DIR="$PWD" \
400-
-v "${PWD%/*}":/ASKCOSv2 \
401-
-t ${ASKCOS_REGISTRY}/askcos2_core:2.0 \
402-
python scripts/pre_deploy.py
403-
}
404-
405404
generate-deployment-scripts() {
406405
python scripts/pre_deploy.py
407406
}
@@ -460,7 +459,7 @@ backup() {
460459
mkdir -p "${BACKUP_DIR}"
461460
echo "Backing up data to ${BACKUP_DIR}"
462461
echo "This may take a few minutes..."
463-
export_volume mongo_data "${BACKUP_DIR}" mongo_data.tar.gz
462+
export_volume askcosv2_mongo_data "${BACKUP_DIR}" mongo_data.tar.gz
464463
echo "Backup complete."
465464
}
466465

@@ -470,7 +469,7 @@ restore() {
470469
fi
471470
echo "Restoring data from ${BACKUP_DIR}"
472471
echo "This may take a few minutes..."
473-
import_volume mongo_data "${BACKUP_DIR}" mongo_data.tar.gz
472+
import_volume askcosv2_mongo_data "${BACKUP_DIR}" mongo_data.tar.gz
474473
echo "Restore complete."
475474
}
476475

@@ -502,7 +501,7 @@ else
502501
$arg
503502
;;
504503
pre-deploy)
505-
copy-https-conf
504+
copy-nginx-conf
506505
diff-env
507506
generate-deployment-scripts
508507
get-images
@@ -512,7 +511,7 @@ else
512511
;;
513512
deploy)
514513
# Normal first deployment, do everything (pre-deploy + start-backend-services)
515-
copy-https-conf
514+
copy-nginx-conf
516515
diff-env
517516
generate-deployment-scripts
518517
get-images
@@ -523,7 +522,7 @@ else
523522
;;
524523
update)
525524
# Update an existing configuration, database seeding is not performed
526-
copy-https-conf
525+
copy-nginxnginxnginx-conf
527526
diff-env
528527
generate-deployment-scripts
529528
get-images

nginx.http.conf

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
events {
2+
worker_connections 1024;
3+
}
4+
5+
http {
6+
include /etc/nginx/mime.types;
7+
8+
# Extra
9+
proxy_read_timeout 600;
10+
uwsgi_read_timeout 600;
11+
12+
server {
13+
listen 80;
14+
server_name askcos;
15+
charset utf-8;
16+
client_max_body_size 25M;
17+
18+
# Route all the vue build pages
19+
location / {
20+
root /usr/share/nginx/html;
21+
index index.html index.htm;
22+
try_files $uri $uri/ /index.html;
23+
}
24+
25+
# Finally, send all non-media requests to the Fastapi server.
26+
location /api/ {
27+
proxy_pass http://0.0.0.0:9100;
28+
}
29+
}
30+
}

nginx.https.conf

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,11 @@ http {
3737
root /usr/share/nginx/html;
3838
index index.html;
3939
try_files $uri $uri/ /index.html;
40-
autoindex on;
4140
}
4241

4342
# Finally, send all non-media requests to the Fastapi server.
4443
location /api/ {
45-
uwsgi_pass 0.0.0.0:9100;
46-
include /etc/nginx/uwsgi_params;
44+
proxy_pass http://0.0.0.0:9100;
4745
}
4846
}
4947
}

0 commit comments

Comments
 (0)