fix: ssl certificate distribution
This commit is contained in:
parent
6eca7d948e
commit
011ea9659e
@ -1,7 +1,7 @@
|
|||||||
import { parentPort } from 'node:worker_threads';
|
import { parentPort } from 'node:worker_threads';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { compareVersions } from 'compare-versions';
|
import { compareVersions } from 'compare-versions';
|
||||||
import { asyncExecShell, cleanupDockerStorage, executeDockerCmd, isDev, prisma, startTraefikTCPProxy, generateDatabaseConfiguration, startTraefikProxy, listSettings, version, createRemoteEngineConfiguration, decrypt } from '../lib/common';
|
import { asyncExecShell, cleanupDockerStorage, executeDockerCmd, isDev, prisma, startTraefikTCPProxy, generateDatabaseConfiguration, startTraefikProxy, listSettings, version, createRemoteEngineConfiguration, decrypt, executeSSHCmd } from '../lib/common';
|
||||||
import { checkContainer } from '../lib/docker';
|
import { checkContainer } from '../lib/docker';
|
||||||
import fs from 'fs/promises'
|
import fs from 'fs/promises'
|
||||||
async function autoUpdater() {
|
async function autoUpdater() {
|
||||||
@ -56,16 +56,32 @@ async function checkFluentBit() {
|
|||||||
async function copySSLCertificates() {
|
async function copySSLCertificates() {
|
||||||
try {
|
try {
|
||||||
const certificates = await prisma.certificate.findMany({ include: { team: true } })
|
const certificates = await prisma.certificate.findMany({ include: { team: true } })
|
||||||
const teamIds = certificates.map(c => c.team.map(t => t.id)).flat()
|
const teamIds = certificates.map(c => c.teamId)
|
||||||
const destinations = await prisma.destinationDocker.findMany({ where: { isCoolifyProxyUsed: true, teams: { some: { id: { in: teamIds } } } } })
|
const destinations = await prisma.destinationDocker.findMany({ where: { isCoolifyProxyUsed: true, teams: { some: { id: { in: [...teamIds] } } } } })
|
||||||
for (const destination of destinations) {
|
for (const destination of destinations) {
|
||||||
if (destination.remoteEngine) {
|
if (destination.remoteEngine) {
|
||||||
|
const { id: dockerId, remoteIpAddress, remoteVerified } = destination
|
||||||
|
if (!remoteVerified) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
// TODO: copy certificates to remote engine
|
// TODO: copy certificates to remote engine
|
||||||
|
for (const certificate of certificates) {
|
||||||
|
const { id, key, cert } = certificate
|
||||||
|
const decryptedKey = decrypt(key)
|
||||||
|
await fs.writeFile(`/tmp/${id}-key.pem`, decryptedKey)
|
||||||
|
await fs.writeFile(`/tmp/${id}-cert.pem`, cert)
|
||||||
|
await asyncExecShell(`scp /tmp/${id}-cert.pem /tmp/${id}-key.pem ${remoteIpAddress}:/tmp/`)
|
||||||
|
await fs.rm(`/tmp/${id}-key.pem`)
|
||||||
|
await fs.rm(`/tmp/${id}-cert.pem`)
|
||||||
|
await executeSSHCmd({ dockerId, command: `docker exec coolify-proxy sh -c 'test -d /etc/traefik/acme/custom/ || mkdir -p /etc/traefik/acme/custom/'` })
|
||||||
|
await executeSSHCmd({ dockerId, command: `docker cp /tmp/${id}-key.pem coolify-proxy:/etc/traefik/acme/custom/ && rm /tmp/${id}-key.pem` })
|
||||||
|
await executeSSHCmd({ dockerId, command: `docker cp /tmp/${id}-cert.pem coolify-proxy:/etc/traefik/acme/custom/ && rm /tmp/${id}-cert.pem` })
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
for (const certificate of certificates) {
|
for (const certificate of certificates) {
|
||||||
const { id, key, cert } = certificate
|
const { id, key, cert } = certificate
|
||||||
const decryptedKey = decrypt(key)
|
const decryptedKey = decrypt(key)
|
||||||
await asyncExecShell(`docker exec coolify-proxy sh -c 'mkdir -p /etc/traefik/acme/custom/'`)
|
await asyncExecShell(`docker exec coolify-proxy sh -c 'test -d /etc/traefik/acme/custom/ || mkdir -p /etc/traefik/acme/custom/'`)
|
||||||
await fs.writeFile(`/tmp/${id}-key.pem`, decryptedKey)
|
await fs.writeFile(`/tmp/${id}-key.pem`, decryptedKey)
|
||||||
await fs.writeFile(`/tmp/${id}-cert.pem`, cert)
|
await fs.writeFile(`/tmp/${id}-cert.pem`, cert)
|
||||||
await asyncExecShell(`docker cp /tmp/${id}-key.pem coolify-proxy:/etc/traefik/acme/custom/`)
|
await asyncExecShell(`docker cp /tmp/${id}-key.pem coolify-proxy:/etc/traefik/acme/custom/`)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user