@gati-framework/cli
Version:
CLI tool for Gati framework - create, develop, build and deploy cloud-native applications
143 lines • 5.47 kB
JavaScript
/**
* @module plugins/aws
* @description AWS cloud provider plugin for Gati framework
*
* This plugin enables deployment to AWS EKS with:
* - EKS cluster provisioning
* - VPC and networking setup
* - Application Load Balancer configuration
* - IAM roles and policies
* - Secrets Manager integration
*/
export * from './types';
export * from './vpc';
export * from './eks';
export * from './secrets';
import { generateVPCTemplate, validateVPCConfig } from './vpc';
import { generateEKSClusterTemplate, generateKubeconfig, validateEKSConfig } from './eks';
import { generateSecretsTemplate, validateSecretsConfig } from './secrets';
/**
* AWS EKS Deployer
*/
export class AWSEKSDeployer {
config;
constructor(config) {
this.config = config;
}
/**
* Validate the entire configuration
*/
validate() {
const errors = [];
// Validate VPC
const vpcValidation = validateVPCConfig(this.config.vpc);
if (!vpcValidation.valid) {
errors.push(...vpcValidation.errors.map((e) => `VPC: ${e}`));
}
// Validate EKS
const eksValidation = validateEKSConfig(this.config);
if (!eksValidation.valid) {
errors.push(...eksValidation.errors.map((e) => `EKS: ${e}`));
}
// Validate secrets if configured
if (this.config.secrets?.enabled) {
const secretsValidation = validateSecretsConfig(this.config.secrets);
if (!secretsValidation.valid) {
errors.push(...secretsValidation.errors.map((e) => `Secrets: ${e}`));
}
}
return {
valid: errors.length === 0,
errors,
};
}
/**
* Generate all CloudFormation templates
*/
generateTemplates() {
return {
vpc: generateVPCTemplate(this.config.vpc, this.config.clusterName),
cluster: generateEKSClusterTemplate(this.config),
secrets: this.config.secrets?.enabled
? generateSecretsTemplate(this.config.clusterName, this.config.secrets)
: undefined,
};
}
/**
* Deploy to AWS (placeholder - would use AWS SDK)
*/
async deploy(options) {
// Validate configuration
const validation = this.validate();
if (!validation.valid) {
throw new Error(`Configuration validation failed:\n${validation.errors.join('\n')}`);
}
if (options?.dryRun) {
// eslint-disable-next-line no-console
console.log('Dry run - templates generated successfully');
const templates = this.generateTemplates();
// eslint-disable-next-line no-console
console.log('VPC template length:', templates.vpc.length);
// eslint-disable-next-line no-console
console.log('Cluster template length:', templates.cluster.length);
if (templates.secrets) {
// eslint-disable-next-line no-console
console.log('Secrets template length:', templates.secrets.length);
}
}
// In production, this would:
// 1. Create CloudFormation stacks for VPC, EKS, Secrets
// 2. Wait for stacks to complete
// 3. Retrieve cluster endpoint and certificate
// 4. Generate kubeconfig
// 5. Return deployment result
// Simulate async operation
await new Promise((resolve) => setTimeout(resolve, 0));
// Mock result for now
const mockEndpoint = `https://${this.config.clusterName}.eks.${this.config.region}.amazonaws.com`;
const mockCertificate = 'LS0tLS1CRUdJTi...'; // Base64 encoded cert
return {
endpoint: mockEndpoint,
clusterArn: `arn:aws:eks:${this.config.region}:123456789012:cluster/${this.config.clusterName}`,
kubeconfig: generateKubeconfig(this.config.clusterName, mockEndpoint, mockCertificate, this.config.region),
resources: {
vpcId: 'vpc-0123456789abcdef0',
subnetIds: ['subnet-abc123', 'subnet-def456'],
securityGroupIds: ['sg-0123456789abcdef0'],
nodeGroupArns: this.config.nodeGroups.map((ng) => `arn:aws:eks:${this.config.region}:123456789012:nodegroup/${this.config.clusterName}/${ng.name}/abcdef`),
},
};
}
/**
* Delete cluster and all resources (placeholder)
*/
async destroy(options) {
if (options?.dryRun) {
// eslint-disable-next-line no-console
console.log(`Dry run - would destroy cluster: ${this.config.clusterName}`);
return;
}
// In production, this would:
// 1. Delete all CloudFormation stacks in reverse order
// 2. Wait for deletion to complete
// 3. Clean up any remaining resources
// Simulate async operation
await new Promise((resolve) => setTimeout(resolve, 0));
// eslint-disable-next-line no-console
console.log(`Cluster ${this.config.clusterName} would be destroyed`);
}
}
/**
* Create a new AWS EKS deployer instance
*/
export function createAWSDeployer(config) {
return new AWSEKSDeployer(config);
}
/**
* Quick deploy function for simple use cases
*/
export async function deployToAWS(config, options) {
const deployer = createAWSDeployer(config);
return deployer.deploy(options);
}
//# sourceMappingURL=index.js.map