feat: backport remote BTC node support

This commit is contained in:
Sérgio Salgado 2023-02-01 15:16:35 +00:00
parent 24473de6d5
commit 1b6ba5e6dc
15 changed files with 272 additions and 55 deletions

32
tools/migrate-env.js Normal file
View file

@ -0,0 +1,32 @@
const fs = require('fs')
const path = require('path')
const _ = require('lodash/fp')
const setEnvVariable = require('./set-env-var')
const ENV_PATH = process.env.NODE_ENV === 'production' ? path.resolve('/etc', 'lamassu', '.env') : path.resolve(__dirname, '../.env')
const BACKUP_TIMESTAMP = Date.now()
const BACKUP_PATH = `${ENV_PATH}-${BACKUP_TIMESTAMP}`
const migrateEnv = newVars => {
try {
fs.copyFileSync(ENV_PATH, BACKUP_PATH)
_.forEach(it => {
setEnvVariable(it[0], it[1], { ENV_PATH })
}, newVars)
fs.unlinkSync(BACKUP_PATH)
console.log('Environment migration successful')
} catch (e) {
// Rollback the migration and restore the backup file
if (fs.existsSync(BACKUP_PATH)) {
console.log('Rolling back the environment migration...')
fs.copyFileSync(BACKUP_PATH, ENV_PATH)
fs.unlinkSync(BACKUP_PATH)
console.log('Rollback finished')
}
console.log('Environment migration failed')
throw e
}
}
module.exports = migrateEnv