Initial commit: Spicy CDK automation framework
Jenkins shared library and CDK constructs for AWS infrastructure. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
61
resources/bin/spicy-cdk.ts
Normal file
61
resources/bin/spicy-cdk.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import * as cdk from 'aws-cdk-lib/core';
|
||||
import { SpicyAlbStack, SpicyEcsClusterStack, SpicyEcsServiceStack, SpicyVpcStack } from '../lib/stacks';
|
||||
|
||||
const app = new cdk.App();
|
||||
|
||||
// Get the stack type from context (default to vpc for backwards compatibility)
|
||||
const stackType = app.node.tryGetContext('stackType');
|
||||
const stackName = app.node.tryGetContext('stackName');
|
||||
|
||||
// Environment configuration from context or environment variables
|
||||
const env: cdk.Environment = {
|
||||
account: app.node.tryGetContext('account') ?? process.env.CDK_DEFAULT_ACCOUNT,
|
||||
region: app.node.tryGetContext('region') ?? process.env.CDK_DEFAULT_REGION,
|
||||
};
|
||||
|
||||
// Create stacks based on stackType
|
||||
// If no stackType is provided, create an empty stack to satisfy CDK's requirement (e.g., for bootstrap)
|
||||
if (stackType) {
|
||||
switch (stackType) {
|
||||
case 'vpc':
|
||||
// Create VPC stack from context
|
||||
// Usage: npx cdk deploy -c stackType=vpc -c stackName=spicy-vpc -c ownerTag=SpicyTeam ...
|
||||
SpicyVpcStack.fromContext(app, stackName ?? 'SpicyVpcStack', { env });
|
||||
break;
|
||||
|
||||
case 'ecs-cluster':
|
||||
// Create ECS Cluster stack from context
|
||||
// Usage: npx cdk deploy -c stackType=ecs-cluster -c stackName=spicy-ecs -c vpcId=vpc-xxx ...
|
||||
SpicyEcsClusterStack.fromContext(app, stackName ?? 'SpicyEcsClusterStack', { env });
|
||||
break;
|
||||
|
||||
case 'ecs-service':
|
||||
// Create ECS Service stack from context
|
||||
// Usage: npx cdk deploy -c stackType=ecs-service -c stackName=my-service -c clusterName=spicy-ecs ...
|
||||
SpicyEcsServiceStack.fromContext(app, stackName ?? 'SpicyEcsServiceStack', { env });
|
||||
break;
|
||||
|
||||
case 'alb':
|
||||
// Create persistent ALB stack from context
|
||||
// Usage: npx cdk deploy -c stackType=alb -c stackName=my-alb -c vpcId=vpc-xxx ...
|
||||
SpicyAlbStack.fromContext(app, stackName ?? 'SpicyAlbStack', { env });
|
||||
break;
|
||||
|
||||
default:
|
||||
console.error(`Unknown stack type: ${stackType}`);
|
||||
console.error('Valid stack types: vpc, ecs-cluster, ecs-service, alb');
|
||||
process.exit(1);
|
||||
}
|
||||
} else {
|
||||
// Create an empty placeholder stack when no stackType is provided
|
||||
// This allows bootstrap and other CDK commands to work without requiring a stack type
|
||||
// This stack is never deployed - it's only used to satisfy CDK's requirement for at least one stack
|
||||
new cdk.Stack(app, 'PlaceholderStack', {
|
||||
stackName: 'spicy-cdk-placeholder',
|
||||
env,
|
||||
});
|
||||
}
|
||||
|
||||
app.synth();
|
||||
Reference in New Issue
Block a user