From 91158448be882fe411ed104cd04bab12aa0f0463 Mon Sep 17 00:00:00 2001 From: Lorena Hendrix Date: Sat, 15 Jun 2024 21:07:25 +0200 Subject: [PATCH] adding debug nginx --- docker-compose-deploy.yml | 17 +++-------------- nginx/Dockerfile | 1 + nginx/renew-certs.sh | 35 +++++++++++++++++++++++++++++++---- 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/docker-compose-deploy.yml b/docker-compose-deploy.yml index fb7fdbe..8b1e637 100644 --- a/docker-compose-deploy.yml +++ b/docker-compose-deploy.yml @@ -1,20 +1,16 @@ version: "3.3" services: - genie: image: ghcr.io/battmoteam/battmogui_genie:latest - build: ./genie container_name: genie restart: always ports: - "8000:8000" - #command: gunicorn -w 1 -b 0.0.0.0:8000 wsgi:server --timeout 200 - command: su genie -c 'julia --project=. -e "include("app/rest.jl")" --color=yes --depwarn=no --project=@. --sysimage="/home/sysimage.so" -q -i -- $$(dirname $$0)/../bootstrap.jl -s=true "$$@"' + command: su genie -c 'julia --project=. -e "include(\"app/rest.jl\")" --color=yes --depwarn=no --project=@. --sysimage=\"/home/sysimage.so\" -q -i -- $$(dirname $$0)/../bootstrap.jl -s=true "$$@"' nginx: image: ghcr.io/battmoteam/battmogui_nginx:latest - build: ./nginx container_name: nginx restart: always ports: @@ -24,19 +20,12 @@ services: depends_on: - genie - streamlit - command: /bin/bash -c "/renew-certs.sh && nginx -g 'daemon off;'" - + command: /renew-certs.sh + streamlit: image: ghcr.io/battmoteam/battmogui_streamlit:latest - build: ./streamlit container_name: streamlit restart: always ports: - "80:80" - # volumes: - # - type: bind - # source: $HOST/location - # target: /container/location - # depends_on: - # - flask command: streamlit run Introduction.py --global.disableWidgetStateDuplicationWarning true --server.port=80 \ No newline at end of file diff --git a/nginx/Dockerfile b/nginx/Dockerfile index 7e12389..f75a454 100644 --- a/nginx/Dockerfile +++ b/nginx/Dockerfile @@ -23,4 +23,5 @@ COPY project.conf /etc/nginx/conf.d/ COPY renew-certs.sh /renew-certs.sh RUN chmod +x /renew-certs.sh +# Entrypoint to handle certificate issuance and renewal ENTRYPOINT ["/renew-certs.sh"] \ No newline at end of file diff --git a/nginx/renew-certs.sh b/nginx/renew-certs.sh index 671854d..3a8304e 100644 --- a/nginx/renew-certs.sh +++ b/nginx/renew-certs.sh @@ -1,7 +1,34 @@ #!/bin/bash set -e -# Obtain/renew SSL certificates -certbot certonly --webroot -w /usr/share/nginx/html -d app.batterymodel.com --agree-tos --email lorena.hendrix@sintef.no -# Reload Nginx to apply new certificates -nginx -s reload \ No newline at end of file +# Function to start Nginx in the background +start_nginx() { + nginx -g 'daemon off;' & + NGINX_PID=$! +} + +# Function to stop the Nginx process +stop_nginx() { + if [ -n "$NGINX_PID" ]; then + kill "$NGINX_PID" + fi +} + +# Trap to ensure Nginx is stopped on script exit +trap stop_nginx EXIT + +# Start Nginx to serve the challenge files +start_nginx + +# Obtain or renew certificates +if [ ! -d "/etc/letsencrypt/live/app.batterymodel.com" ]; then + certbot certonly --webroot -w /usr/share/nginx/html -d app.batterymodel.com --email lorena.hendrix@sintef.no --agree-tos --non-interactive +else + certbot renew --webroot -w /usr/share/nginx/html +fi + +# Stop the background Nginx process +stop_nginx + +# Start Nginx in the foreground +exec nginx -g 'daemon off;' \ No newline at end of file