-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathbuildspec-router.yml
More file actions
52 lines (45 loc) · 2.1 KB
/
buildspec-router.yml
File metadata and controls
52 lines (45 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
version: 0.2
# This is a router buildspec that can dynamically run different build processes
# based on environment variables set in the CodeBuild project.
#
# Example usage:
# - Set BUILD_TYPE=cdk and STACK_NAME=SQLAgentStack in the CodeBuild project to build CDK stack
# - Set BUILD_TYPE=lambda, LAMBDA_LANGUAGE=python, and LAMBDA_DIR=lambda/tools/db-interface to build a Lambda function
phases:
install:
runtime-versions:
python: 3.9
commands:
# Determine which buildspec to use based on environment variables
- |
if [ "$BUILD_TYPE" = "cdk" ]; then
echo "Running CDK stack build for $STACK_NAME"
cp buildspec-templates/cdk/buildspec-template.yml buildspec-temp.yml
# Replace placeholder values
sed -i "s/STACK_NAME/$STACK_NAME/g" buildspec-temp.yml
sed -i "s/STACK_NAME_LOWERCASE/${STACK_NAME,,}/g" buildspec-temp.yml
elif [ "$BUILD_TYPE" = "lambda" ]; then
echo "Running Lambda build for $LAMBDA_LANGUAGE function in $LAMBDA_DIR"
cp buildspec-templates/lambda/buildspec-${LAMBDA_LANGUAGE}-lambda.yml buildspec-temp.yml
# Replace placeholder values
sed -i "s|LAMBDA_DIR|$LAMBDA_DIR|g" buildspec-temp.yml
LAMBDA_NAME=$(basename "$LAMBDA_DIR")
sed -i "s/LAMBDA_NAME/$LAMBDA_NAME/g" buildspec-temp.yml
elif [ "$BUILD_TYPE" = "lambda-extension" ]; then
echo "Running Lambda extension build"
cp buildspec-templates/lambda/buildspec-lambda-extension.yml buildspec-temp.yml
else
echo "Error: Unknown BUILD_TYPE: $BUILD_TYPE"
exit 1
fi
# Debug: Show the generated buildspec
- cat buildspec-temp.yml
# Execute the generated buildspec
- buildspec-exec buildspec-temp.yml
build:
commands:
- echo "This build phase doesn't run - execution is delegated to the generated buildspec"
post_build:
commands:
- echo "This post_build phase doesn't run - execution is delegated to the generated buildspec"
# Note: The artifacts will be collected by the executed buildspec