0.0.21 • Published 12 months ago

@m-yamagishi/aws-cdk-appdp v0.0.21

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
12 months ago

AWS CDK APPDP

cdk-constructs: Experimental

View on Construct Hub

The APIs in this module are experimental and under active development.

AWS CDK Typical application deployment for AWS Fargate, alternative to AWS CDK Pipelines.

This repository structure refers to cdk-pipelines-github.

Usage

Source

declare const githubOwner: string;
declare const githubRepo: string;
declare const targetBranch: string;

const source = AppDpSource.fromGitHub({
  owner: githubOwner,
  repo: githubRepo,
  branch: targetBranch,
  oauthToken: SecretValue.secretsManager('github-token'),
});

// FUTURE: fromCodeStarConnection or other repositories

Container Build Definitions

const defaultBuildDefinition = {
  directory: '../../',
  buildArgs: {
    VERSION: 'v2024.09.01.01',
    ENV: 'production',
  },
};
const appBuildDefinition = new AppDpBuildDefinition(this, 'App', {
  ...defaultBuildDefinition,
  ...{
    target: 'app',
  },
});
const adminBuildDefinition = new AppDpBuildDefinition(this, 'Admin', {
  ...defaultBuildDefinition,
  ...{
    target: 'admin',
  },
});
const cliBuildDefinition = new AppDpBuildDefinition(this, 'CLI', {
  ...defaultBuildDefinition,
  ...{
    target: 'cli',
  },
});

Cluster Configurations

declare const vpc: ec2.Vpc;

const cluster = new AppDpCluster(this, 'AppDpCluster', {
  vpc,
});
const appTaskDefinition = new ecs.FargateTaskDefinition(this, 'AppTask', {
  cpu: '4096',
  memoryLimitMiB: '8192',
  executionRole,
  taskRole,
});
appTaskDefinition.addContainer('app', {
  image: ecs.ContainerImage.fromEcrRepository(appBuildDefinition.repository, source.commitId),
  portMappings: [
    {
      containerPort: 80,
    },
  ],
});
const service = cluster.addHttpService('app', {
  taskDefinition: appTaskDefinition,
});
// You can add auto-scaling config to FargateService
const scaling = service.autoScaleTaskCount({
  maxCapacity: 100,
});
scaling.scaleOnCpuUtilization('CpuScaling', {
  targetUtilizationPercent: 50,
});
const adminTaskDefinition = new ecs.FargateTaskDefinition(this, 'AdminTask', {
  cpu: '256',
  memoryLimitMiB: '512',
  executionRole,
  taskRole,
});
adminTaskDefinition.addContainer('admin', {
  image: ecs.ContainerImage.fromEcrRepository(adminBuildDefinition.repository, source.commitId),
  portMappings: [
    {
      containerPort: 80,
    },
  ],
});
cluster.addHttpService('admin', {
  taskDefinition: adminTaskDefinition,
});
const cliTaskDefinition = new ecs.FargateTaskDefinition(this, 'CLITask', {
  cpu: '256',
  memoryLimitMiB: '512',
  executionRole,
  taskRole,
});
cliTaskDefinition.addContainer('cli', {
  image: ecs.ContainerImage.fromEcrRepository(cliBuildDefinition.repository, source.commitId),
});
cluster.addNonHttpService('cli', {
  taskDefinition: cliTaskDefinition,
});

Pipeline

const pipeline = new AppDpPipeline(this, 'AppDpPipeline', {
  source,
  buildDefinitions: [
    appBuildDefinition,
    adminBuildDefinition,
    cliBuildDefinition,
  ],
  cluster,
  needManualApprove: true, // default: false
});

References

Contributing

See CONTRIBUTING for more information.

License

This project is licensed under the Apache-2.0 License.

0.0.21

12 months ago

0.0.20

12 months ago

0.0.19

12 months ago

0.0.17

12 months ago

0.0.18

12 months ago

0.0.16

12 months ago

0.0.15

12 months ago

0.0.14

12 months ago

0.0.13

12 months ago

0.0.12

12 months ago

0.0.11

12 months ago

0.0.10

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago

0.0.0

1 year ago