mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-09 23:48:36 +01:00
updates for testmode
This commit is contained in:
@@ -7,17 +7,11 @@ 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 REMOTE_PATH = '/home/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';
|
||||
const MODE = DeployHelper.getMode();
|
||||
const SKIP_BUILD = DeployHelper.getArgAt(0) == '--no-build';
|
||||
|
||||
console.log('Deploying dashboard in mode:', MODE);
|
||||
|
||||
@@ -28,20 +22,16 @@ 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`)
|
||||
if (!SKIP_BUILD) {
|
||||
console.log('Building');
|
||||
child.execSync(`cd ${LOCAL_PATH} && pnpm i && pnpm run build`)
|
||||
}
|
||||
|
||||
console.log('Creting zip file');
|
||||
console.log('Creating zip file');
|
||||
const archive = createZip(TMP_PATH + '/' + ZIP_NAME);
|
||||
archive.directory(LOCAL_PATH + '/.output', '/.output');
|
||||
archive.file(LOCAL_PATH + '/ecosystem.config.js', { name: '/ecosystem.config.js' })
|
||||
|
||||
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();
|
||||
|
||||
|
||||
@@ -5,10 +5,14 @@ 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, '../../email');
|
||||
const REMOTE_PATH = '/home/litlyx/email';
|
||||
const ZIP_NAME = 'email.zip';
|
||||
|
||||
const REMOTE_PATH = '/home/production/litlyx/email';
|
||||
const MODE = DeployHelper.getMode();
|
||||
console.log('Deploying mail-service in mode:', MODE);
|
||||
|
||||
setTimeout(() => { main(); }, 3000);
|
||||
|
||||
async function main() {
|
||||
|
||||
@@ -16,11 +20,9 @@ async function main() {
|
||||
fs.ensureDirSync(TMP_PATH);
|
||||
|
||||
console.log('Creting zip file');
|
||||
const archive = createZip(TMP_PATH + '/email.zip');
|
||||
const archive = createZip(TMP_PATH + '/' + ZIP_NAME);
|
||||
archive.directory(LOCAL_PATH + '/dist', '/dist');
|
||||
|
||||
archive.file(LOCAL_PATH + '/ecosystem.config.js', { name: '/ecosystem.config.js' })
|
||||
|
||||
archive.file(LOCAL_PATH + '/package.json', { name: '/package.json' });
|
||||
archive.file(LOCAL_PATH + '/pnpm-lock.yaml', { name: '/pnpm-lock.yaml' });
|
||||
await archive.finalize();
|
||||
@@ -42,14 +44,14 @@ async function main() {
|
||||
await scp.mkdir(REMOTE_PATH);
|
||||
|
||||
console.log('Uploading zip file');
|
||||
await scp.uploadFile(TMP_PATH + '/email.zip', REMOTE_PATH + '/email.zip');
|
||||
await scp.uploadFile(TMP_PATH + '/' + ZIP_NAME, REMOTE_PATH + '/' + ZIP_NAME);
|
||||
scp.close();
|
||||
|
||||
console.log('Cleaning local');
|
||||
fs.rmSync(TMP_PATH + '/email.zip', { force: true, recursive: true });
|
||||
fs.rmSync(TMP_PATH + '/' + ZIP_NAME, { force: true, recursive: true });
|
||||
|
||||
console.log('Extracting remote');
|
||||
await DeployHelper.execute(`cd ${REMOTE_PATH} && unzip email.zip && rm -r email.zip`);
|
||||
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`);
|
||||
@@ -58,7 +60,4 @@ async function main() {
|
||||
|
||||
ssh.dispose();
|
||||
|
||||
|
||||
}
|
||||
|
||||
main();
|
||||
@@ -2,22 +2,37 @@
|
||||
import { Client, ScpClient } from 'node-scp';
|
||||
import { NodeSSH } from 'node-ssh'
|
||||
import fs from 'fs-extra';
|
||||
import { REMOTE_HOST, IDENTITY_FILE } from '../.config'
|
||||
import { REMOTE_HOST_PRODUCTION, REMOTE_HOST_TESTMODE, IDENTITY_FILE } from '../.config'
|
||||
|
||||
export class DeployHelper {
|
||||
|
||||
private static scpClient: ScpClient;
|
||||
private static sshClient: NodeSSH;
|
||||
|
||||
static getMode() {
|
||||
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';
|
||||
return MODE;
|
||||
}
|
||||
|
||||
static getArgAt(index: number) {
|
||||
return process.argv[3 + index];
|
||||
}
|
||||
|
||||
|
||||
static async connect() {
|
||||
this.scpClient = await Client({
|
||||
host: REMOTE_HOST,
|
||||
host: this.getMode() === 'production' ? REMOTE_HOST_PRODUCTION : REMOTE_HOST_TESTMODE,
|
||||
username: 'root',
|
||||
privateKey: fs.readFileSync(IDENTITY_FILE)
|
||||
})
|
||||
this.sshClient = new NodeSSH();
|
||||
await this.sshClient.connect({
|
||||
host: REMOTE_HOST,
|
||||
host: this.getMode() === 'production' ? REMOTE_HOST_PRODUCTION : REMOTE_HOST_TESTMODE,
|
||||
username: 'root',
|
||||
privateKeyPath: IDENTITY_FILE
|
||||
});
|
||||
|
||||
@@ -8,12 +8,12 @@ export class SharedHelper {
|
||||
constructor(private localSharedPath: string) { }
|
||||
|
||||
static getSharedPath() { return path.join(__dirname, '../../shared_global'); }
|
||||
|
||||
|
||||
clear() {
|
||||
if (fs.existsSync(this.localSharedPath)) {
|
||||
fs.rmSync(this.localSharedPath, { force: true, recursive: true });
|
||||
fs.mkdirSync(this.localSharedPath);
|
||||
}
|
||||
fs.mkdirSync(this.localSharedPath);
|
||||
}
|
||||
|
||||
create(name: string) {
|
||||
|
||||
74
scripts/producer/deploy.ts
Normal file
74
scripts/producer/deploy.ts
Normal file
@@ -0,0 +1,74 @@
|
||||
|
||||
import fs from 'fs-extra';
|
||||
import path from 'path';
|
||||
import { createZip } from '../helpers/zip-helper';
|
||||
import { DeployHelper } from '../helpers/deploy-helper';
|
||||
import { REMOTE_HOST_TESTMODE } from '../.config';
|
||||
|
||||
const TMP_PATH = path.join(__dirname, '../../tmp');
|
||||
const LOCAL_PATH = path.join(__dirname, '../../producer');
|
||||
const REMOTE_PATH = '/home/litlyx/producer';
|
||||
const ZIP_NAME = 'producer.zip';
|
||||
|
||||
const MODE = DeployHelper.getMode();
|
||||
console.log('Deploying producer 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('Creting zip file');
|
||||
const archive = createZip(TMP_PATH + '/' + ZIP_NAME);
|
||||
archive.directory(LOCAL_PATH + '/dist', '/dist');
|
||||
|
||||
if (MODE === 'testmode') {
|
||||
const ecosystemContent = fs.readFileSync(LOCAL_PATH + '/ecosystem.config.js', 'utf8');
|
||||
const devContent = ecosystemContent.replace("redis://litlyx.com", `redis://${REMOTE_HOST_TESTMODE}`);
|
||||
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 + '/package.json', { name: '/package.json' });
|
||||
archive.file(LOCAL_PATH + '/pnpm-lock.yaml', { name: '/pnpm-lock.yaml' });
|
||||
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`);
|
||||
|
||||
console.log('Executing remote');
|
||||
await DeployHelper.execute(`cd ${REMOTE_PATH} && /root/.nvm/versions/node/v21.2.0/bin/pm2 start ecosystem.config.js`);
|
||||
|
||||
ssh.dispose();
|
||||
|
||||
}
|
||||
@@ -1 +1,13 @@
|
||||
|
||||
import { SharedHelper } from "../helpers/shared-helper";
|
||||
import path from "node:path";
|
||||
|
||||
const helper = new SharedHelper(path.join(__dirname, '../../producer/src/shared'))
|
||||
|
||||
helper.clear();
|
||||
|
||||
helper.create('utils');
|
||||
helper.copy('utils/requireEnv.ts');
|
||||
|
||||
helper.create('services');
|
||||
helper.copy('services/RedisStreamService.ts');
|
||||
|
||||
Reference in New Issue
Block a user