Skip to content

Create AWS status/commit-id badges for CodeBuild & CodePipeline automatically

License

Notifications You must be signed in to change notification settings

unfor19/aws-build-badges

Repository files navigation

aws-build-badges

Create status-badges and commit-id badges according to CodeBuild/CodePipeline states.
The badges are uploaded to S3 bucket, and then you can link to those badges (SVG files) in your README.md

Example

Getting Started

Prerequisites

  1. You have at least one CodeBuild project and/or at least one CodePipeline.
  2. You're going to launch this app in the same region your CodeBuild projects and CodePipelines are
  3. Yup, that's it, no installation no nothing

Deployment

Quick Deployment

Launch in Virginia Virginia us-east-1

Launch in Ireland Ireland eu-west-1

Launch in Hong Kong Hong Kong ap-east-1

Launch in Canada Canada ca-central-1

Not using any of the regions above? Go ahead and deploy with a template

Deploy with a template

Download the cloudformation template from here and upload it manually to a specific region.

Contributing

Expand/Collapse

Built With

  1. NodeJS 10.x - AWS Lambda supports this version of NodeJS
  2. AWS SDK for JavaScript - Upload status badges to S3 bucket, and get commit-id from pipeline
  3. yarn - package manager (instead of npm)
  4. TypeScript 3.7 - targeting ES5
  5. ESLint - Linting TypeScript (src) and JavaScript (dist) files
  6. Webpack v3.3 - Packing and minifying code - yarn build
  7. serverless-framework - Deploying to AWS - yarn deploy:vault-dev
  8. Jest - for testing - yarn test
  9. aws-vault - securing AWS credentials

Installation

  1. Download and install the LTS version of NodeJS
  2. Download and install git
  3. Clone this repo with git
    (home) $: git clone https://github.com/unfor19/aws-build-badges.git
    (home) $: cd ./aws-build-badges
    (aws-build-badges) $: 
    
  4. Download and install yarn
  5. Install serverless-framework globally
    (aws-build-badges) $: yarn global add serverless
    
  6. Install application dependencies
    (aws-build-badges) $: yarn installDeps
    
  7. Create a bucket for serverless deployments, and name it: myapp-badges-deployment-STAGE, where myapp is your app's name
    • For example: myapp-badges-deployment-prod
  8. (Optional) Download and install aws-vault

Configuration

.env

Copy env file to .env and modify the relevant variables.

These variables are releavnt only if you intend to run tests or aws-vault.

BUCKET_BADGES=myapp-bucket-for-testing # jest
IMAGEPATH=true                         # for tests
VAULT_PROFILE_TESTING=myapp-dev        # aws-vault
VAULT_PROFILE_DEV=myapp-dev            # aws-vault
VAULT_PROFILE_STAGING=myapp-staging    # aws-vault
VAULT_PROFILE_PROD=myapp-prod          # aws-vault

.serverless.vars.yml

Copy serverless.vars.yml to .serverless.vars.yml and modify the relevant variables.

Find and replace "myapp" with your application's name. And of course, do whatever changes you need, so it fits your infrastructure.

Scripts

The scripts reside in the package.json file, under the scripts section.
All the scripts must run while the present working directory is the project's folder, aws-build-badges

yarn test:vault          - Run jest using aws-vault profile
yarn test:aws            - Run jest using AWS credentials and profiles
yarn build:dev           - Run webpack for each service, mode=development
yarn build:prod          - Run webpack for each service, mode=production
yarn deploy:vault-STAGE  - Deploy to AWS using aws-vault profile
yarn deploy:aws-STAGE    - Deploy to AWS using AWS credentials and profiles
yarn destroy:vault-STAGE - Destroy stack using aws-vault profile
yarn destroy:aws-STAGE   - Destroy stack using AWS credentials and profiles

Usage

(aws-build-badges) $: yarn deploy:vault-prod
yarn run v1.19.1
$ yarn build:prod && export $(cat .env) && aws-vault exec ${VAULT_PROFILE_PROD} -- sls deploy --verbose --stage=prod
$ bash build_services_prod
...
Serverless: Removing old service artifacts from S3...
Serverless: Run the "serverless" command to setup monitoring, troubleshooting and testing.
Done in 193.59s.

Troubleshooting

yarn test:vault

  1. Issue: Fails with: Invalid bucket name.
    • Solution: Set the BUCKET_BADGES variable in .env
  2. Issue: Failed to get credentials for jest
    • Solution: Set the VAULT_PROFILE_TESTING variable in .env
  3. Issue: (node:#####) DeprecationWarning: Tapable.plugin is deprecated. Use new API on .hooks instead
    • Solution: You can ignore this warning - details

Tested on

OS Bash serverless-framework yarn AWS SDK aws-vault
Ubuntu 19.10 5.0.3 1.56.1 1.19.1 2.580.0 4.7.1
Windows 10 TBD TBD TBD TBD TBD
MacOS TBD TBD TBD TBD TBD

About

Create AWS status/commit-id badges for CodeBuild & CodePipeline automatically

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published