Skip to content

Commit

Permalink
added volume to nginx in docker-compose file to copy ssl certificates…
Browse files Browse the repository at this point in the history
… from host to container
  • Loading branch information
LorenaH84 committed Jun 16, 2024
1 parent 9115844 commit 0160dc4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 30 deletions.
4 changes: 3 additions & 1 deletion docker-compose-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ services:
depends_on:
- genie
- streamlit
command: /renew-certs.sh
volumes:
- /path/to/host/certificates:/etc/letsencrypt/live/app.batterymodel.com:ro
command: /bin/bash -c "/renew-certs.sh && nginx -g 'daemon off;'"

streamlit:
image: ghcr.io/battmoteam/battmogui_streamlit:latest
Expand Down
30 changes: 1 addition & 29 deletions nginx/renew-certs.sh
Original file line number Diff line number Diff line change
@@ -1,34 +1,6 @@
#!/bin/bash
set -e

# Function to start Nginx in the background
start_nginx() {
nginx -g 'daemon off;' &
NGINX_PID=$!
}
certbot certonly --webroot -w /usr/share/nginx/html -d app.batterymodel.com --email [email protected] --agree-tos --non-interactive

# 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 [email protected] --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;'

0 comments on commit 0160dc4

Please sign in to comment.