From f9ad4e5ad7ddd04f6f04fda6a8ce78e3929f2dbe Mon Sep 17 00:00:00 2001 From: Gregory Campbell Date: Sun, 14 Jun 2026 15:55:00 -0400 Subject: [PATCH] Added buildspac to get lambda implementation started --- buildspec.yml | 170 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 170 insertions(+) create mode 100644 buildspec.yml diff --git a/buildspec.yml b/buildspec.yml new file mode 100644 index 000000000..1d1d695c2 --- /dev/null +++ b/buildspec.yml @@ -0,0 +1,170 @@ +version: 0.2 + +env: + variables: + # Node.js version for React and infrastructure + NODE_VERSION: "18" + # Python version for Lambda functions + PYTHON_VERSION: "3.9" + # Go version for Lambda functions + GO_VERSION: "1.21" + # Rust version for Lambda functions + RUST_VERSION: "1.75.0" + +phases: + install: + runtime-versions: + nodejs: 18 + python: 3.9 + golang: 1.21 + commands: + - echo "Installing build dependencies..." + + # Install Rust + - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y + - source $HOME/.cargo/env + - rustup default $RUST_VERSION + - rustc --version + - cargo --version + + # Install AWS CDK globally + - npm install -g aws-cdk + + # Verify all runtime versions + - node --version + - npm --version + - python3 --version + - go version + - rustc --version + + pre_build: + commands: + - echo "Pre-build phase started on `date`" + + # Install React dependencies + - echo "Installing React dependencies..." + - npm ci + + # Install Python dependencies for Lambda functions + - echo "Installing Python dependencies..." + - cd functions/python + - pip3 install -r requirements.txt --target . + - cd ../.. + + # Download Go dependencies + - echo "Downloading Go dependencies..." + - cd functions/go + - go mod download + - go mod verify + - cd ../.. + + # Check Rust dependencies + - echo "Checking Rust dependencies..." + - cd functions/rust + - cargo check + - cd ../.. + + # Install CDK dependencies for infrastructure + - echo "Installing CDK dependencies..." + - npm ci + + build: + commands: + - echo "Build phase started on `date`" + + # Build React application + - echo "Building React application..." + - npm run build + + # Build Go Lambda function + - echo "Building Go Lambda function..." + - cd functions/go + - GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags="-s -w" -o bootstrap main.go + - zip go-lambda.zip bootstrap + - cd ../.. + + # Build Rust Lambda function + - echo "Building Rust Lambda function..." + - cd functions/rust + - cargo lambda build --release + - cd ../.. + + # Package Python Lambda function + - echo "Packaging Python Lambda function..." + - cd functions/python + - zip -r ../python-lambda.zip . -x "*.pyc" "__pycache__/*" + - cd ../.. + + # Run tests if they exist + - echo "Running tests..." + - | + if [ -f "package.json" ] && grep -q '"test"' package.json; then + npm test -- --coverage --ci --testResultsProcessor="jest-junit" --watchAll=false + fi + + # Build CDK infrastructure (synthesize CloudFormation templates) + - echo "Building CDK infrastructure..." + - npx cdk synth + + # Run linting and code quality checks + - echo "Running code quality checks..." + - | + if [ -f "package.json" ] && grep -q '"lint"' package.json; then + npm run lint + fi + + post_build: + commands: + - echo "Post-build phase started on `date`" + + # Create deployment package structure + - mkdir -p dist/react + - mkdir -p dist/lambdas + - mkdir -p dist/infrastructure + + # Copy React build artifacts + - cp -r build/* dist/react/ + + # Copy Lambda function packages + - cp functions/go/go-lambda.zip dist/lambdas/ + - cp functions/python-lambda.zip dist/lambdas/ + - | + if [ -f "functions/rust/target/lambda/rust-lambda/bootstrap.zip" ]; then + cp functions/rust/target/lambda/rust-lambda/bootstrap.zip dist/lambdas/rust-lambda.zip + fi + + # Copy CDK synthesized templates + - cp -r cdk.out/* dist/infrastructure/ + + # Generate build info + - echo "{\"buildTime\":\"$(date -u +%Y-%m-%dT%H:%M:%SZ)\",\"commitHash\":\"$CODEBUILD_RESOLVED_SOURCE_VERSION\"}" > dist/build-info.json + + - echo "Build completed successfully on `date`" + +reports: + jest_reports: + files: + - junit.xml + base-directory: . + file-format: JUNITXML + coverage_reports: + files: + - clover.xml + base-directory: coverage + file-format: CLOVERXML + +artifacts: + files: + - '**/*' + base-directory: dist + name: personal-site-build-$(date +%Y-%m-%d-%H-%M-%S) + +cache: + paths: + - node_modules/**/* + - functions/go/go.mod + - functions/go/go.sum + - functions/rust/target/**/* + - ~/.cargo/**/* + - ~/.npm/**/* + - ~/.cache/pip/**/*