fix: reload proxy on ssl cert

This commit is contained in:
Andras Bacsai 2022-03-02 12:10:12 +01:00
parent 5d722183d3
commit acacef95cd

View File

@ -1,5 +1,5 @@
import { asyncExecShell, getDomain, getEngine } from '$lib/common'; import { asyncExecShell, getDomain, getEngine } from '$lib/common';
import { checkContainer } from '$lib/haproxy'; import { checkContainer, reloadHaproxy } from '$lib/haproxy';
import * as db from '$lib/database'; import * as db from '$lib/database';
import { dev } from '$app/env'; import { dev } from '$app/env';
import cuid from 'cuid'; import cuid from 'cuid';
@ -56,6 +56,7 @@ export async function letsEncrypt(domain, id = null, isCoolify = false) {
await asyncExecShell( await asyncExecShell(
`DOCKER_HOST=${host} docker run --rm -v "coolify-letsencrypt:/etc/letsencrypt" -v "coolify-ssl-certs:/app/ssl" alpine:latest sh -c "test -d /etc/letsencrypt/live/${nakedDomain}/ && cat /etc/letsencrypt/live/${nakedDomain}/fullchain.pem /etc/letsencrypt/live/${nakedDomain}/privkey.pem > /app/ssl/${nakedDomain}.pem || cat /etc/letsencrypt/live/${wwwDomain}/fullchain.pem /etc/letsencrypt/live/${wwwDomain}/privkey.pem > /app/ssl/${wwwDomain}.pem"` `DOCKER_HOST=${host} docker run --rm -v "coolify-letsencrypt:/etc/letsencrypt" -v "coolify-ssl-certs:/app/ssl" alpine:latest sh -c "test -d /etc/letsencrypt/live/${nakedDomain}/ && cat /etc/letsencrypt/live/${nakedDomain}/fullchain.pem /etc/letsencrypt/live/${nakedDomain}/privkey.pem > /app/ssl/${nakedDomain}.pem || cat /etc/letsencrypt/live/${wwwDomain}/fullchain.pem /etc/letsencrypt/live/${wwwDomain}/privkey.pem > /app/ssl/${wwwDomain}.pem"`
); );
await reloadHaproxy(host);
} else { } else {
await asyncExecShell( await asyncExecShell(
`DOCKER_HOST=${host} docker run --rm --name certbot-${randomCuid} -p 9080:${randomPort} -v "coolify-letsencrypt:/etc/letsencrypt" certbot/certbot --logs-dir /etc/letsencrypt/logs certonly --standalone --preferred-challenges http --http-01-address 0.0.0.0 --http-01-port ${randomPort} -d ${domain} --expand --agree-tos --non-interactive --register-unsafely-without-email ${ `DOCKER_HOST=${host} docker run --rm --name certbot-${randomCuid} -p 9080:${randomPort} -v "coolify-letsencrypt:/etc/letsencrypt" certbot/certbot --logs-dir /etc/letsencrypt/logs certonly --standalone --preferred-challenges http --http-01-address 0.0.0.0 --http-01-port ${randomPort} -d ${domain} --expand --agree-tos --non-interactive --register-unsafely-without-email ${
@ -65,6 +66,7 @@ export async function letsEncrypt(domain, id = null, isCoolify = false) {
await asyncExecShell( await asyncExecShell(
`DOCKER_HOST=${host} docker run --rm -v "coolify-letsencrypt:/etc/letsencrypt" -v "coolify-ssl-certs:/app/ssl" alpine:latest sh -c "cat /etc/letsencrypt/live/${domain}/fullchain.pem /etc/letsencrypt/live/${domain}/privkey.pem > /app/ssl/${domain}.pem"` `DOCKER_HOST=${host} docker run --rm -v "coolify-letsencrypt:/etc/letsencrypt" -v "coolify-ssl-certs:/app/ssl" alpine:latest sh -c "cat /etc/letsencrypt/live/${domain}/fullchain.pem /etc/letsencrypt/live/${domain}/privkey.pem > /app/ssl/${domain}.pem"`
); );
await reloadHaproxy(host);
} }
} catch (error) { } catch (error) {
if (error.code !== 0) { if (error.code !== 0) {
@ -142,9 +144,11 @@ export async function generateSSLCerts() {
const isHttps = fqdn.startsWith('https://'); const isHttps = fqdn.startsWith('https://');
if (isHttps) ssls.push({ domain, id: 'coolify', isCoolify: true }); if (isHttps) ssls.push({ domain, id: 'coolify', isCoolify: true });
} }
console.log(ssls);
if (ssls.length > 0) { if (ssls.length > 0) {
for (const ssl of ssls) { for (const ssl of ssls) {
if (!dev) { if (!dev) {
console.log('Generate ssl for', ssl.domain);
await letsEncrypt(ssl.domain, ssl.id, ssl.isCoolify); await letsEncrypt(ssl.domain, ssl.id, ssl.isCoolify);
} else { } else {
console.log('Generate ssl for', ssl.domain); console.log('Generate ssl for', ssl.domain);