diff --git a/apps/api/prisma/seed.js b/apps/api/prisma/seed.js index e335607ac..3e5dab103 100644 --- a/apps/api/prisma/seed.js +++ b/apps/api/prisma/seed.js @@ -94,11 +94,20 @@ async function main() { } } async function reEncryptSecrets() { + const { execaCommand } = await import('execa'); + await execaCommand('env | grep COOLIFY > .env', { shell: true }); const secretOld = process.env['COOLIFY_SECRET_KEY']; - const secretNew = process.env['COOLIFY_SECRET_KEY_BETTER']; + let secretNew = process.env['COOLIFY_SECRET_KEY_BETTER']; if (!secretNew) { - console.log('no new secret found'); - return; + console.log('no new secret found, generating new one'); + const { stdout: newKey } = await execaCommand( + 'openssl rand -base64 1024 | sha256sum | base64 | head -c 32', + { shell: true } + ); + await execaCommand('echo "COOLIFY_SECRET_KEY_BETTER=' + newKey + '" >> .env ', { shell: true }); + await execaCommand(`sed -i '/COOLIFY_SECRET_KEY=/d' .env`, { shell: true }); + await execaCommand(`echo "COOLIFY_SECRET_KEY=${newKey}" >> .env`, { shell: true }); + secretNew = newKey; } if (secretOld !== secretNew) { console.log('secrets are different, so re-encrypting'); @@ -113,6 +122,8 @@ async function reEncryptSecrets() { }); } } + } else { + console.log('secrets are the same, so no need to re-encrypt'); } } main() diff --git a/apps/api/src/routes/api/v1/handlers.ts b/apps/api/src/routes/api/v1/handlers.ts index 69c73b940..a9525b74f 100644 --- a/apps/api/src/routes/api/v1/handlers.ts +++ b/apps/api/src/routes/api/v1/handlers.ts @@ -163,7 +163,7 @@ export async function update(request: FastifyRequest) { await executeCommand({ command: `docker pull ${image}` }); } - await executeCommand({ shell: true, command: `env | grep COOLIFY > .env` }); + await executeCommand({ shell: true, command: `ls .env || env | grep COOLIFY > .env` }); await executeCommand({ command: `sed -i '/COOLIFY_AUTO_UPDATE=/cCOOLIFY_AUTO_UPDATE=${isAutoUpdateEnabled}' .env` });