Skip to content

Commit

Permalink
Merge pull request #5 from LokoMoloko98:Codebuild
Browse files Browse the repository at this point in the history
Refactor CodeBuild configuration to use external buildspec file and add environment variable for shared artifacts bucket
  • Loading branch information
LokoMoloko98 authored Dec 19, 2024
2 parents 165fe3b + b0cf37d commit 82cc389
Showing 1 changed file with 5 additions and 26 deletions.
31 changes: 5 additions & 26 deletions codebuild/codebuild.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,7 @@ resource "aws_codebuild_project" "lambdius-constructum-continua-artifacts_codebu
type = "GITHUB"
location = "https://github.com/LokoMoloko98/mea-munera-lambda.git"
git_clone_depth = 1
buildspec = <<-EOF
version: 0.2
phases:
install:
commands:
pre_build:
commands:
- echo "Detecting changes in the repository..."
- export CHANGED_DIRS=$(git diff --name-only HEAD~1 HEAD | awk -F'/' '{print $1}' | sort -u | uniq)
- echo "Changed directories: $CHANGED_DIRS
build:
commands:
- for DIR in $CHANGED_DIRS; do
echo "Processing $DIR...";
cd $DIR;
pip install -r requirements.txt -t .; # Install requirements into the directory
zip -r function.zip .; # Zip the entire directory
version=$(date +%Y%m%d%H%M%S)
aws s3 cp function.zip s3://${var.shared_artifacts_bucket}/lambda/$DIR/function-$version.zip; # Upload zip to S3
cd ..;
done
post_build:
commands:
EOF
buildspec = "buildspec.yaml"
}

artifacts {
Expand All @@ -45,6 +20,10 @@ resource "aws_codebuild_project" "lambdius-constructum-continua-artifacts_codebu
compute_type = "BUILD_GENERAL1_SMALL"
image = "aws/codebuild/standard:6.0"
type = "LINUX_CONTAINER"
environment_variable {
name = "SHARED_ARTIFACTS_BUCKET"
value = var.shared_artifacts_bucket
}
}

tags = {
Expand Down

0 comments on commit 82cc389

Please sign in to comment.