Skip to content
This repository was archived by the owner on Dec 30, 2025. It is now read-only.

Commit 68b4d0c

Browse files
committed
feat(compose.yaml, ssl-manager.sh): add persistent volume for Let's Encrypt data and improve certificate management
Add a new volume `letsencrypt_data` to persist Let's Encrypt certificates, ensuring they are not lost when containers are recreated. Update `ssl-manager.sh` to prioritize copying certificates from the certbot container, enhancing flexibility and reliability in certificate management. This change allows for better handling of certificates within Docker environments, ensuring they are accessible and properly managed across container restarts.
1 parent 14ef9c8 commit 68b4d0c

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

compose.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,9 @@ services:
9494
- path: .env.local
9595
required: false
9696

97-
# Volume mounts - direct access to UnrealIRCd TLS directory
97+
# Volume mounts - persist certificates and access UnrealIRCd TLS directory
9898
volumes:
99+
- letsencrypt_data:/etc/letsencrypt
99100
- ./unrealircd/conf/tls:/etc/letsencrypt/unrealircd:rw
100101
- ./cloudflare-credentials.ini:/etc/letsencrypt/cloudflare-credentials.ini:ro
101102

@@ -230,4 +231,6 @@ volumes:
230231
driver: local
231232
thelounge_data:
232233
driver: local
234+
letsencrypt_data:
235+
driver: local
233236

scripts/ssl-manager.sh

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,20 +123,36 @@ copy_certificates() {
123123
return 0
124124
fi
125125

126-
# Try to copy from Let's Encrypt directory (if running on host)
127-
local letsencrypt_dir="/etc/letsencrypt/live/$DOMAIN"
128-
if [[ -d "$letsencrypt_dir" ]]; then
129-
cp "$letsencrypt_dir/fullchain.pem" "$TLS_DIR/server.cert.pem"
130-
cp "$letsencrypt_dir/privkey.pem" "$TLS_DIR/server.key.pem"
126+
# Try to copy from Docker container first
127+
log_info "Looking for certificates in certbot container..."
128+
if docker compose run --rm certbot test -f "/etc/letsencrypt/live/$DOMAIN/fullchain.pem" 2>/dev/null; then
129+
log_info "Found certificates in certbot container, copying..."
130+
131+
# Copy certificate from container
132+
docker compose run --rm certbot cat "/etc/letsencrypt/live/$DOMAIN/fullchain.pem" > "$TLS_DIR/server.cert.pem"
133+
docker compose run --rm certbot cat "/etc/letsencrypt/live/$DOMAIN/privkey.pem" > "$TLS_DIR/server.key.pem"
131134

132135
# Set proper permissions
133136
chmod 644 "$TLS_DIR/server.cert.pem"
134137
chmod 600 "$TLS_DIR/server.key.pem"
135138

136-
log_success "Certificates copied from Let's Encrypt directory to $TLS_DIR"
139+
log_success "Certificates copied from certbot container to $TLS_DIR"
137140
else
138-
log_warn "No certificates found to copy from Let's Encrypt directory"
139-
log_info "Run 'make ssl-setup' to issue new certificates"
141+
# Try to copy from Let's Encrypt directory (if running on host)
142+
local letsencrypt_dir="/etc/letsencrypt/live/$DOMAIN"
143+
if [[ -d "$letsencrypt_dir" ]]; then
144+
cp "$letsencrypt_dir/fullchain.pem" "$TLS_DIR/server.cert.pem"
145+
cp "$letsencrypt_dir/privkey.pem" "$TLS_DIR/server.key.pem"
146+
147+
# Set proper permissions
148+
chmod 644 "$TLS_DIR/server.cert.pem"
149+
chmod 600 "$TLS_DIR/server.key.pem"
150+
151+
log_success "Certificates copied from Let's Encrypt directory to $TLS_DIR"
152+
else
153+
log_warn "No certificates found to copy"
154+
log_info "Certificates may have been issued but not accessible for copying"
155+
fi
140156
fi
141157
}
142158

0 commit comments

Comments
 (0)