Skip to content

Commit

Permalink
Update ADF pipeline generation to CDKv2
Browse files Browse the repository at this point in the history
  • Loading branch information
pergardebrink committed Mar 15, 2023
1 parent cb029ef commit 9873e03
Show file tree
Hide file tree
Showing 20 changed files with 101 additions and 139 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ Resources:
python: 3.9
nodejs: 14
commands:
- npm install cdk@1.188 -g -y --quiet --no-progress
- npm install cdk@2.68 -g -y --quiet --no-progress
- aws s3 cp s3://$SHARED_MODULES_BUCKET/adf-build/ ./adf-build/ --recursive --quiet
- pip install -r adf-build/requirements.txt -r adf-build/helpers/requirements.txt -q -t ./adf-build
pre_build:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ Resources:
python: 3.9
nodejs: 14
commands:
- npm install cdk@1.188 -g -y --quiet --no-progress
- npm install cdk@2.68 -g -y --quiet --no-progress
- aws s3 cp s3://$SHARED_MODULES_BUCKET/adf-build/ ./adf-build/ --recursive --quiet
- pip install -r adf-build/requirements.txt -q -t ./adf-build
- chmod 755 adf-build/cdk/execute_pipeline_stacks.py adf-build/cdk/generate_pipeline_stacks.py
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
from aws_cdk import (
aws_codestarnotifications as cp_notifications,
aws_codepipeline as codepipeline,
core,
Stack
)
from constructs import Construct
from logger import configure_logger

ADF_DEPLOYMENT_REGION = os.environ["AWS_REGION"]
Expand All @@ -28,17 +29,17 @@
]


