Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added CodeBuild Project resource and a CodeBuild example #624

Merged
merged 1 commit into from
Dec 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions examples/CodeBuild.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from troposphere import Template
from troposphere.codebuild import Artifacts, Environment, Source, Project


template = Template()
template.add_version('2010-09-09')

artifacts = Artifacts(Type='NO_ARTIFACTS')

environment = Environment(
ComputeType='BUILD_GENERAL1_SMALL',
Image='aws/codebuild/java:openjdk-8',
Type='LINUX_CONTAINER',
EnvironmentVariables=[{'Name': 'APP_NAME', 'Value': 'demo'}],
)

source = Source(
Location='codebuild-demo-test/0123ab9a371ebf0187b0fe5614fbb72c',
Type='S3'
)

project = Project(
"DemoProject",
Artifacts=artifacts,
Environment=environment,
Name='DemoProject',
ServiceRole='arn:aws:iam::0123456789:role/codebuild-role',
Source=source,
)
template.add_resource(project)

print(template.to_json())
30 changes: 30 additions & 0 deletions tests/examples_output/CodeBuild.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"AWSTemplateFormatVersion": "2010-09-09",
"Resources": {
"DemoProject": {
"Properties": {
"Artifacts": {
"Type": "NO_ARTIFACTS"
},
"Environment": {
"ComputeType": "BUILD_GENERAL1_SMALL",
"EnvironmentVariables": [
{
"Name": "APP_NAME",
"Value": "demo"
}
],
"Image": "aws/codebuild/java:openjdk-8",
"Type": "LINUX_CONTAINER"
},
"Name": "DemoProject",
"ServiceRole": "arn:aws:iam::0123456789:role/codebuild-role",
"Source": {
"Location": "codebuild-demo-test/0123ab9a371ebf0187b0fe5614fbb72c",
"Type": "S3"
}
},
"Type": "AWS::CodeBuild::Project"
}
}
}
106 changes: 106 additions & 0 deletions troposphere/codebuild.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Copyright (c) 2016, Mark Peek <mark@peek.org>
# All rights reserved.
#
# See LICENSE file for full license.

from . import AWSObject, AWSProperty, Tags
from .validators import integer


class Artifacts(AWSProperty):
props = {
'Location': (basestring, False),
'Name': (basestring, False),
'NameSpaceType': (basestring, False),
'Packaging': (basestring, False),
'Path': (basestring, False),
'Type': (basestring, True),
}

def validate(self):
valid_types = [
'CODEPIPELINE',
'NO_ARTIFACTS',
'S3',
]
artifact_type = self.properties.get('Type')
if artifact_type not in valid_types:
raise ValueError('Artifacts Type: must be one of %s' %
','.join(valid_types))

if artifact_type == 'S3':
for required_property in ['Name', 'Location']:
if not self.properties.get(required_property):
raise ValueError(
'Artifacts Type S3: requires %s to be set' %
required_property
)


class EnvironmentVariable(AWSProperty):
props = {
'Name': (basestring, True),
'Value': (basestring, True),
}


class Environment(AWSProperty):
props = {
'ComputeType': (basestring, True),
'EnvironmentVariables': ((list, [EnvironmentVariable]), False),
'Image': (basestring, True),
'Type': (basestring, True),
}

def validate(self):
valid_types = [
'LINUX_CONTAINER',
]
env_type = self.properties.get('Type')
if env_type not in valid_types:
raise ValueError('Environment Type: must be one of %s' %
','.join(valid_types))


class Source(AWSProperty):
props = {
'BuildSpec': (basestring, False),
'Location': (basestring, False),
'Type': (basestring, True),
}

def validate(self):
valid_types = [
'CODECOMMIT',
'CODEPIPELINE',
'GITHUB',
'S3',
]

source_type = self.properties.get('Type')
if source_type not in valid_types:
raise ValueError('Source Type: must be one of %s' %
','.join(valid_types))

location = self.properties.get('Location')
if source_type is not 'CODEPIPELINE' and not location:
raise ValueError(
'Source Location: must be defined when type is %s' %
source_type
)


class Project(AWSObject):
resource_type = "AWS::CodeBuild::Project"

props = {
'Artifacts': (Artifacts, True),
'Description': (basestring, False),
'EncryptionKey': (basestring, False),
'Environment': (Environment, True),
'Name': (basestring, True),
'ServiceRole': (basestring, True),
'Source': (Source, True),
'Tags': (Tags, False),
'TimeoutInMinutes': (integer, False),
}