Skip to main content

GitHub Workflows support for CDK Pipelines

Project description

CDK Pipelines for GitHub Workflows

Experimental

NOTICE: this library is still not published to package managers. Stay tuned.

Deploy CDK applications through GitHub workflows.

Usage

Assuming you have a Stage called MyStage that includes CDK stacks for your app and you want to deploy it to two AWS environments (BETA_ENV and PROD_ENV):

import { ShellStep } from 'aws-cdk-lib/pipelines';
import { GithubWorkflow } from 'cdk-pipelines-github';

const app = new App();

const pipeline = new GithubWorkflow(app, 'Pipeline', {
  synth: new ShellStep('Build', {
    commands: [
      'yarn install',
      'yarn build',
    ],
  }),
  workflowPath: '.github/workflows/deploy.yml',
});

pipeline.addStage(new MyStage(this, 'Beta', { env: BETA_ENV }));
pipeline.addStage(new MyStage(this, 'Prod', { env: PROD_ENV }));

app.synth();

When you run cdk synth, a deploy.yml workflow will be created under .github/workflows in your repo. This workflow will deploy your application based on the definition of the pipeline. In this case, it will the two stages in sequence, and within each stage, it will deploy all the stacks according to their dependency order and maximum parallelism. If you app uses assets, assets will be published to the relevant destination environment.

The Pipeline class from cdk-pipelines-github is derived from the base CDK Pipelines class, so most features should be supported out of the box. See the CDK Pipelines documentation for more details.

NOTES:

  • Environments must be bootstrapped separately using cdk bootstrap. See CDK Environment Bootstrapping for details.
  • The workflow expects the GitHub repository to include secrets with AWS credentials (AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY).

Example

You can find an example usage in test/example-app.ts which includes a simple CDK app and a pipeline.

You can find a repository that uses this example here: eladb/test-app-cdkpipeline.

To run the example, clone this repository and install dependencies:

cd ~/projects # or some other playground space
git clone https://github.com/cdklabs/cdk-pipelines-github
cd cdk-pipelines-github
yarn

Now, create a new GitHub repository and clone it as well:

cd ~/projects
git clone https://github.com/myaccount/my-test-repository

You'll need to set up AWS credentials in your environment:

export AWS_ACCESS_KEY_ID=xxxx
export AWS_SECRET_ACCESS_KEY=xxxxx

Bootstrap your environments:

export CDK_NEW_BOOTSTRAP=1
npx cdk bootstrap aws://ACCOUNTID/us-east-1
npx cdk bootstrap aws://ACCOUNTID/eu-west-2

Now, run the manual-test.sh script when your working directory is the new repository:

cd ~/projects/my-test-repository
~/projects/cdk-piplines/github/test/manual-test.sh

This will produce a cdk.out directory and a .github/workflows/deploy.yml file.

Commit and push these files to your repo and you should see the deployment workflow in action. Make sure your GitHub repository has AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY secrets that can access the same account that you synthesized against.

Not supported yet

This is work in progress. The following features are still not supported:

  • Credentials and roles (document permissions required, etc)
  • Anti-tamper check for CI runs (synth should fail if CI=1 and the workflow has changed)
  • Revise Documentation

Contributing

See CONTRIBUTING for more information.

License

This project is licensed under the Apache-2.0 License.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cdk-pipelines-github-0.0.92.tar.gz (192.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cdk_pipelines_github-0.0.92-py3-none-any.whl (190.7 kB view details)

Uploaded Python 3

File details

Details for the file cdk-pipelines-github-0.0.92.tar.gz.

File metadata

  • Download URL: cdk-pipelines-github-0.0.92.tar.gz
  • Upload date:
  • Size: 192.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for cdk-pipelines-github-0.0.92.tar.gz
Algorithm Hash digest
SHA256 6e900c6a638be2d382477065be7e7463441477f900c4902b86f9b663634a07ba
MD5 8cdb06b845acc4752ea977256b2e475a
BLAKE2b-256 05c728fec59b719ec73f66765421a816acc5cbf3a10dc4cc07adc060a574855b

See more details on using hashes here.

File details

Details for the file cdk_pipelines_github-0.0.92-py3-none-any.whl.

File metadata

  • Download URL: cdk_pipelines_github-0.0.92-py3-none-any.whl
  • Upload date:
  • Size: 190.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for cdk_pipelines_github-0.0.92-py3-none-any.whl
Algorithm Hash digest
SHA256 88181cf6b4f6fdb1e11bd270c7d71c8c1bc771539cb8a7d8e35e82bbc9159eab
MD5 f28d0ca53e05effd93f1712f7131f34f
BLAKE2b-256 e234cdad173d72eebe0a2730a096d2ed38d83e88d4e1f8a561267db0fc8ee877

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page