class PipelineNotifications(core.Construct):
class PipelineNotifications(Construct):
def __init__(
self,
scope: core.Construct,
scope: Construct,
id: str,
pipeline: codepipeline.CfnPipeline,
notification_config,
**kwargs,
): # pylint: disable=W0622
super().__init__(scope, id, **kwargs)
stack = core.Stack.of(self)
stack = Stack.of(self)
slack_channel_arn = (
f"arn:{stack.partition}:chatbot::{ADF_DEPLOYMENT_ACCOUNT_ID}:"
f"chat-configuration/slack-channel/"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,17 @@
"""

import os
from aws_cdk import (
core
)
from constructs import Construct

from cdk_constructs import adf_codepipeline

ADF_DEPLOYMENT_REGION = os.environ["AWS_REGION"]
ADF_DEFAULT_BUILD_TIMEOUT = 20


class CloudFormation(core.Construct):
class CloudFormation(Construct):
# pylint: disable=W0622, W0235
def __init__(self, scope: core.Construct, id: str, **kwargs):
def __init__(self, scope: Construct, id: str, **kwargs):
super().__init__(scope, id, **kwargs)

@staticmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,30 @@
aws_kms as _kms,
aws_ecr as _ecr,
aws_ec2 as _ec2,
core
Stack,
Duration,
Aws
)
from constructs import Construct

from cdk_constructs.adf_codepipeline import Action

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_CODEBUILD_IMAGE = "STANDARD_5_0"
DEFAULT_BUILD_SPEC_FILENAME = 'buildspec.yml'
DEFAULT_DEPLOY_SPEC_FILENAME = 'deployspec.yml'
ADF_DEFAULT_BUILD_ROLE_NAME = 'adf-codebuild-role'
ADF_DEFAULT_BUILD_TIMEOUT = 20


class CodeBuild(core.Construct):
class CodeBuild(Construct):
# pylint: disable=no-value-for-parameter

# pylint: disable=W0622
def __init__(
self,
scope: core.Construct,
scope: Construct,
id: str,
shared_modules_bucket: str,
deployment_region_kms: str,
Expand All @@ -43,7 +46,7 @@ def __init__(
**kwargs,
):
super().__init__(scope, id, **kwargs)
stack = core.Stack.of(self)
stack = Stack.of(self)

# if CodeBuild is being used as a deployment action we want to allow
# target specific values.
Expand Down Expand Up @@ -123,7 +126,7 @@ def __init__(
),
description=f"ADF CodeBuild Project for {id}",
project_name=f"adf-deploy-{id}",
timeout=core.Duration.minutes(timeout),
timeout=Duration.minutes(timeout),
role=_iam.Role.from_role_arn(
self,
'build_role',
Expand Down Expand Up @@ -205,7 +208,7 @@ def __init__(
),
description=f"ADF CodeBuild Project for {map_params['name']}",
project_name=f"adf-build-{map_params['name']}",
timeout=core.Duration.minutes(timeout),
timeout=Duration.minutes(timeout),
build_spec=build_spec,
role=_iam.Role.from_role_arn(
self,
Expand Down Expand Up @@ -399,7 +402,7 @@ def generate_build_env_variables(
"ADF_DEPLOYMENT_MAP_SOURCE": deployment_map_source,
"ADF_DEPLOYMENT_MAP_NAME": deployment_map_name,
"S3_BUCKET_NAME": shared_modules_bucket,
"ACCOUNT_ID": core.Aws.ACCOUNT_ID,
"ACCOUNT_ID": Aws.ACCOUNT_ID,
**(
map_params
.get('default_providers', {})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

import os
from aws_cdk import (
aws_codepipeline as _codepipeline,
core
aws_codepipeline as _codepipeline
)
from constructs import Construct

from cdk_constructs.adf_codepipeline import Action

Expand All @@ -17,8 +17,8 @@
ADF_DEFAULT_BUILD_TIMEOUT = 20


class CodeCommit(core.Construct):
def __init__(self, scope: core.Construct, id: str, map_params: dict, **kwargs): #pylint: disable=W0622
class CodeCommit(Construct):
def __init__(self, scope: Construct, id: str, map_params: dict, **kwargs): #pylint: disable=W0622
super().__init__(scope, id, **kwargs)
default_providers = map_params.get("default_providers", {})
source_props = default_providers.get("source", {}).get("properties", {})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
aws_codepipeline as _codepipeline,
aws_events as _eventbridge,
aws_events_targets as _eventbridge_targets,
core
SecretValue,
Fn
)
from constructs import Construct

from cdk_constructs import adf_events
from logger import configure_logger
Expand Down Expand Up @@ -241,7 +243,7 @@ def _generate_configuration(self):
.get('branch', self.default_scm_branch)
),
# pylint: disable=no-value-for-parameter
"OAuthToken": core.SecretValue.secrets_manager(
"OAuthToken": SecretValue.secrets_manager(
(
self.map_params['default_providers']['source']
.get('properties', {})
Expand Down Expand Up @@ -682,7 +684,7 @@ def _get_output_artifacts(self):
return []


class Pipeline(core.Construct):
class Pipeline(Construct):
_import_arns = [
'CodePipelineRoleArn',
'CodeBuildRoleArn',
Expand All @@ -696,7 +698,7 @@ class Pipeline(core.Construct):
# pylint: disable=W0622
def __init__(
self,
scope: core.Construct,
scope: Construct,
id: str,
map_params: dict,
ssm_params: dict,
Expand Down Expand Up @@ -827,7 +829,7 @@ def import_required_arns():
output = []
for arn in Pipeline._import_arns:
# pylint: disable=no-value-for-parameter
output.append(core.Fn.import_value(arn))
output.append(Fn.import_value(arn))
return output

def add_pipeline_trigger(self, trigger_type, trigger_config):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import os

from aws_cdk import (
aws_codepipeline as _codepipeline,
core
aws_codepipeline as _codepipeline
)
from constructs import Construct

from cdk_constructs.adf_codepipeline import Action

Expand All @@ -18,8 +18,8 @@
ADF_DEFAULT_BUILD_TIMEOUT = 20


class CodeStar(core.Construct):
def __init__(self, scope: core.Construct, id: str, map_params: dict, **kwargs): #pylint: disable=W0622
class CodeStar(Construct):
def __init__(self, scope: Construct, id: str, map_params: dict, **kwargs): #pylint: disable=W0622
super().__init__(scope, id, **kwargs)
self.source = _codepipeline.CfnPipeline.StageDeclarationProperty(
name="Source-CodeStar",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
aws_events_targets as _targets,
aws_codepipeline as _codepipeline,
aws_sns as _sns,
core
Stack
)
from constructs import Construct


ADF_DEPLOYMENT_REGION = os.environ["AWS_REGION"]
Expand All @@ -21,11 +22,11 @@
ADF_PIPELINE_PREFIX = os.environ.get("ADF_PIPELINE_PREFIX", "")


class Events(core.Construct):
def __init__(self, scope: core.Construct, id: str, params: dict, **kwargs): # pylint: disable=W0622
class Events(Construct):
def __init__(self, scope: Construct, id: str, params: dict, **kwargs): # pylint: disable=W0622
super().__init__(scope, id, **kwargs)
# pylint: disable=no-value-for-parameter
stack = core.Stack.of(self)
stack = Stack.of(self)
_pipeline = _codepipeline.Pipeline.from_pipeline_arn(self, 'pipeline', params["pipeline"])
_source_account = params.get('source', {}).get('account_id')
_provider = params.get('source', {}).get('provider')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

from aws_cdk import (
aws_codepipeline as _codepipeline,
core
Token
)
from constructs import Construct

from cdk_constructs.adf_codepipeline import Action

Expand All @@ -18,8 +19,8 @@
ADF_DEFAULT_BUILD_TIMEOUT = 20


class GitHub(core.Construct):
def __init__(self, scope: core.Construct, id: str, map_params: dict, **kwargs): #pylint: disable=W0622
class GitHub(Construct):
def __init__(self, scope: Construct, id: str, map_params: dict, **kwargs): #pylint: disable=W0622
super().__init__(scope, id, **kwargs)
self.source = _codepipeline.CfnPipeline.StageDeclarationProperty(
name="Source-Github",
Expand Down Expand Up @@ -65,6 +66,6 @@ def create_webhook_when_required(scope, pipeline, map_params):
target_action="source",
name=f"adf-webhook-{map_params['name']}",
# pylint: disable=no-value-for-parameter
target_pipeline_version=core.Token.as_number(pipeline_version),
target_pipeline_version=Token.as_number(pipeline_version),
register_with_third_party=True
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@

import os
from aws_cdk import (
aws_codepipeline as _codepipeline,
core
aws_codepipeline as _codepipeline
)
from constructs import Construct

from cdk_constructs.adf_codepipeline import Action

ADF_DEPLOYMENT_REGION = os.environ["AWS_REGION"]
ADF_DEPLOYMENT_ACCOUNT_ID = os.environ["ACCOUNT_ID"]

class Jenkins(core.Construct):
def __init__(self, scope: core.Construct, id: str, map_params: dict, **kwargs): #pylint: disable=W0622
class Jenkins(Construct):
def __init__(self, scope: Construct, id: str, map_params: dict, **kwargs): #pylint: disable=W0622
super().__init__(scope, id, **kwargs)
self.build = _codepipeline.CfnPipeline.StageDeclarationProperty(
name="Build",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
aws_iam as _iam,
aws_kms as _kms,
aws_lambda_event_sources as _event_sources,
core
Stack
)
from constructs import Construct
from logger import configure_logger

ADF_DEPLOYMENT_REGION = os.environ["AWS_REGION"]
Expand All @@ -21,13 +22,13 @@
LOGGER = configure_logger(__name__)


class Notifications(core.Construct):
class Notifications(Construct):
def __init__(
self, scope: core.Construct, id: str, map_params: dict, **kwargs
self, scope: Construct, id: str, map_params: dict, **kwargs
): # pylint: disable=W0622
super().__init__(scope, id, **kwargs)
LOGGER.debug('Notification configuration required for %s', map_params['name'])
stack = core.Stack.of(self)
stack = Stack.of(self)
# pylint: disable=no-value-for-parameter
_slack_func = _lambda.Function.from_function_arn(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import os

from aws_cdk import (
aws_codepipeline as _codepipeline,
core
aws_codepipeline as _codepipeline
)
from constructs import Construct

from cdk_constructs.adf_codepipeline import Action

Expand All @@ -18,8 +18,8 @@
ADF_DEFAULT_BUILD_TIMEOUT = 20


class S3(core.Construct):
def __init__(self, scope: core.Construct, id: str, map_params: dict, **kwargs): #pylint: disable=W0622
class S3(Construct):
def __init__(self, scope: Construct, id: str, map_params: dict, **kwargs): #pylint: disable=W0622
super().__init__(scope, id, **kwargs)
self.source = _codepipeline.CfnPipeline.StageDeclarationProperty(
name="Source-S3",
Expand Down
Loading

0 comments on commit 9873e03

Please sign in to comment.