Updated buildspec
This commit is contained in:
+125
-80
@@ -2,12 +2,13 @@ version: 0.2
|
|||||||
|
|
||||||
env:
|
env:
|
||||||
variables:
|
variables:
|
||||||
# Node.js version for React and infrastructure
|
# Runtime versions
|
||||||
NODE_VERSION: "18"
|
NODE_VERSION: "18"
|
||||||
# Python version for Lambda functions
|
|
||||||
PYTHON_VERSION: "3.9"
|
PYTHON_VERSION: "3.9"
|
||||||
# Go version for Lambda functions
|
|
||||||
GO_VERSION: "1.21"
|
GO_VERSION: "1.21"
|
||||||
|
# Build configuration
|
||||||
|
BUILD_ENV: "production"
|
||||||
|
RUST_BACKTRACE: "1"
|
||||||
|
|
||||||
phases:
|
phases:
|
||||||
install:
|
install:
|
||||||
@@ -18,126 +19,170 @@ phases:
|
|||||||
commands:
|
commands:
|
||||||
- echo "Installing build dependencies..."
|
- echo "Installing build dependencies..."
|
||||||
|
|
||||||
# Install Rust
|
# Install Rust with error handling
|
||||||
- curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
|
- |
|
||||||
- source $HOME/.cargo/env
|
if ! command -v rustc &> /dev/null; then
|
||||||
- rustup update stable
|
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
|
||||||
- rustc --version
|
source $HOME/.cargo/env
|
||||||
- cargo --version
|
rustup update stable
|
||||||
|
fi
|
||||||
|
|
||||||
# Install AWS CDK globally
|
# Install AWS CDK globally
|
||||||
- npm install -g aws-cdk
|
- npm install -g aws-cdk@latest
|
||||||
|
|
||||||
# Verify all runtime versions
|
# Verify runtime versions
|
||||||
|
- echo "=== Runtime Versions ==="
|
||||||
- node --version
|
- node --version
|
||||||
- npm --version
|
- npm --version
|
||||||
- python3 --version
|
- python3 --version
|
||||||
- go version
|
- go version
|
||||||
- rustc --version
|
- rustc --version || echo "Rust not available"
|
||||||
|
- cdk --version
|
||||||
|
|
||||||
pre_build:
|
pre_build:
|
||||||
commands:
|
commands:
|
||||||
- echo "Pre-build phase started on `date`"
|
- echo "Pre-build phase started on $(date)"
|
||||||
|
|
||||||
# Install React dependencies
|
# Install React dependencies with clean install
|
||||||
- echo "Installing React dependencies..."
|
- echo "Installing React dependencies..."
|
||||||
- npm ci
|
- npm ci --prefer-offline --no-audit
|
||||||
|
|
||||||
# Install Python dependencies for Lambda functions
|
# Install Python dependencies for Lambda functions
|
||||||
- echo "Installing Python dependencies..."
|
- |
|
||||||
- cd functions/python
|
if [ -d "functions/python" ] && [ -f "functions/python/requirements.txt" ]; then
|
||||||
- pip3 install -r requirements.txt --target .
|
echo "Installing Python dependencies..."
|
||||||
- cd ../..
|
cd functions/python
|
||||||
|
pip3 install -r requirements.txt --target . --upgrade --no-cache-dir
|
||||||
|
cd ../..
|
||||||
|
else
|
||||||
|
echo "No Python Lambda function found, skipping..."
|
||||||
|
fi
|
||||||
|
|
||||||
# Download Go dependencies
|
# Download Go dependencies
|
||||||
- echo "Downloading Go dependencies..."
|
- |
|
||||||
- cd functions/go
|
if [ -d "functions/go" ] && [ -f "functions/go/go.mod" ]; then
|
||||||
- go mod download
|
echo "Downloading Go dependencies..."
|
||||||
- go mod verify
|
cd functions/go
|
||||||
- cd ../..
|
go mod download
|
||||||
|
go mod verify
|
||||||
|
cd ../..
|
||||||
|
else
|
||||||
|
echo "No Go Lambda function found, skipping..."
|
||||||
|
fi
|
||||||
|
|
||||||
# Check Rust dependencies
|
# Check Rust dependencies
|
||||||
- echo "Checking Rust dependencies..."
|
- |
|
||||||
- cd functions/rust
|
if [ -d "functions/rust" ] && [ -f "functions/rust/Cargo.toml" ]; then
|
||||||
- cargo check
|
echo "Checking Rust dependencies..."
|
||||||
- cd ../..
|
cd functions/rust
|
||||||
|
cargo check --release
|
||||||
# Install CDK dependencies for infrastructure
|
cd ../..
|
||||||
- echo "Installing CDK dependencies..."
|
else
|
||||||
- npm ci
|
echo "No Rust Lambda function found, skipping..."
|
||||||
|
fi
|
||||||
|
|
||||||
build:
|
build:
|
||||||
commands:
|
commands:
|
||||||
- echo "Build phase started on `date`"
|
- echo "Build phase started on $(date)"
|
||||||
|
|
||||||
|
# Run linting and code quality checks early
|
||||||
|
- |
|
||||||
|
if [ -f "package.json" ] && grep -q '"lint"' package.json; then
|
||||||
|
echo "Running code quality checks..."
|
||||||
|
npm run lint
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Run tests before building
|
||||||
|
- |
|
||||||
|
if [ -f "package.json" ] && grep -q '"test"' package.json; then
|
||||||
|
echo "Running tests..."
|
||||||
|
npm test -- --coverage --ci --testResultsProcessor="jest-junit" --watchAll=false
|
||||||
|
fi
|
||||||
|
|
||||||
# Build React application
|
# Build React application
|
||||||
- echo "Building React application..."
|
- echo "Building React application..."
|
||||||
- npm run build
|
- npm run build
|
||||||
|
|
||||||
|
# Build Lambda functions in parallel where possible
|
||||||
|
- echo "Building Lambda functions..."
|
||||||
|
|
||||||
# Build Go Lambda function
|
# Build Go Lambda function
|
||||||
- echo "Building Go Lambda function..."
|
- |
|
||||||
- cd functions/go
|
if [ -d "functions/go" ]; then
|
||||||
- GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags="-s -w" -o bootstrap main.go
|
echo "Building Go Lambda function..."
|
||||||
- zip go-lambda.zip bootstrap
|
cd functions/go
|
||||||
- cd ../..
|
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags="-s -w" -o bootstrap main.go
|
||||||
|
zip -9 go-lambda.zip bootstrap
|
||||||
|
cd ../..
|
||||||
|
fi
|
||||||
|
|
||||||
# Build Rust Lambda function
|
# Build Rust Lambda function
|
||||||
- echo "Building Rust Lambda function..."
|
- |
|
||||||
- cd functions/rust
|
if [ -d "functions/rust" ]; then
|
||||||
- cargo lambda build --release
|
echo "Building Rust Lambda function..."
|
||||||
- cd ../..
|
cd functions/rust
|
||||||
|
if command -v cargo-lambda &> /dev/null; then
|
||||||
|
cargo lambda build --release
|
||||||
|
else
|
||||||
|
cargo install cargo-lambda
|
||||||
|
cargo lambda build --release
|
||||||
|
fi
|
||||||
|
cd ../..
|
||||||
|
fi
|
||||||
|
|
||||||
# Package Python Lambda function
|
# 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
|
if [ -d "functions/python" ]; then
|
||||||
npm test -- --coverage --ci --testResultsProcessor="jest-junit" --watchAll=false
|
echo "Packaging Python Lambda function..."
|
||||||
|
cd functions/python
|
||||||
|
zip -r9 ../python-lambda.zip . -x "*.pyc" "__pycache__/*" "*.git*" "*.DS_Store*"
|
||||||
|
cd ../..
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Build CDK infrastructure (synthesize CloudFormation templates)
|
# Build CDK infrastructure
|
||||||
- echo "Building CDK infrastructure..."
|
- echo "Synthesizing CDK infrastructure..."
|
||||||
- npx cdk synth
|
- npx cdk synth --all
|
||||||
|
|
||||||
# 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:
|
post_build:
|
||||||
commands:
|
commands:
|
||||||
- echo "Post-build phase started on `date`"
|
- echo "Post-build phase started on $(date)"
|
||||||
|
|
||||||
# Create deployment package structure
|
# Create deployment package structure
|
||||||
- mkdir -p dist/react
|
- mkdir -p dist/{react,lambdas,infrastructure}
|
||||||
- mkdir -p dist/lambdas
|
|
||||||
- mkdir -p dist/infrastructure
|
|
||||||
|
|
||||||
# Copy React build artifacts
|
# 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
|
if [ -d "build" ]; then
|
||||||
cp functions/rust/target/lambda/rust-lambda/bootstrap.zip dist/lambdas/rust-lambda.zip
|
cp -r build/* dist/react/
|
||||||
|
else
|
||||||
|
echo "No React build directory found"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Copy Lambda function packages
|
||||||
|
- |
|
||||||
|
[ -f "functions/go/go-lambda.zip" ] && cp functions/go/go-lambda.zip dist/lambdas/
|
||||||
|
[ -f "functions/python-lambda.zip" ] && cp functions/python-lambda.zip dist/lambdas/
|
||||||
|
[ -f "functions/rust/target/lambda/rust-lambda/bootstrap.zip" ] && cp functions/rust/target/lambda/rust-lambda/bootstrap.zip dist/lambdas/rust-lambda.zip
|
||||||
|
|
||||||
# Copy CDK synthesized templates
|
# Copy CDK synthesized templates
|
||||||
- cp -r cdk.out/* dist/infrastructure/
|
- |
|
||||||
|
if [ -d "cdk.out" ]; then
|
||||||
|
cp -r cdk.out/* dist/infrastructure/
|
||||||
|
fi
|
||||||
|
|
||||||
# Generate build info
|
# Generate build metadata
|
||||||
- echo "{\"buildTime\":\"$(date -u +%Y-%m-%dT%H:%M:%SZ)\",\"commitHash\":\"$CODEBUILD_RESOLVED_SOURCE_VERSION\"}" > dist/build-info.json
|
- |
|
||||||
|
cat > dist/build-info.json << EOF
|
||||||
|
{
|
||||||
|
"buildTime": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
|
||||||
|
"commitHash": "${CODEBUILD_RESOLVED_SOURCE_VERSION:-unknown}",
|
||||||
|
"buildId": "${CODEBUILD_BUILD_ID:-unknown}",
|
||||||
|
"projectName": "${CODEBUILD_BUILD_PROJECT_NAME:-unknown}",
|
||||||
|
"buildNumber": "${CODEBUILD_BUILD_NUMBER:-unknown}"
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
|
||||||
- echo "Build completed successfully on `date`"
|
- echo "Build completed successfully on $(date)"
|
||||||
|
|
||||||
reports:
|
reports:
|
||||||
jest_reports:
|
jest_reports:
|
||||||
@@ -155,14 +200,14 @@ artifacts:
|
|||||||
files:
|
files:
|
||||||
- '**/*'
|
- '**/*'
|
||||||
base-directory: dist
|
base-directory: dist
|
||||||
name: personal-site-build-$(date +%Y-%m-%d-%H-%M-%S)
|
name: personal-site-build-$CODEBUILD_BUILD_NUMBER
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
paths:
|
paths:
|
||||||
- node_modules/**/*
|
- node_modules/**/*
|
||||||
|
- ~/.npm/**/*
|
||||||
|
- ~/.cache/pip/**/*
|
||||||
|
- ~/.cargo/**/*
|
||||||
- functions/go/go.mod
|
- functions/go/go.mod
|
||||||
- functions/go/go.sum
|
- functions/go/go.sum
|
||||||
- functions/rust/target/**/*
|
- functions/rust/target/**/*
|
||||||
- ~/.cargo/**/*
|
|
||||||
- ~/.npm/**/*
|
|
||||||
- ~/.cache/pip/**/*
|
|
||||||
|
|||||||
Reference in New Issue
Block a user