update deploy scripts + dashboard ecosystem

This commit is contained in:
Emily
2025-01-28 15:29:20 +01:00
parent 19b7c7664a
commit 39b8dd84f1
4 changed files with 85 additions and 1 deletions

View File

@@ -12,7 +12,8 @@
"docker-build": "docker build -t litlyx-dashboard -f Dockerfile ../",
"docker-inspect": "docker run -it litlyx-dashboard sh",
"docker-run": "docker run -p 3000:3000 litlyx-dashboard",
"workspace:shared": "node ../scripts/dashboard/shared.js"
"workspace:shared": "ts-node ../scripts/dashboard/shared.ts",
"workspace:deploy": "ts-node ../scripts/dashboard/deploy.ts --testmode"
},
"dependencies": {
"@nuxtjs/tailwindcss": "^6.12.0",

View File

@@ -0,0 +1,82 @@
import fs from 'fs-extra';
import path from 'path';
import child from 'child_process';
import { createZip } from '../helpers/zip-helper';
import { DeployHelper } from '../helpers/deploy-helper';
const TMP_PATH = path.join(__dirname, '../../tmp');
const LOCAL_PATH = path.join(__dirname, '../../dashboard');
const REMOTE_PATH = '/home/testmode/litlyx/dashboard';
const ZIP_NAME = 'dashboard.zip';
const TESTMODE_PORT = "4010";
const argvMode = process.argv[2]
if (argvMode != '--production' && argvMode != '--testmode') {
console.error('use --production or --testmode');
process.exit(1);
}
const MODE = argvMode === '--production' ? 'production' : 'testmode';
console.log('Deploying dashboard in mode:', MODE);
setTimeout(() => { main(); }, 3000);
async function main() {
if (fs.existsSync(TMP_PATH)) fs.rmSync(TMP_PATH, { force: true, recursive: true });
fs.ensureDirSync(TMP_PATH);
// console.log('Building');
// child.execSync(`cd ${LOCAL_PATH} && pnpm i && pnpm run build`)
console.log('Creting zip file');
const archive = createZip(TMP_PATH + '/' + ZIP_NAME);
archive.directory(LOCAL_PATH + '/.output', '/.output');
if (MODE === 'testmode') {
const ecosystemContent = fs.readFileSync(LOCAL_PATH + '/ecosystem.config.js', 'utf8');
const devContent = ecosystemContent.replace(/name: '(.*?)'/, "name: 'test-$1'").replace(/3010/, TESTMODE_PORT);
archive.append(Buffer.from(devContent), { name: '/ecosystem.config.js' });
} else {
archive.file(LOCAL_PATH + '/ecosystem.config.js', { name: '/ecosystem.config.js' })
}
// archive.file(LOCAL_PATH + '/.env', { name: '/.env' });
await archive.finalize();
await DeployHelper.connect();
const { scp, ssh } = DeployHelper.instances();
console.log('Creating remote structure');
console.log('Check existing');
const remoteExist = await scp.exists(REMOTE_PATH);
console.log('Exist', remoteExist);
if (remoteExist) {
console.log('Deleting');
await DeployHelper.execute(`rm -r ${REMOTE_PATH}`);
}
console.log('Creating folder');
await scp.mkdir(REMOTE_PATH);
console.log('Uploading zip file');
await scp.uploadFile(TMP_PATH + '/' + ZIP_NAME, REMOTE_PATH + '/' + ZIP_NAME);
scp.close();
console.log('Cleaning local');
fs.rmSync(TMP_PATH + '/' + ZIP_NAME, { force: true, recursive: true });
console.log('Extracting remote');
await DeployHelper.execute(`cd ${REMOTE_PATH} && unzip ${ZIP_NAME} && rm -r ${ZIP_NAME}`);
// console.log('Installing remote');
// await DeployHelper.execute(`cd ${REMOTE_PATH} && /root/.nvm/versions/node/v21.2.0/bin/pnpm i`);
// await DeployHelper.execute(`cd ${REMOTE_PATH} && /root/.nvm/versions/node/v21.2.0/bin/pm2 start ecosystem.config.js`);
ssh.dispose();
}

View File

@@ -15,6 +15,7 @@ async function main() {
if (fs.existsSync(TMP_PATH)) fs.rmSync(TMP_PATH, { force: true, recursive: true });
fs.ensureDirSync(TMP_PATH);
console.log('Creting zip file');
const archive = createZip(TMP_PATH + '/email.zip');
archive.directory(LOCAL_PATH + '/dist', '/dist');