Skip to content

Commit 567bb0f

Browse files
committed
Merge branch 'feature/pipeline-improvement' into 'develop'
## Pipeline Improvements See merge request genaiic-reusable-assets/engagement-artifacts/genaiic-idp-accelerator!408
2 parents 446e873 + bc3539b commit 567bb0f

File tree

5 files changed

+42
-72
lines changed

5 files changed

+42
-72
lines changed

.gitlab-ci.yml

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ deployment_validation:
9595
integration_tests:
9696
stage: integration_tests
9797
timeout: 2h
98+
variables:
99+
IDP_ADMIN_EMAIL: ${GITLAB_USER_EMAIL}
98100
# variables:
99101
# # In order to run tests in another account, add a AWS_CREDS_TARGET_ROLE variable to the Gitlab pipeline variables.
100102
# AWS_CREDS_TARGET_ROLE: ${AWS_CREDS_TARGET_ROLE}
@@ -138,41 +140,32 @@ integration_tests:
138140
- python3 scripts/integration_test_deployment.py
139141

140142
after_script:
141-
# Capture CodeBuild logs using the tracked execution ID
143+
# Display CodeBuild logs directly in GitLab runner console
142144
- |
143-
echo "=== IDP Pipeline Results ===" > pipeline_summary.txt
144-
echo "Branch: $CI_COMMIT_REF_NAME" >> pipeline_summary.txt
145-
echo "Commit: $CI_COMMIT_SHA" >> pipeline_summary.txt
146-
echo "Status: $CI_JOB_STATUS" >> pipeline_summary.txt
147-
echo "" >> pipeline_summary.txt
148-
149-
# Get CodeBuild logs using the exact execution ID from Python script
150145
if [ -f "pipeline_execution_id.txt" ]; then
151146
EXECUTION_ID=$(cat pipeline_execution_id.txt)
152-
echo "Pipeline Execution: $EXECUTION_ID" >> pipeline_summary.txt
153-
echo "" >> pipeline_summary.txt
147+
echo "Pipeline Execution: $EXECUTION_ID"
154148
155149
# Get CodeBuild ID from the pipeline execution
156150
BUILD_ID=$(aws codepipeline list-action-executions --pipeline-name ${IDP_PIPELINE_NAME:-idp-sdlc-deploy-pipeline} --filter pipelineExecutionId=$EXECUTION_ID --query 'actionExecutionDetails[?actionName==`BuildAction`].output.executionResult.externalExecutionId' --output text 2>/dev/null || echo "")
157151
158152
if [ "$BUILD_ID" != "" ] && [ "$BUILD_ID" != "None" ]; then
159-
echo "CodeBuild ID: $BUILD_ID" >> pipeline_summary.txt
153+
echo "CodeBuild ID: $BUILD_ID"
160154
# Extract just the build ID part (after the colon)
161155
LOG_STREAM_NAME="${BUILD_ID#*:}"
162-
echo "Log Stream: $LOG_STREAM_NAME" >> pipeline_summary.txt
163-
echo "" >> pipeline_summary.txt
164-
echo "=== CODEBUILD LOGS ===" >> pipeline_summary.txt
165-
aws logs get-log-events --log-group-name "/aws/codebuild/app-sdlc" --log-stream-name "$LOG_STREAM_NAME" --limit 100 --query 'events[].message' --output text 2>/dev/null >> pipeline_summary.txt || echo "Could not retrieve CodeBuild logs" >> pipeline_summary.txt
156+
echo "Log Stream: $LOG_STREAM_NAME"
157+
echo ""
158+
echo "=== CODEBUILD LOGS ==="
159+
aws logs get-log-events --log-group-name "/aws/codebuild/app-sdlc" --log-stream-name "$LOG_STREAM_NAME" --start-from-head --query 'events[].message' --output text 2>/dev/null || echo "Could not retrieve CodeBuild logs"
166160
else
167-
echo "Could not find CodeBuild execution" >> pipeline_summary.txt
161+
echo "Could not find CodeBuild execution"
168162
fi
169163
else
170-
echo "No pipeline execution ID found" >> pipeline_summary.txt
164+
echo "No pipeline execution ID found"
171165
fi
172166
173167
artifacts:
174168
when: always
175169
paths:
176-
- pipeline_summary.txt
177170
- pipeline_execution_id.txt
178171
expire_in: 1 week

