Code Monkey home page Code Monkey logo

aws-cdk-staging-pipeline's Introduction

NPM version Release

tested cdk versions

aws-cdk-staging-pipeline

An AWS CDK Construct with utilizing the CDK Pipeline and with focus on abstraction with use of higher order functions to hide more details of the staging pipeline.

If you successfully managed to set this staging pipeline up, in future only commits to the choosen remote in branch will be sufficiently to make changes to your staging stacks and to the pipeline itself as the pipeline is self-mutating.

It leverages all the cool stuff from the CDK Pipeline. As a matter of fact the core component is the CDK Pipeline.

As well this construct leverages the Projen as its best like the library is created with Projen and I utilise the default commands like yarn deploy, yarn build and so one.

Unlucky this library can't be translated to PyPi / Python as is uses higher order functions and the translation with JSII for those are not supported for. Hopefully that will be supported soon.

Special Features

  • CustomStacks automatically getting some build information like Stage or CommitId attached. Check src/custom-stack.ts for more details.

Usage

Your stack you want to be managed by the staging pipeline needs to extend from the CustomStack interface.

Look at the example. Please be aware that the staging pipeline is atm only designed for managing one stack. But it should be possible to manage multiple stack.

As well you might run into issue using different accounts. Than check you cdk bootstrap. Anyway as this is experimental there are probably still issues in the library. ATM my different stages map to different regions in the same account. A better practice would be do have multiple Accounts. So for each stage a dedicated account. But ATM I don't want to struggle with multiple accounts yet.

I am excited to your feedback and would be happy to see PRs. Enjoy.

Example

Taken from https://github.com/mmuller88/aws-api-gw-petstore-example

Import needed dependencies:

cdkDependencies: [
  '@aws-cdk/aws-codepipeline',
  '@aws-cdk/aws-codepipeline-actions',
  '@aws-cdk/pipelines',
];
import * as core from '@aws-cdk/core';
import { PipelineStack } from 'aws-cdk-staging-pipeline';
// import { PipelineStack } from '../../aws-cdk-staging-pipeline/src/index';
import { ApiGwStack } from './apigw-stack';

const app = new core.App();

new PipelineStack(app, 'petstore-pipeline', {
  stackName: 'petstore-pipeline',
  // Account and region where the pipeline will be build
  env: {
    account: 'XYZ',
    region: 'eu-central-1',
  },
  // Staging Accounts e.g. dev qa prod
  stageAccounts: [
    {
      account: {
        id: 'XYZ',
        region: 'eu-central-1',
      },
      stage: 'dev',
    },
    {
      account: {
        id: 'XYZ',
        region: 'us-east-1',
      },
      stage: 'prod',
    },
  ],
  branch: 'master',
  repositoryName: 'aws-api-gw-petstore-example',
  customStack: (scope, stageAccount) => {
    const apiGwStack = new ApiGwStack(
      scope,
      `petstore-stack-${stageAccount.stage}`,
      {
        stackName: `petstore-stack-${stageAccount.stage}`,
        stage: stageAccount.stage,
      },
    );
    return apiGwStack;
  },
  manualApprovals: (_) => true,
  testCommands: (stageAccount) => [
    `echo "${stageAccount.stage} stage"`,
    `echo ${stageAccount.account.id} id + ${stageAccount.account.region} region`,
  ],
  gitHub: {
    owner: 'mmuller88',
    oauthToken: core.SecretValue.secretsManager('alfcdk', {
      jsonField: 'muller88-github-token',
    }),
  },
});

app.synth();

Planed Features / Ideas

  • making GitLab and AWS CodeCommit repo available too
  • conditional runs / triggering of the pipeline would be cool. Maybe only if it is a versions commit
  • having a way to manage multiple stacks with might dedicated versions / dashboard features would be cool
  • ...

Troubleshooting

  • I had some issues with the bootstrap stack in the stage regions. So I just recreated them
  • ...

Thanks To

  • The CDK Community cdk-dev.slack.com
  • Projen project and the community around it

aws-cdk-staging-pipeline's People

Contributors

mmuller88 avatar dependabot[bot] avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.