Skip to content
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
13 changes: 13 additions & 0 deletions docs/providers-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,25 @@ Provider type: `codebuild`.
> If you wish to pass in a custom inline Buildspec as a string for the
> CodeBuild Project this would override any `buildspec.yml` file.
> Read more [here](https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html#build-spec-ref-example).
>
> Note: Either specify the `spec_inline` or the `spec_filename` in the
> properties block. If both are supplied, the pipeline generator will throw
> an error instead.
- *spec_filename* *(String)* default: `buildspec.yml`.
> If you wish to pass in a custom Buildspec file that is within the
> repository. This is useful for custom deploy type actions where CodeBuild
> will perform the execution of the commands. Path is relational to the
> root of the repository, so `build/buidlspec.yml` refers to the
> `buildspec.yml` stored in the `build` directory of the repository.
>
> In case CodeBuild is used as a deployment provider, the default BuildSpec
> file name is `deployspec.yml` instead. In case you would like to test
> a given environment using CodeBuild, you can rename it to `testspec.yml`
> or something similar using this property.
>
> Note: Either specify the `spec_inline` or the `spec_filename` in the
> properties block. If both are supplied, the pipeline generator will throw
> an error instead.

### Jenkins

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
ADF_DEPLOYMENT_REGION = os.environ["AWS_REGION"]
ADF_DEPLOYMENT_ACCOUNT_ID = os.environ["ACCOUNT_ID"]
DEFAULT_CODEBUILD_IMAGE = "UBUNTU_14_04_PYTHON_3_7_1"
DEFAULT_BUILD_SPEC_FILENAME = 'buildspec.yml'
DEFAULT_DEPLOY_SPEC_FILENAME = 'deployspec.yml'

class CodeBuild(core.Construct):
# pylint: disable=no-value-for-parameter
Expand All @@ -45,10 +47,10 @@ def __init__(self, scope: core.Construct, id: str, shared_modules_bucket: str, d
environment_variables=CodeBuild.generate_build_env_variables(_codebuild, shared_modules_bucket, map_params, target),
privileged=target.get('properties', {}).get('privileged', False) or map_params['default_providers']['build'].get('properties', {}).get('privileged', False)
)
_spec_filename = (
target.get('properties', {}).get('spec_filename') or
map_params['default_providers']['deploy'].get('properties', {}).get('spec_filename') or
'deployspec.yml'
build_spec = CodeBuild.determine_build_spec(
id,
map_params['default_providers']['deploy'].get('properties', {}),
target,
)
_codebuild.PipelineProject(
self,
Expand All @@ -59,7 +61,7 @@ def __init__(self, scope: core.Construct, id: str, shared_modules_bucket: str, d
project_name="adf-deploy-{0}".format(id),
timeout=core.Duration.minutes(_timeout),
role=_iam.Role.from_role_arn(self, 'build_role', role_arn=_build_role, mutable=False),
build_spec=_codebuild.BuildSpec.from_source_filename(_spec_filename)
build_spec=build_spec,
)
self.deploy = Action(
name="{0}".format(id),
Expand All @@ -85,18 +87,10 @@ def __init__(self, scope: core.Construct, id: str, shared_modules_bucket: str, d
)
if map_params['default_providers']['build'].get('properties', {}).get('role'):
ADF_DEFAULT_BUILD_ROLE = 'arn:aws:iam::{0}:role/{1}'.format(ADF_DEPLOYMENT_ACCOUNT_ID, map_params['default_providers']['build'].get('properties', {}).get('role'))
_build_stage_spec = map_params['default_providers']['build'].get('properties', {}).get('spec_filename')
_build_inline_spec = map_params['default_providers']['build'].get(
'properties', {}).get(
'spec_inline', '') or map_params['default_providers']['build'].get(
'properties', {}).get(
'spec_inline', '')
if _build_stage_spec:
_spec = _codebuild.BuildSpec.from_source_filename(_build_stage_spec)
elif _build_inline_spec:
_spec = _codebuild.BuildSpec.from_object(_build_inline_spec)
else:
_spec = None
build_spec = CodeBuild.determine_build_spec(
id,
map_params['default_providers']['build'].get('properties', {})
)
_codebuild.PipelineProject(
self,
'project',
Expand All @@ -105,7 +99,7 @@ def __init__(self, scope: core.Construct, id: str, shared_modules_bucket: str, d
description="ADF CodeBuild Project for {0}".format(map_params['name']),
project_name="adf-build-{0}".format(map_params['name']),
timeout=core.Duration.minutes(_timeout),
build_spec=_spec,
build_spec=build_spec,
role=_iam.Role.from_role_arn(self, 'default_build_role', role_arn=_build_role, mutable=False)
)
self.build = _codepipeline.CfnPipeline.StageDeclarationProperty(
Expand All @@ -122,6 +116,49 @@ def __init__(self, scope: core.Construct, id: str, shared_modules_bucket: str, d
]
)

@staticmethod
def _determine_stage_build_spec(codebuild_id, props, stage_name, default_filename):
filename = props.get('spec_filename')
spec_inline = props.get('spec_inline', {})
if filename and spec_inline:
raise Exception(
"The spec_filename and spec_inline are both present "
"inside the {0} stage definition of {1}. "
"Whereas only one of these two is allowed.".format(
stage_name,
codebuild_id,
),
)

if spec_inline:
return _codebuild.BuildSpec.from_object(spec_inline)

return _codebuild.BuildSpec.from_source_filename(
filename or default_filename,
)

@staticmethod
def determine_build_spec(codebuild_id, default_props, target=None):
if target:
target_props = target.get('properties', {})
if 'spec_inline' in target_props or 'spec_filename' in target_props:
return CodeBuild._determine_stage_build_spec(
codebuild_id=codebuild_id,
props=target_props,
stage_name='deploy target',
default_filename=DEFAULT_DEPLOY_SPEC_FILENAME,
)
return CodeBuild._determine_stage_build_spec(
codebuild_id=codebuild_id,
props=default_props,
stage_name='default {}'.format('deploy' if target else 'build'),
default_filename=(
DEFAULT_DEPLOY_SPEC_FILENAME
if target
else DEFAULT_BUILD_SPEC_FILENAME
),
)

@staticmethod
def determine_build_image(scope, target, map_params):
specific_image = None
Expand Down
Loading