Skip to content

Commit

Permalink
Mcodestar source for build pipeline generation
Browse files Browse the repository at this point in the history
  • Loading branch information
robincsamuel committed Feb 16, 2022
1 parent b7ab6e2 commit c51bc41
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
6 changes: 4 additions & 2 deletions chalice/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,11 +565,13 @@ def package(ctx, single_file, stage, merge_template,
"This option must be provided when using a python "
"version besides 2.7."))
@click.option('-s', '--source', default='codecommit',
type=click.Choice(['codecommit', 'github']),
type=click.Choice(['codecommit', 'github', 'codestar']),
help=("Specify the input source. The default value of "
"'codecommit' will create a CodeCommit repository "
"for you. The 'github' value allows you to "
"reference an existing GitHub repository."))
"reference an existing GitHub repository."
"The 'codestar' value allows you to reference "
"bitbucket or any codestar connection."))
@click.option('-b', '--buildspec-file',
help=("Specify path for buildspec.yml file. "
"By default, the build steps are included in the "
Expand Down
5 changes: 5 additions & 0 deletions chalice/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ def index():
],
"Resource": "*",
"Effect": "Allow"
},
{
"Action": ["codestar-connections:UseConnection"],
"Resource": "*",
"Effect": "Allow"
}
]
}
Expand Down
44 changes: 44 additions & 0 deletions chalice/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ def create_template(self, pipeline_params):
resources = [] # type: List[BaseResource]
if pipeline_params.code_source == 'github':
resources.append(GithubSource())
elif pipeline_params.code_source == 'codestar':
resources.append(CodeStarSource())
else:
resources.append(CodeCommitSourceRepository())
resources.extend([CodeBuild(create_buildspec_v2), CodePipeline()])
Expand Down Expand Up @@ -254,6 +256,22 @@ def add_to_template(self, template, pipeline_params):
}


class CodeStarSource(BaseResource):
def add_to_template(self, template, pipeline_params):
p = template.setdefault('Parameters', {})
p['CodeStarConnectionArn'] = {
'Type': 'String',
'Description': 'The codestar connection arn.',
}
p['CodeStarFullRepositoryId'] = {
'Type': 'String',
'Description': (
'The repository id. '
'Example, bitbucketusername/repo'
)
}


class GithubSource(BaseResource):
def add_to_template(self, template, pipeline_params):
# type: (Dict[str, Any], PipelineParameters) -> None
Expand Down Expand Up @@ -520,8 +538,34 @@ def _create_source_stage(self, pipeline_params):
# type: (PipelineParameters) -> Dict[str, Any]
if pipeline_params.code_source == 'codecommit':
return self._code_commit_source()
if pipeline_params.code_source == 'codestar':
return self._code_star_source()
return self._github_source(pipeline_params.pipeline_version)

def _code_star_source(self):
return {
'Name': 'Source',
'Actions': [{
"Name": "Source",
"ActionTypeId": {
"Category": "Source",
"Owner": "AWS",
"Version": "1",
"Provider": "CodeStarSourceConnection"
},
'RunOrder': 1,
'OutputArtifacts': [{
'Name': 'SourceRepo',
}],
'Configuration': {
'ConnectionArn': {'Ref': 'CodeStarConnectionArn'},
'FullRepositoryId': {'Ref': 'CodeStarFullRepositoryId'},
'BranchName': 'master',
'DetectChanges': True,
}
}],
}

def _github_source(self, pipeline_version):
# type: (str) -> Dict[str, Any]
oauth_token = {'Ref': 'GithubPersonalToken'} # type: Dict[str, Any]
Expand Down

0 comments on commit c51bc41

Please sign in to comment.