Skip to content

Commit b516a3e

Browse files
committed
Merge branch 'feature/add-p2-pipeline' into 'develop'
Pipeline improvements for integrating idp-cli and cf role changes to support p2 See merge request genaiic-reusable-assets/engagement-artifacts/genaiic-idp-accelerator!372
2 parents f47118c + b3c9bae commit b516a3e

22 files changed

+611
-234
lines changed

.gitlab-ci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
# Any publicly available image
55
image: public.ecr.aws/docker/library/python:3.13-bookworm
66

7+
# Global timeout for all jobs
8+
default:
9+
timeout: 2h
10+
711
# Change pip's cache directory to be inside the project directory since we can
812
# only cache local items.
913
# variables:
@@ -51,6 +55,7 @@ developer_tests:
5155

5256
integration_tests:
5357
stage: integration_tests
58+
timeout: 2h
5459
# variables:
5560
# # In order to run tests in another account, add a AWS_CREDS_TARGET_ROLE variable to the Gitlab pipeline variables.
5661
# AWS_CREDS_TARGET_ROLE: ${AWS_CREDS_TARGET_ROLE}

iam-roles/cloudformation-management/IDP-Cloudformation-Service-Role.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ Resources:
5959
- iam:DeletePolicy
6060
- iam:GetPolicy
6161
- iam:ListPolicies
62+
- iam:ListPolicyVersions
63+
- iam:CreatePolicyVersion
64+
- iam:DeletePolicyVersion
65+
- iam:SetDefaultPolicyVersion
6266
- iam:AttachRolePolicy
6367
- iam:DetachRolePolicy
6468
- iam:PutRolePolicy
@@ -122,6 +126,7 @@ Resources:
122126
- ec2:DeleteTags
123127
- ec2:DescribeTags
124128
- ec2:DescribeAvailabilityZones
129+
- ecr:*
125130
Resource: '*'
126131

127132
PassRolePolicy:

scripts/sdlc/cfn/codepipeline-s3.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,10 @@ Resources:
168168
- export IDP_CFN_PREFIX=$(make cfn-prefix) || { echo "CFN prefix generation failed"; exit 1; }
169169
- make install -e IDP_CFN_PREFIX=$IDP_CFN_PREFIX
170170
- make smoketest -e IDP_CFN_PREFIX=$IDP_CFN_PREFIX
171-
- echo "All tests passed successfully, running cleanup..."
172-
- make uninstall -e IDP_CFN_PREFIX=$IDP_CFN_PREFIX && aws cloudformation delete-stack --stack-name ${IDP_CFN_PREFIX}-cloudformation-service-role --region us-east-1 || echo "Cleanup failed but continuing"
171+
finally:
172+
- echo "Running cleanup regardless of build result..."
173+
- make uninstall -e IDP_CFN_PREFIX=$IDP_CFN_PREFIX || echo "Cleanup failed but continuing"
174+
- make -n cli-smoketest >/dev/null 2>&1 && make cli-smoketest -e IDP_CFN_PREFIX=$IDP_CFN_PREFIX || echo "CLI smoketest target not found, skipping"
173175
174176
DeploymentPipeline:
175177
Type: 'AWS::CodePipeline::Pipeline'

scripts/sdlc/cfn/sdlc-iam-role.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ Resources:
9999
Properties:
100100
RoleName: !Ref BuilderRoleName
101101
Description: 'Role for application builders with PowerUser and Limited IAM access'
102+
MaxSessionDuration: 7200 # 2 hours for long-running CI/CD operations
102103
AssumeRolePolicyDocument:
103104
Version: '2012-10-17'
104105
Statement:

scripts/sdlc/idp-cli/Makefile

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ IDP_CFN_PREFIX?=idp-dev
1010
IDP_STACK_NAME?=$(IDP_CFN_PREFIX)
1111
IDP_PIPELINE_NAME?=idp-sdlc-deploy-pipeline
1212

13+
# Pattern-specific configurations
14+
IDP_PATTERN1_STACK_NAME?=$(IDP_CFN_PREFIX)-p1
15+
IDP_PATTERN2_STACK_NAME?=$(IDP_CFN_PREFIX)-p2
16+
IDP_PATTERN1_NAME?=Pattern1 - Packet or Media processing with Bedrock Data Automation (BDA)
17+
IDP_PATTERN2_NAME?=Pattern2 - OCR → Bedrock Classification (page-level or holistic) → Bedrock Extraction
18+
1319
test:
1420
poetry run pytest -s --log-cli-level=DEBUG
1521

@@ -27,20 +33,28 @@ install:
2733
uninstall:
2834
export S3UTIL_ALLOW_BUCKET_DESTRUCT=true && \
2935
poetry run idpcli uninstall \
30-
--stack-name=$(IDP_STACK_NAME) \
36+
--stack-name-prefix=$(IDP_CFN_PREFIX) \
3137
--account-id=$(IDP_ACCOUNT_ID) \
3238
--cfn-prefix=$(IDP_CFN_PREFIX)
33-
# Clean up CloudWatch Logs resource policy after uninstall
34-
cd $(IDP_CWD) && python3 scripts/cleanup-logs.py || echo "Log cleanup failed but continuing" \
39+
cd $(IDP_CWD) && python3 scripts/cleanup-logs.py || echo "Log cleanup failed but continuing"
3540