scripts/codebuild_deployment.py

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def publish_templates():
9797
sys.exit(1)
9898

9999

100-
def deploy_and_test_pattern(stack_prefix, pattern_config, admin_email, template_url):
100+
def deploy_test_and_cleanup_pattern(stack_prefix, pattern_config, admin_email, template_url):
101101
"""Deploy and test a specific IDP pattern"""
102102
pattern_name = pattern_config["name"]
103103
pattern_id = pattern_config["id"]
@@ -195,28 +195,35 @@ def deploy_and_test_pattern(stack_prefix, pattern_config, admin_email, template_
195195
print(
196196
f"[{pattern_name}] ✅ Found expected verification string: '{verify_string}'"
197197
)
198-
return {
198+
199+
success_result = {
199200
"stack_name": stack_name,
200201
"pattern_name": pattern_name,
201202
"success": True,
202203
}
203204

204205
except Exception as e:
205206
print(f"[{pattern_name}] ❌ Failed to validate result content: {e}")
206-
return {
207+
success_result = {
207208
"stack_name": stack_name,
208209
"pattern_name": pattern_name,
209210
"success": False,
210211
}
211212

212213
except Exception as e:
213214
print(f"[{pattern_name}] ❌ Testing failed: {e}")
214-
return {
215+
success_result = {
215216
"stack_name": stack_name,
216217
"pattern_name": pattern_name,
217218
"success": False,
218219
}
219220

221+
# Always cleanup the stack regardless of success/failure
222+
finally:
223+
cleanup_stack(stack_name, pattern_name)
224+
225+
return success_result
226+
220227

221228
def cleanup_stack(stack_name, pattern_name):
222229
"""Clean up a deployed stack"""
@@ -274,16 +281,15 @@ def main():
274281
# Step 1: Publish templates to S3
275282
template_url = publish_templates()
276283

277-
deployed_stacks = []
278284
all_success = True
279285

280-
# Step 2: Deploy and test patterns concurrently
286+
# Step 2: Deploy, test, and cleanup patterns concurrently
281287
print("🚀 Starting concurrent deployment of all patterns...")
282288
with ThreadPoolExecutor(max_workers=len(DEPLOY_PATTERNS)) as executor:
283289
# Submit all deployment tasks
284290
future_to_pattern = {
285291
executor.submit(
286-
deploy_and_test_pattern,
292+
deploy_test_and_cleanup_pattern,
287293
stack_prefix,
288294
pattern_config,
289295
admin_email,
@@ -292,33 +298,22 @@ def main():
292298
for pattern_config in DEPLOY_PATTERNS
293299
}
294300

295-
# Collect results as they complete
301+
# Collect results as they complete (cleanup happens within each pattern)
296302
for future in as_completed(future_to_pattern):
297303
pattern_config = future_to_pattern[future]
298304
try:
299305
result = future.result()
300-
deployed_stacks.append(result)
301306
if not result["success"]:
302307
all_success = False
303308
print(f"[{pattern_config['name']}] ❌ Failed")
304309
else:
305310
print(f"[{pattern_config['name']}] ✅ Success")
311+
306312
except Exception as e:
307313
print(f"[{pattern_config['name']}] ❌ Exception: {e}")
308314
all_success = False
309315

310-
# Step 3: Cleanup all stacks concurrently
311-
print("🧹 Starting concurrent cleanup of all stacks...")
312-
with ThreadPoolExecutor(max_workers=len(deployed_stacks)) as executor:
313-
cleanup_futures = [
314-
executor.submit(cleanup_stack, result["stack_name"], result["pattern_name"])
315-
for result in deployed_stacks
316-
]
317-
318-
# Wait for all cleanups to complete
319-
for future in as_completed(cleanup_futures):
320-
future.result() # Wait for completion
321-
316+
# Check final status after all cleanups are done
322317
if all_success:
323318
print("🎉 All pattern deployments completed successfully!")
324319
sys.exit(0)

scripts/integration_test_deployment.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,20 @@ def upload_to_s3(bucket_name):
7979
s3_client = boto3.client("s3")
8080

8181
try:
82+
# Get GitLab user email to pass to CodeBuild
83+
gitlab_user_email = os.environ.get("GITLAB_USER_EMAIL", "")
84+
85+
# Add metadata to pass email to CodeBuild
86+
metadata = {}
87+
if gitlab_user_email:
88+
metadata["gitlab-user-email"] = gitlab_user_email
89+
print(f"Adding GitLab user email to metadata: {gitlab_user_email}")
90+
8291
response = s3_client.put_object(
8392
Bucket=bucket_name,
8493
Key="deploy/code.zip",
8594
Body=open("./dist/code.zip", "rb"),
95+
Metadata=metadata,
8696
)
8797
version_id = response.get("VersionId", "unknown")
8898
print(f"✅ Uploaded with version ID: {version_id}")

scripts/sdlc/cfn/codepipeline-s3.yml

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -159,42 +159,13 @@ Resources:
159159
commands:
160160
- n 22 && node --version || { echo "Node setup failed"; exit 1; }
161161
- npm install -g aws-cdk || { echo "CDK installation failed"; exit 1; }
162-
# Check which deployment method to use
163-
- |
164-
if [ -d "./scripts/sdlc/idp-cli" ]; then
165-
echo "Using legacy poetry-based deployment"
166-
curl -sSL https://install.python-poetry.org | python3 - || { echo "Poetry installation failed"; exit 1; }
167-
export PATH="/root/.local/bin:$PATH"
168-
cd ./scripts/sdlc/idp-cli
169-
poetry install || { echo "Poetry dependencies installation failed"; exit 1; }
170-
cd ../../..
171-
else
172-
echo "Using new idp-cli deployment"
173-
cd idp_cli && pip install -e . && cd .. || { echo "IDP CLI installation failed"; exit 1; }
174-
fi
162+
- export IDP_ADMIN_EMAIL=$(aws s3api head-object --bucket idp-sdlc-sourcecode-${AWS_ACCOUNT_ID:-020432867916}-${AWS_DEFAULT_REGION:-us-east-1} --key deploy/code.zip --query 'Metadata."gitlab-user-email"' --output text 2>/dev/null || echo "")
163+
- cd idp_cli && pip install -e . && cd .. || { echo "IDP CLI installation failed"; exit 1; }
175164
build:
176165
commands:
177-
- |
178-
if [ -d "./scripts/sdlc/idp-cli" ]; then
179-
echo "Running legacy poetry-based build"
180-
cd ./scripts/sdlc/idp-cli
181-
export IDP_CFN_PREFIX=$(make cfn-prefix) || { echo "CFN prefix generation failed"; exit 1; }
182-
make install -e IDP_CFN_PREFIX=$IDP_CFN_PREFIX
183-
make smoketest -e IDP_CFN_PREFIX=$IDP_CFN_PREFIX
184-
else
185-
echo "Running codebuild deployment script"
186-
python3 scripts/codebuild_deployment.py
187-
fi
166+
- python3 scripts/codebuild_deployment.py
188167
finally:
189-
- |
190-
if [ -d "./scripts/sdlc/idp-cli" ]; then
191-
echo "Running legacy cleanup"
192-
cd ./scripts/sdlc/idp-cli
193-
make uninstall -e IDP_CFN_PREFIX=$IDP_CFN_PREFIX || echo "Cleanup failed but continuing"
194-
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"
195-
else
196-
echo "Cleanup handled by codebuild deployment script"
197-
fi
168+
- echo "Cleanup handled by codebuild deployment script"
198169
199170
DeploymentPipeline:
200171
Type: 'AWS::CodePipeline::Pipeline'

scripts/sdlc/cfn/credential-vendor.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ Resources:
8282
- codepipeline:GetPipelineExecution
8383
- codepipeline:ListPipelineExecutions
8484
- codepipeline:ListPipelines
85+
- codepipeline:ListActionExecutions
8586
Resource: !Sub "arn:aws:codepipeline:*:${AWS::AccountId}:*"
8687
- PolicyName: CodeBuildAccessPolicy
8788
PolicyDocument:

0 commit comments

Comments
 (0)