Skip to content

Powerful DSL to easily create and manage AWS CodeBuild projects

License

Notifications You must be signed in to change notification settings

boltops-tools/cody

Repository files navigation

Cody

Build Status Gem Version

BoltOps Badge

Please watch/star this repo to help grow and support the project.

Cody is an AWS CodeBuild Management Tool. Cody lets you create AWS CodeBuild projects with a beautiful DSL. The documentation site is at: cody.run

Quick Start

cody init
cody deploy
cody start
cody logs

Private Repo

IMPORTANT: Before deploying, if you are using a private repo, use aws codebuild import-source-credentials to add credentials so that codebuild can clone down the repo. Refer to the CodeBuilld Github Oauth for more info.

Usage

  1. init: generate starter .cody files.
  2. deploy: deploy the CodeBuild project on AWS.
  3. start: kick off a CodeBuild project run.

Init and Structure

First, run cody init to generate a starter .cody folder structure.

$ tree .cody
.cody
├── buildspec.yml
├── project.rb
└── role.rb
File Description
buildspec.yml The build commands to run. Here are the buildspec.yml syntax docs.
project.rb The codebuild project written as a DSL. Here are the Project DSL docs
role.rb The IAM role associated with the codebuild project written as a DSL. Here are the IAM Role DSL docs

Deploy

Adjust the files in .cody to fit your needs. When you're ready, deploy the CodeBuild project with:

cody deploy PROJECT_NAME

More examples:

cody deploy # infers the CodeBuild project name from the parent folder
cody deploy PROJECT_NAME # explicitly specify project name

It is useful to just see the generated CloudFormation template with --noop mode:

cody deploy --noop # see generated CloudFormation template

For more help:

cody deploy -h

Start

When you are ready to start a codebuild project run, you can use codebuild start. Examples:

cody start # infers the name from the parent folder
cody start PROJECT_NAME # looks up project via CodeBuild project name

The cody start command understands multiple identifiers. It will look up the codebuild project either via CloudFormation or the CodeBuild project name.

The start command continuously polls the CodeBuild project and prints out the logs until the build completes. To disable this, use the --no-wait option.

cody start PROJECT_NAME --no-wait

The logs from the Phase Details and CloudWatch Logs are both displayed. Because they come from 2 different sources, the logs can interlace.

Project DSL

The tool provides a DSL to create a codebuild project. Here's an example.

.cody/project.rb:

# name("demo") # recommended to leave unset and use the conventional name that cody sets
github_url("https://github.com/tongueroo/demo-ufo")
linux_image("aws/codebuild/amazonlinux2-x86_64-standard:2.0")
environment_variables(
  UFO_ENV: "development",
  API_KEY: "ssm:/codebuild/demo/api_key" # ssm param example
)

Here's a list of some of the convenience shorthand DSL methods:

  • github_url(url)
  • github_source(options={})
  • linux_image(name)
  • linux_environment(options={})
  • environment_variables(vars)
  • local_cache(enable=true)

Please refer to lib/codebuild/dsl/project.rb for the full list.

More slightly more control, you may be interested in the github_source and linux_environment methods. For even more control, see DSL docs.

IAM Role DSL

Cody can create the IAM service role associated with the codebuild project. Here's an example:

.cody/role.rb:

iam_policy("logs", "ssm")

For more control, here's a longer form:

iam_policy(
  action: [
    "logs:CreateLogGroup",
    "logs:CreateLogStream",
    "logs:PutLogEvents",
    "ssm:*",
  ],
  effect: "Allow",
  resource: "*"
)

You can also create managed iam policy.

managed_iam_policy("AmazonS3ReadOnlyAccess")

Schedule Support

.cody/schedule.rb:

rate "1 day"

Full DSL

The convenience DSL methods shown above are short and clean. They merely wrap a DSL that map to the properties of CloudFormation resources like AWS::CodeBuild::Project and AWS::IAM::Role. Refer the DSL docs for more info.

Type Option

By default, cody looks up files in the .cody folder. You can affect the behavior of the Type logic with the --Type option. More info Type docs.

Installation

Add this line to your application's Gemfile:

gem "cody"

And then execute:

bundle

Or install it yourself as:

gem install cody

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am "Add some feature")
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

About

Powerful DSL to easily create and manage AWS CodeBuild projects

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Languages