3641
smoketest:
3742
poetry run idpcli smoketest \
38-
--stack-name=$(IDP_STACK_NAME)
43+
--stack-name-prefix=$(IDP_CFN_PREFIX) \
44+
--file-path="../../../samples/lending_package.pdf"
45+
46+
cli-smoketest:
47+
poetry run idpcli idp-cli-smoketest \
48+
--cfn-prefix=$(IDP_CFN_PREFIX) \
49+
--admin-email=$(IDP_ADMIN_EMAIL) \
50+
--account-id=$(IDP_ACCOUNT_ID) \
51+
--cwd=$(IDP_CWD)
52+
3953

4054
wait:
4155
$(eval VERSION_ID := $(shell cat $(IDP_CWD)/.upload_version_id 2>/dev/null || echo ""))
4256
@if [ -z "$(VERSION_ID)" ]; then echo "Error: No version ID found"; exit 1; fi
43-
$(eval EXECUTION_ID := $(shell poetry run python -c "from idp_cli.util.codepipeline_util import CodePipelineUtil; print(CodePipelineUtil.get_execution_id_by_version('$(IDP_PIPELINE_NAME)', '$(VERSION_ID)'))" || echo "FAILED"))
57+
$(eval EXECUTION_ID := $(shell poetry run python -c "from idpcli.util.codepipeline_util import CodePipelineUtil; print(CodePipelineUtil.get_execution_id_by_version('$(IDP_PIPELINE_NAME)', '$(VERSION_ID)'))" || echo "FAILED"))
4458
@if [ "$(EXECUTION_ID)" = "FAILED" ]; then echo "Error: Failed to find pipeline execution for version $(VERSION_ID)"; exit 1; fi
4559
poetry run idpcli monitor-pipeline \
4660
--pipeline-name=$(IDP_PIPELINE_NAME) \

scripts/sdlc/idp-cli/pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ dependencies = [
1919
]
2020

2121
[tool.poetry]
22-
packages = [{include = "idp_cli", from = "src"}]
22+
packages = [{include = "idpcli", from = "src"}]
2323

2424
[tool.poetry.scripts]
25-
idpcli = "idp_cli.cli.main:app"
25+
idpcli = "idpcli.cli.main:app"
2626

2727
[tool.poetry.group.dev.dependencies]
2828
ipykernel = "^6.29.5"

scripts/sdlc/idp-cli/src/idp_cli/service/uninstall_service.py

Lines changed: 0 additions & 102 deletions
This file was deleted.
File renamed without changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: MIT-0

scripts/sdlc/idp-cli/src/idp_cli/cli/main.py renamed to scripts/sdlc/idp-cli/src/idpcli/cli/main.py

Lines changed: 58 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33

44
import os
55
import sys
6-
from idp_cli.service.install_service import InstallService
7-
from idp_cli.util.codepipeline_util import CodePipelineUtil
6+
from idpcli.service.install_service import InstallService
7+
from idpcli.util.codepipeline_util import CodePipelineUtil
88
import typer
9-
from idp_cli.service.uninstall_service import UninstallService
10-
from idp_cli.service.smoketest_service import SmokeTestService
9+
from idpcli.service.uninstall_service import UninstallService
10+
from idpcli.service.smoketest_service import SmokeTestService
11+
from idpcli.service.smoketest_idp_cli_service import SmokeTestIdpCliService
1112
from dotenv import load_dotenv
1213

