Created
July 25, 2017 03:35
-
-
Save ssummer3/6283d0a9a26c5904f459a76f82a8d536 to your computer and use it in GitHub Desktop.
CodeBuild for Github Projects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| AWSTemplateFormatVersion: '2010-09-09' | |
| Description: '{{ application_stage }} CodeBuild' | |
| Metadata: | |
| AWS::CloudFormation::Interface: | |
| ParameterLabels: | |
| # Application Settings | |
| ApplicationName: {default: Application Name} | |
| RepoUrl: {default: Application GitHub Repo Name (if different)} | |
| TargetStage: {default: Artifact Target Stage} | |
| BuildSpec: {default: BuildSpec location or content} | |
| # CodeBuild Settings | |
| BuildImage: {default: CodeBuild Environment} | |
| TargetBucket: {default: Artifact Target S3 Bucket} | |
| Packaging: {default: Packaging Type} | |
| BuildTimeout: {default: Max Build Time in Minutes} | |
| BuildComputeType: {default: CodeBuild Machine Type} | |
| ServiceRole: {default: CodeBuild Service IAM Role} | |
| LogRetention: {default: Build Log Retention} | |
| ParameterGroups: | |
| - Label: {default: Application Settings} | |
| Parameters: | |
| - ApplicationName | |
| - RepoUrl | |
| - TargetStage | |
| - BuildSpec | |
| - Label: {default: CodeBuild Settings} | |
| Parameters: | |
| - BuildImage | |
| - TargetBucket | |
| - Packaging | |
| - BuildTimeout | |
| - BuildComputeType | |
| - ServiceRole | |
| - LogRetention | |
| Outputs: | |
| BuildLogsURL: | |
| Value: !Sub https://console.aws.amazon.com/cloudwatch/home?region=${AWS::Region}#logStream:group=${LogGroup} | |
| CodeBuildURL: | |
| Value: !Sub https://console.aws.amazon.com/codebuild/home?region=${AWS::Region}#/projects/${Project}/view | |
| RepoURL: | |
| Value: !If [BlankRepoUrl, !Sub 'https://github.com/ndlib/${ApplicationName}.git', !Ref RepoUrl] | |
| Conditions: | |
| DefaultServiceRole: !Equals ['', !Ref ServiceRole] | |
| DefaultBuildSpec: !Equals ['', !Ref BuildSpec] | |
| BlankRepoUrl: !Equals ['', !Ref RepoUrl] | |
| ZipPackaging: !Equals ['ZIP', !Ref Packaging] | |
| Parameters: | |
| ApplicationName: | |
| Type: String | |
| RepoUrl: | |
| Type: String | |
| Description: https://github.com/<user>/<application>.git | |
| Default: '' | |
| TargetStage: | |
| Type: String | |
| Default: test | |
| BuildSpec: | |
| Type: String | |
| Description: file name or valid yaml | |
| Default: '' | |
| BuildImage: | |
| Type: String | |
| Description: aws/codebuild or docker hub image | |
| # aws codebuild list-curated-environment-images --query 'platforms[].languages[].images[].name' | |
| # - aws/codebuild/ubuntu-base:14.04 | |
| # - aws/codebuild/nodejs:4.3.2 | |
| # - aws/codebuild/nodejs:7.0.0 | |
| # - aws/codebuild/python:2.7.12 | |
| # - aws/codebuild/python:3.5.2 | |
| # - aws/codebuild/ruby:2.3.1 | |
| # - aws/codebuild/eb-ruby-2.3-amazonlinux-64:2.3.2 | |
| TargetBucket: | |
| Type: String | |
| Description: versioned S3 bucket | |
| Default: testlibnd-cf | |
| Packaging: | |
| Type: String | |
| Description: ZIP | NONE | |
| Default: NONE | |
| AllowedValues: | |
| - ZIP | |
| - NONE | |
| BuildTimeout: | |
| Type: Number | |
| Description: minutes | |
| Default: 5 | |
| BuildComputeType: | |
| Type: String | |
| Description: CodeBuild Machine Type | |
| Default: BUILD_GENERAL1_SMALL | |
| AllowedValues: | |
| - BUILD_GENERAL1_SMALL # 3 GB memory, 2 vCPU | |
| - BUILD_GENERAL1_MEDIUM # 7 GB memory, 4 vCPU | |
| - BUILD_GENERAL1_LARGE # 15 GB memory, 8 vCPU | |
| ServiceRole: | |
| Type: String | |
| Description: Arn | |
| Default: '' | |
| LogRetention: | |
| Type: Number | |
| Description: days | |
| Default: 7 | |
| AllowedValues: [1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1827, 3653] | |
| Resources: | |
| LogGroup: | |
| Type: AWS::Logs::LogGroup | |
| Properties: | |
| LogGroupName: !Sub /aws/codebuild/${Project} | |
| RetentionInDays: !Ref LogRetention | |
| Project: | |
| Type: AWS::CodeBuild::Project | |
| Properties: | |
| Name: !Sub ${ApplicationName}-${TargetStage} | |
| Description: | |
| !Join | |
| - ' ' | |
| - - !Sub ${ApplicationName}-${TargetStage} from | |
| - !If [BlankRepoUrl, !Sub 'https://github.com/ndlib/${ApplicationName}.git', !Ref RepoUrl] | |
| TimeoutInMinutes: !Ref BuildTimeout | |
| ServiceRole: !If [DefaultServiceRole, !ImportValue 'codebuild:role', !Ref ServiceRole] | |
| Artifacts: | |
| Type: S3 | |
| Packaging: !If [ZipPackaging, ZIP, NONE] | |
| NamespaceType: BUILD_ID | |
| Location: !Ref TargetBucket | |
| Path: !Sub ${TargetStage}/${ApplicationName} | |
| Name: !If [ZipPackaging, build.zip, build] | |
| Environment: | |
| Type: LINUX_CONTAINER | |
| ComputeType: !Ref BuildComputeType | |
| Image: !Ref BuildImage | |
| EnvironmentVariables: | |
| - {Name: BUNDLE_FROZEN, Value: 'true'} | |
| # - {Name: NODE_ENV, Value: 'production'} | |
| - {Name: TARGET_BUCKET, Value: !Ref TargetBucket} | |
| - {Name: APPLICATION_NAME, Value: !Ref ApplicationName} | |
| - {Name: TARGET_STAGE, Value: !Ref TargetStage} | |
| Source: | |
| Type: GITHUB | |
| Location: !If [BlankRepoUrl, !Sub 'https://github.com/ndlib/${ApplicationName}.git', !Ref RepoUrl] | |
| BuildSpec: !If [DefaultBuildSpec, !Ref 'AWS::NoValue', !Ref BuildSpec] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment