Skip to content

Instantly share code, notes, and snippets.

@onema
Created September 7, 2018 21:09
Show Gist options
  • Save onema/c67429e13f77dd2aa9fc15e9a95fdb13 to your computer and use it in GitHub Desktop.
Save onema/c67429e13f77dd2aa9fc15e9a95fdb13 to your computer and use it in GitHub Desktop.
Cloudformation template to create codebuild service for scala libraries
# Code pipeline for scala applications
AWSTemplateFormatVersion: '2010-09-09'
Description: >
Template to create codebuild service for components and libraries
#
#--------------------------------------------------------------------------
# PARAMETERS
#--------------------------------------------------------------------------
#
# Required and optional parameters to create simple build service
#
Parameters:
#
#--------------------------------------------------------------------------
# General application settings
#--------------------------------------------------------------------------
#
AppName:
Description: Name of the application
Type: String
CodacyProjectToken:
Description: Codacy Prject token for submitting code coverage information
Type: String
NoEcho: true
#
#--------------------------------------------------------------------------
# GitHub settings
#--------------------------------------------------------------------------
#
GitHubOwner:
Type: String
Description: GitHub repository owner
GitHubRepo:
Type: String
Description: GitHub repository name
GitHubBranch:
Type: String
Default: master
Description: GitHub repository branch
#
#--------------------------------------------------------------------------
# Code build settings
#--------------------------------------------------------------------------
#
CodeBuildComputeType:
Description: The build compute type
Type: String
Default: BUILD_GENERAL1_SMALL
AllowedValues:
- BUILD_GENERAL1_SMALL
- BUILD_GENERAL1_MEDIUM
- BUILD_GENERAL1_LARGE
CodeBuildDockerImage:
Description: The docker image to be used for code build
Type: String
Default: onema/scala-sbt:8u171-2.12.6-1.2.1-build
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: "Application Settings"
Parameters:
- AppName
- CodacyProjectToken
- Label:
default: "CodeBuild Settings"
Parameters:
- CodeBuildComputeType
- CodeBuildDockerImage
- Label:
default: "GitHub Settings"
Parameters:
- GitHubBranch
- GitHubOwner
- GitHubRepo
#
#--------------------------------------------------------------------------
# RESOURCES
#--------------------------------------------------------------------------
#
# Definition of all the resources required for the service
#
Resources:
#
#--------------------------------------------------------------------------
# CodeBuild Role and permissions.
#--------------------------------------------------------------------------
#
CodeBuildDeploymentRole:
Type: AWS::IAM::Role
Properties:
RoleName: !Sub "${AppName}-code-build-role"
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Service:
- "codebuild.amazonaws.com"
Action:
- "sts:AssumeRole"
ManagedPolicyArns:
#================================================================
# NOTE: This role has admin access
# lock down to fit your needs!
#================================================================
- arn:aws:iam::aws:policy/AdministratorAccess
#
#--------------------------------------------------------------------------
# CodeBuild definitions
#--------------------------------------------------------------------------
#
#========================================================================
# NOTE: GitHub requires a one time manual oauth authentication step
# see https://itonaut.com/2018/06/18/use-github-source-in-aws-codebuild-project-using-aws-cloudformation/
# for more information.
#========================================================================
CodeBuild:
Type: AWS::CodeBuild::Project
Properties:
Name: !Sub "${AppName}"
Description: !Sub "Run unit test for ${AppName}"
BadgeEnabled: true
Artifacts:
Type: NO_ARTIFACTS
ServiceRole: !Ref CodeBuildDeploymentRole
Environment:
ComputeType: !Ref CodeBuildComputeType
EnvironmentVariables:
- Name: CODACY_PROJECT_TOKEN
Value: !Ref CodacyProjectToken
- Name: APP_NAME
Value: !Ref AppName
Image: !Ref CodeBuildDockerImage
Type: LINUX_CONTAINER
Source:
Auth:
Type: OAUTH
Type: GITHUB
GitCloneDepth: 1
Location: !Sub "https://github.com/${GitHubOwner}/${GitHubRepo}.git"
BuildSpec: "buildspec.yml"
ReportBuildStatus: true
Triggers:
Webhook: true
#
#--------------------------------------------------------------------------
# OUTPUTS
#--------------------------------------------------------------------------
#
# Outputs of the resources generated by the code pipeline
#
Outputs:
CodeBuild:
Description: CodeBuild resource for the master branch
Value: !Ref CodeBuild
Export:
Name: !Sub "${AppName}-codebuild"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment