All Projects → jch254 → Buildpipeline

jch254 / Buildpipeline

Licence: mit
AWS-powered serverless build, test and deploy pipeline ft. multiple environments

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Buildpipeline

Terrascan
Detect compliance and security violations across Infrastructure as Code to mitigate risk before provisioning cloud native infrastructure.
Stars: ✭ 2,687 (+2459.05%)
Mutual labels:  aws, terraform, infrastructure
Toc
A Table of Contents of all Gruntwork Code
Stars: ✭ 111 (+5.71%)
Mutual labels:  aws, terraform, infrastructure
Terraform Multienv
A template for maintaining a multiple environments infrastructure with Terraform. This template includes a CI/CD process, that applies the infrastructure in an AWS account.
Stars: ✭ 107 (+1.9%)
Mutual labels:  terraform, infrastructure, ci
Infra Personal
Terraform for setting up my personal infrastructure
Stars: ✭ 45 (-57.14%)
Mutual labels:  aws, terraform, infrastructure
Baumeister
👷 The aim of this project is to help you to build your things. From Bootstrap themes over static websites to single page applications.
Stars: ✭ 171 (+62.86%)
Mutual labels:  webpack, build-tool, build-automation
Tfsec
Security scanner for your Terraform code
Stars: ✭ 3,622 (+3349.52%)
Mutual labels:  aws, terraform, ci
Mikado
🤖💨Mikado helps managing your AWS infrastructure for WordPress sites by defining an out-of-box, highly available, easy-to-deploy setup
Stars: ✭ 80 (-23.81%)
Mutual labels:  aws, terraform, infrastructure
Walk
A fast, general purpose, graph based build and task execution utility.
Stars: ✭ 108 (+2.86%)
Mutual labels:  build-tool, build-automation, infrastructure
Terraform Aws Gitlab Runner
Terraform module for AWS GitLab runners on ec2 (spot) instances
Stars: ✭ 292 (+178.1%)
Mutual labels:  aws, terraform, ci
Terraform Security Scan
Run a security scan on your terraform with the very nice https://github.com/liamg/tfsec
Stars: ✭ 64 (-39.05%)
Mutual labels:  aws, terraform, ci
Typhoon
Minimal and free Kubernetes distribution with Terraform
Stars: ✭ 1,397 (+1230.48%)
Mutual labels:  aws, terraform
Gitops Terraform Jenkins
GitOps Workflow with Jenkins and Terraform
Stars: ✭ 73 (-30.48%)
Mutual labels:  aws, terraform
Tf Jitsi
5-minute self-hosted Jitsi on AWS
Stars: ✭ 73 (-30.48%)
Mutual labels:  aws, terraform
Serverless Plugin Webpack
Serverless Plugin Webpack
Stars: ✭ 72 (-31.43%)
Mutual labels:  webpack, aws
Terraform Aws Elasticache Redis
Terraform module to provision an ElastiCache Redis Cluster
Stars: ✭ 73 (-30.48%)
Mutual labels:  aws, terraform
Terraform Aws Couchbase
Reusable infrastructure modules for running Couchbase on AWS
Stars: ✭ 73 (-30.48%)
Mutual labels:  aws, terraform
Tf aws elasticsearch
Terraform module which creates AWS Elasticsearch resources
Stars: ✭ 73 (-30.48%)
Mutual labels:  aws, terraform
Terraform Ebs Attachmentizer
Convert ebs_block_device blocks in aws_instance resource to aws_ebs_volume and aws_volume_attachment resources
Stars: ✭ 79 (-24.76%)
Mutual labels:  aws, terraform
Terraform Aws Wireguard
Terraform module to deploy WireGuard on AWS
Stars: ✭ 72 (-31.43%)
Mutual labels:  aws, terraform
Terraboard
🌍 📋 A web dashboard to inspect Terraform States
Stars: ✭ 1,192 (+1035.24%)
Mutual labels:  aws, terraform

BuildPipeline

Test env | Production env

This project demonstrates an AWS-powered serverless build, test and deploy pipeline ft. multiple environments. The /src directory contains a React/TypeScript/Webpack-powered web app that is served from S3 with CloudFront as a CDN and Route 53 for DNS. The /infrastructure directory contains all infrastructure and deployment steps defined as code (Terraform and bash scripts). CodeBuild and CodePipeline take care of building, testing and deploying the project. All build logs are stored in CloudWatch. CodePipeline accesses GitHub using an access token.

