UNPKG

@k1ssh/qbot

Version:

QBot SDK is a set of APIs for creating and managing microservices, and Kubernetes deployments. This is the core package for QBot AI.

79 lines (78 loc) 2.75 kB
import fs from 'fs/promises'; import path from 'path'; import os from 'os'; import { ProjectUtils } from './ProjectUtils.js'; import { log } from './Util.js'; export const BASE_DIRS = ['envs', 'charts', 'config', 'templates', 'snapshots']; // for kustomize, we use the following environments export const ENV_DIRS = [ 'base', 'dev', 'prod', 'staging', 'test', 'qa', 'uat', 'sandbox', ]; export const QBOT_DIR = os.homedir() + '/.la-rebelion/k1s/qbot'; export const initProject = initProjectTask; // @todo - refactor to create Task Class extended by these functions - Task as actions and it's dependencies async function initProjectTask(projectName) { const projectDir = path.resolve(QBOT_DIR, projectName); try { await ProjectUtils.validateProjectDirectories(projectName); } catch (error) { log(`Error creating project directory ${projectDir}:`, error); throw error; } log(`Project ${projectName} created in ${projectDir}`); // Create a sample config file const configPath = path.resolve(projectDir, 'config', 'config.json'); try { const config = { projectName, environment: 'dev', namespace: 'default', }; await fs.writeFile(configPath, JSON.stringify(config, null, 2)); log(`Config file created at ${configPath}`); } catch (error) { log(`Error creating config file ${configPath}:`, error); process.exit(1); } // git init to trace changes and allow QBot to manage different versions of the project, rollback, etc. await ProjectUtils.gitInit(projectName); // @todo suggest next steps like: add a remote git repository, clone a project, deploy to a cluster, etc. } export async function cloneProject(projectName, repositoryUrl, isChart) { if (!repositoryUrl) { repositoryUrl = 'git@github.com:la-rebelion/qbot-base-template.git'; } let cloneDir = path.resolve(QBOT_DIR, projectName, 'envs', 'base'); if (isChart) cloneDir = path.resolve(QBOT_DIR, projectName, 'charts'); ProjectUtils.gitClone(projectName, repositoryUrl, cloneDir); } export async function addEnvironment(projectName, environmentName) { // @todo // update kustomization.yaml - resources } export async function addChart(projectName, chartName) { // @todo // update kustomization.yaml - helmCharts } export async function snapshotProject(projectName, snapshotName) { // @todo } export async function diffProject(projectName, snapshotName, offline) { // @todo } export async function rollbackProject(projectName, snapshotName) { // @todo } export async function deployProject(projectName, environment, release) { // @todo }