1314
from loguru import logger
@@ -28,7 +29,6 @@ def install(
2829
account_id: str = typer.Option(..., "--account-id", help="AWS Account ID"),
2930
cfn_prefix: str = typer.Option("idp-dev", "--cfn-prefix", help="An identifier to prefix the stack"),
3031
admin_email: str = typer.Option(..., "--admin-email", help="The admin email"),
31-
idp_pattern: str = typer.Option("Pattern1 - Packet or Media processing with Bedrock Data Automation (BDA)", "--idp-pattern", help="The IDP Pattern to install"),
3232
cwd: str = typer.Option("./", "--cwd", help="Current working directory"),
3333
debug: bool = typer.Option(False, "--debug", help="Enable debug mode"),
3434
publish: bool = typer.Option(True, "--publish", help="Control publishing"),
@@ -43,27 +43,35 @@ def install(
4343
service.publish()
4444

4545
if deploy:
46-
service.install(admin_email=admin_email, idp_pattern=idp_pattern)
47-
typer.echo("Install Complete!")
46+
all_patterns_succeeded = service.install(admin_email=admin_email)
47+
if all_patterns_succeeded:
48+
typer.echo("Install Complete!")
49+
else:
50+
typer.echo("Install failed!", err=True)
51+
sys.exit(1)
4852

4953

5054
@app.command()
5155
def uninstall(
52-
stack_name: str = typer.Option(..., "--stack-name", help="Name of the stack to uninstall"),
56+
stack_name_prefix: str = typer.Option(..., "--stack-name-prefix", help="Prefix of the stacks to uninstall"),
5357
account_id: str = typer.Option(..., "--account-id", help="AWS Account ID"),
5458
cfn_prefix: str = typer.Option("idp-dev", "--cfn-prefix", help="An identifier to prefix the stack")
5559
):
5660
"""
5761
Uninstall IDP Accelerator
5862
"""
5963
try:
60-
typer.echo(f"Uninstalling stack: {stack_name}")
61-
62-
service = UninstallService(stack_name=stack_name, account_id=account_id, cfn_prefix=cfn_prefix)
64+
typer.echo(f"Uninstalling stacks with prefix: {stack_name_prefix}")
6365

64-
service.uninstall()
66+
service = UninstallService(stack_name_prefix=stack_name_prefix, account_id=account_id, cfn_prefix=cfn_prefix)
6567

66-
typer.echo("Uninstall Complete!")
68+
all_patterns_succeeded = service.uninstall()
69+
70+
if all_patterns_succeeded:
71+
typer.echo("Uninstall Complete!")
72+
else:
73+
typer.echo("Uninstall failed!", err=True)
74+
sys.exit(1)
6775
except Exception as e:
6876
logger.exception(f"Error during uninstall process: {str(e)}")
6977
typer.echo(f"Uninstall failed: {str(e)}", err=True)
@@ -72,26 +80,26 @@ def uninstall(
7280

7381
@app.command()
7482
def smoketest(
75-
stack_name: str = typer.Option("idp-Stack", "--stack-name", help="Name of the deployed stack to test"),
83+
stack_name_prefix: str = typer.Option("idp-Stack", "--stack-name-prefix", help="Prefix of the deployed stacks to test"),
7684
file_path: str = typer.Option("../../../samples/lending_package.pdf", "--file-path", help="Path to the test file"),
7785
verify_string: str = typer.Option("ANYTOWN, USA 12345", "--verify-string", help="String to verify in the processed output")
7886
):
7987
"""
80-
Run a smoke test on the deployed IDP Accelerator
88+
Run a smoke test on both deployed IDP patterns
8189
"""
8290
try:
83-
typer.echo(f"Running smoke test on stack: {stack_name}")
91+
typer.echo(f"Running smoke test on stacks with prefix: {stack_name_prefix}")
8492

8593
service = SmokeTestService(
86-
stack_name=stack_name,
94+
stack_name_prefix=stack_name_prefix,
8795
file_path=file_path,
8896
verify_string=verify_string
8997
)
9098

9199
result = service.do_smoketest()
92100

93101
if result:
94-
typer.echo("Smoke test passed successfully!")
102+
typer.echo("All smoke tests passed successfully!")
95103
else:
96104
typer.echo("Smoke test failed!", err=True)
97105
sys.exit(1)
@@ -100,6 +108,38 @@ def smoketest(
100108
typer.echo(f"Smoke test failed: {str(e)}", err=True)
101109
sys.exit(1)
102110

111+
@app.command()
112+
def idp_cli_smoketest(
113+
cfn_prefix: str = typer.Option(..., "--cfn-prefix", help="CloudFormation prefix for stack naming"),
114+
admin_email: str = typer.Option(..., "--admin-email", help="Admin email for deployment"),
115+
account_id: str = typer.Option(..., "--account-id", help="AWS account ID"),
116+
cwd: str = typer.Option("../../../", "--cwd", help="Working directory path")
117+
):
118+
"""
119+
End-to-end smoketest: install CLI, deploy stack, run inference, verify results
120+
"""
121+
try:
122+
typer.echo(f"Running IDP CLI smoketest with prefix: {cfn_prefix}")
123+
124+
service = SmokeTestIdpCliService(
125+
cfn_prefix=cfn_prefix,
126+
admin_email=admin_email,
127+
account_id=account_id,
128+
cwd=cwd
129+
)
130+
131+
result = service.do_smoketest()
132+
133+
if result:
134+
typer.echo("IDP CLI smoketest passed successfully!")
135+
else:
136+
typer.echo("IDP CLI smoketest failed!", err=True)
137+
sys.exit(1)
138+
except Exception as e:
139+
logger.exception(f"Error during IDP CLI smoketest: {str(e)}")
140+
typer.echo(f"IDP CLI smoketest failed: {str(e)}", err=True)
141+
sys.exit(1)
142+
103143
@app.command()
104144
def monitor_pipeline(
105145
pipeline_name: str = typer.Option(..., "--pipeline-name", help="Name of the CodePipeline to monitor"),

0 commit comments

Comments
 (0)