-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added CodeBuild Project resource and a CodeBuild example
- Loading branch information
1 parent
ac2516b
commit 90890a4
Showing
3 changed files
with
168 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
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( | ||
ComputerType='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()) |
This file contains 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
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": { | ||
"ComputerType": "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" | ||
} | ||
} | ||
} |
This file contains 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
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), | ||
} |