When using CodeBuild to build, test and deploy each project, information about the build environment must be provided. A build environment represents a combination of operating system, programming language runtime, and tools that CodeBuild uses to build, test and deploy - A.K.A. a Docker image. I maintain build environments for the programming languages and tools I use frequently - e.g. docker-node-terraform-aws. The build commands and related settings must also be specified in a buildspec declaration (YAML format) stored at the root level of the project - e.g. buildspec-test.yml. Because a buildspec declaration must be valid YAML, the spacing in a buildspec declaration is important. If the number of spaces in a buildspec declaration is invalid, builds might fail immediately. A YAML validator can be used to test whether a buildspec declaration is valid YAML. See AWS CodeBuild Concepts and Build Phase Transitions for further information.

This project can be updated as needed to build many different types of project. If a project needs to build Docker images/interact with the Docker daemon the Privileged flag under advanced settings of the CodeBuild project in AWS console must be set to true. This can also be set to true using the privileged_mode variable of the build-pipeline module. The buildspec declaration must also start the Docker daemon and wait for it to become interactive:

- nohup /usr/local/bin/dockerd --host=unix:///var/run/docker.sock --host=tcp://0.0.0.0:2375 --storage-driver=overlay&
- timeout -t 15 sh -c "until docker info; do echo .; sleep 1; done"

CodeBuild and application/service secrets

This project uses EC2 Systems Manager Parameter Store to store shared, CodeBuild and app/service secrets as encrypted strings (e.g. passwords, database strings, etc.).

Secrets can be encrypted and decrypted via AWS console/CLI/SDK:

aws ssm put-parameter --region REGION --name "/codebuild/PROJECT_NAME/SECRET_NAME" --value "VALUE" --type SecureString --key-id "KEY_ID"
aws ssm get-parameters --region REGION --name "/codebuild/PROJECT_NAME/SECRET_NAME" --with-decryption --query Parameters[0].Value --output text

Naming Parameter Store parameters

  • Shared secrets: /shared/SECRET_NAME
  • CodeBuild secrets: /codebuild/PROJECT_NAME/SECRET_NAME
  • App/service secrets: /PROJECT_NAME/SECRET_NAME

See ./buildspec-test.yml as an example of decrypting a shared secret (GitHub OAuth token) via SSM Parameter Store in a buildspec declaration.

Deploying to production

Production deploy

This project automatically deploys the master branch to the test environment. To deploy a new version to the production environment the master branch must be merged into a production branch. The production branch is deployed to the production environment only after it is explicitly confirmed by the required parties via a CodePipeline approval action. The approval action prevents accidental releases to production (e.g. someone merges master into production by accident). This is useful as the production deploy is tightly controlled - to avoid impacting users during peak hours, align releases with third parties etc. Each commit on the production branch reflects a production deploy with the commit time being the approximate time of deployment (providing the pipelines are fast enough). Approval notifications are sent out via SNS.

Approval notification

Different steps run in each environment by utilising separate buildspec declarations and Terraform state files per environment. Production doesn't need to build or run tests, it just needs to deploy infrastructure and artifacts.

Cross-account production deploy

TODO!

Build notifications

AWS provides instructions on setting up build notifications with CloudWatch Events and SNS to send build notifications to subscribers whenever builds succeed, fail, go from one build phase to another, or any combination of these events. For more detailed notifications a Lambda function can be used (e.g. including commit details, sending data to a webhook etc.).

Caching

If the cache_bucket Terraform variable is provided, CodeBuild will use a folder in the given bucket as a build cache. See ./buildspec-test.yml as an example of defining cache paths in a buildspec declaration.

Using shared Terraform modules

This project defines Terraform modules within the /infrastructure directory. A good practice is to create a repository containing common infrastructure components which can be referenced and configured within other projects (e.g. web-app, rds-database, ecs-service etc.). Utilising Terraform modules to create 'building blocks' allows conventions to be enforced and standards defined for infrastructure (e.g. tags, security etc.). Modules are defined once then referenced and configured within projects using the repository URL/branch/tag/subfolder as the module source. This makes it easy for developers to define infrastructure as code within projects, achieve total ownership (provisioning and deploying as needed) and move fast. It also makes it easy to try out new concepts/ideas on isolated infrastructure. See Standardizing Application Deployments Using Amazon ECS and Terraform for a more detailed introduction and terraform-modules for an example.

--

Running the web app locally (with hot reloading)

  1. Run the following commands in the app's root directory then open http://localhost:3001
yarn install
yarn run dev

Building the production web app

  1. Run the following commands in the app's root directory then check the /dist folder
yarn install
yarn run build

Running the production web app locally

  1. Run the following commands in the app's root directory then open http://localhost:3001
yarn install
yarn run prod

Deployment/Infrastructure

Refer to the /infrastructure directory.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].