This commit is contained in:
Andras Bacsai
2023-07-15 09:50:29 +02:00
parent 9ebfc6646e
commit 1bba747ce5
2 changed files with 15 additions and 4 deletions

View File

@@ -94,11 +94,20 @@ async function main() {
} }
} }
async function reEncryptSecrets() { async function reEncryptSecrets() {
const { execaCommand } = await import('execa');
await execaCommand('env | grep COOLIFY > .env', { shell: true });
const secretOld = process.env['COOLIFY_SECRET_KEY']; 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) { if (!secretNew) {
console.log('no new secret found'); console.log('no new secret found, generating new one');
return; 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) { if (secretOld !== secretNew) {
console.log('secrets are different, so re-encrypting'); 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() main()

View File

@@ -163,7 +163,7 @@ export async function update(request: FastifyRequest<Update>) {
await executeCommand({ command: `docker pull ${image}` }); 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({ await executeCommand({
command: `sed -i '/COOLIFY_AUTO_UPDATE=/cCOOLIFY_AUTO_UPDATE=${isAutoUpdateEnabled}' .env` command: `sed -i '/COOLIFY_AUTO_UPDATE=/cCOOLIFY_AUTO_UPDATE=${isAutoUpdateEnabled}' .env`
}); });