@forzalabs/remora
Version:
A powerful CLI tool for seamless data translation.
95 lines (94 loc) • 4.68 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.deploy = void 0;
const chalk_1 = __importDefault(require("chalk"));
const fs_1 = __importDefault(require("fs"));
const adm_zip_1 = __importDefault(require("adm-zip"));
const path_1 = __importDefault(require("path"));
const Constants_1 = __importDefault(require("../Constants"));
const deploy = (options) => __awaiter(void 0, void 0, void 0, function* () {
console.log(chalk_1.default.blue.bold(`🚀 Deploying to ${options.env}...`));
try {
const rootDir = './remora';
if (!fs_1.default.existsSync('./remora'))
throw new Error(chalk_1.default.red('Missing directory: ') + chalk_1.default.yellow('./remora'));
const zip = new adm_zip_1.default();
// Function to recursively add files to zip
const addDirectoryToZip = (directoryPath, zipPath = '') => {
const files = fs_1.default.readdirSync(directoryPath);
files.forEach(file => {
const fullPath = path_1.default.join(directoryPath, file);
const stat = fs_1.default.statSync(fullPath);
if (file === 'temp')
return;
if (stat.isDirectory()) {
addDirectoryToZip(fullPath, path_1.default.join(zipPath, file));
}
else {
const fileContent = fs_1.default.readFileSync(fullPath);
zip.addFile(path_1.default.join(zipPath, file), fileContent);
}
});
};
addDirectoryToZip(rootDir);
// Write the zip file to a temporary location
const tempZipPath = path_1.default.join(process.cwd(), 'temp_deployment.zip');
zip.writeZipPromise(tempZipPath)
.then(() => __awaiter(void 0, void 0, void 0, function* () {
try {
// Read the zip file as a buffer
const zipBuffer = fs_1.default.readFileSync(tempZipPath);
const host = process.env.REMORA_WORKER_HOST;
const version = Constants_1.default.lambdaVersion;
const workerAPI = `${host}/cli/v${version}/uploaddeployment`;
const formData = new FormData();
const blob = new Blob([zipBuffer], { type: 'application/zip' });
formData.append('remora_config', blob, 'temp_deployment.zip'); // Updated to match the actual file name
const apiKey = process.env.REMORA_LICENCE_KEY;
if (!apiKey)
throw new Error('REMORA_LICENCE_KEY environment variable is not set');
const response = yield fetch(workerAPI, {
method: 'POST',
headers: {
Authorization: `Bearer ${apiKey}`
},
body: formData
});
if (!response.ok) {
throw new Error(`Upload failed with status ${response.status}: ${yield response.text()}`);
}
console.log(chalk_1.default.green('✅ Deployment package uploaded successfully'));
}
finally {
// Clean up the temporary zip file
fs_1.default.unlinkSync(tempZipPath);
}
}))
.catch(error => {
throw error;
});
// TODO
// Check if exist remora worker
// if not pull remora image and doker compose up
// compile
// upload configuration into rw
// create consumers tath require creation ( view, materialized view )
}
catch (error) {
console.error(chalk_1.default.red('❌ Deployment error:'), error instanceof Error ? error.message : String(error));
process.exit(1);
}
});
exports.deploy = deploy;