Reverted back to this repo being only for the react app, nothing else
This commit is contained in:
@@ -31,66 +31,11 @@ jobs:
|
|||||||
|
|
||||||
- name: Run Tests
|
- name: Run Tests
|
||||||
run: npm test -- --watchAll=false
|
run: npm test -- --watchAll=false
|
||||||
|
|
||||||
go-build:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checkout source
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Setup Go
|
|
||||||
uses: actions/setup-go@v5
|
|
||||||
with:
|
|
||||||
go-version: '1.22'
|
|
||||||
|
|
||||||
- name: Build Go service
|
|
||||||
working-directory: functions/go
|
|
||||||
run: go build
|
|
||||||
|
|
||||||
- name: Deploy placeholder
|
|
||||||
run: echo "Deploy the Go function to AWS Lambda from this step."
|
|
||||||
|
|
||||||
rust-build:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checkout source
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Setup Rust
|
|
||||||
uses: dtolnay/rust-toolchain@stable
|
|
||||||
|
|
||||||
- name: Build Rust service
|
|
||||||
working-directory: functions/rust
|
|
||||||
run: cargo build --release
|
|
||||||
|
|
||||||
- name: Deploy placeholder
|
|
||||||
run: echo "Deploy the Rust function to AWS Lambda from this step."
|
|
||||||
|
|
||||||
python-build:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checkout source
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Setup Python
|
|
||||||
uses: actions/setup-python@v5
|
|
||||||
with:
|
|
||||||
python-version: '3.11'
|
|
||||||
|
|
||||||
- name: Install dependencies
|
|
||||||
working-directory: functions/python
|
|
||||||
run: pip3 install -r requirements.txt
|
|
||||||
|
|
||||||
- name: Deploy placeholder
|
|
||||||
run: echo "Deploy the Python function to AWS Lambda with Mangum from this step."
|
|
||||||
|
|
||||||
# Deployment (Waits for manual approval after all build jobs pass)
|
# Deployment (Waits for manual approval after all build jobs pass)
|
||||||
deploy:
|
deploy:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: [react-build, go-build, rust-build, python-build]
|
needs: [react-build]
|
||||||
environment: production
|
environment: production
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
|||||||
@@ -1,197 +0,0 @@
|
|||||||
.PHONY: build-go build-rust build-python build-all clean test deploy help install-deps check-deps
|
|
||||||
|
|
||||||
# Variables
|
|
||||||
DIST_DIR := dist
|
|
||||||
GO_FUNCTIONS := $(wildcard functions/go/*/main.go)
|
|
||||||
RUST_FUNCTIONS := $(wildcard functions/rust/*/Cargo.toml)
|
|
||||||
PYTHON_FUNCTIONS := $(wildcard functions/python/*/lambda_function.py)
|
|
||||||
|
|
||||||
# Detect Python command
|
|
||||||
PYTHON := $(shell command -v python3 2> /dev/null || command -v python 2> /dev/null)
|
|
||||||
PIP := $(shell command -v pip3 2> /dev/null || command -v pip 2> /dev/null)
|
|
||||||
|
|
||||||
help:
|
|
||||||
@echo "Available targets:"
|
|
||||||
@echo " check-deps - Check if all required tools are installed"
|
|
||||||
@echo " build-all - Build all functions (Go, Rust, Python)"
|
|
||||||
@echo " build-go - Build all Go functions"
|
|
||||||
@echo " build-rust - Build all Rust functions"
|
|
||||||
@echo " build-python - Build all Python functions"
|
|
||||||
@echo " clean - Clean all build artifacts"
|
|
||||||
@echo " test - Run all tests"
|
|
||||||
@echo " deploy - Deploy to Amplify"
|
|
||||||
@echo " dev - Start development environment"
|
|
||||||
@echo " install-deps - Install all dependencies"
|
|
||||||
|
|
||||||
# Check if required tools are installed
|
|
||||||
check-deps:
|
|
||||||
@echo "🔍 Checking dependencies..."
|
|
||||||
@command -v node >/dev/null 2>&1 || { echo "❌ Node.js is required but not installed."; exit 1; }
|
|
||||||
@command -v npm >/dev/null 2>&1 || { echo "❌ npm is required but not installed."; exit 1; }
|
|
||||||
@command -v go >/dev/null 2>&1 || { echo "⚠️ Go is not installed. Go functions will be skipped."; }
|
|
||||||
@command -v cargo >/dev/null 2>&1 || { echo "⚠️ Rust/Cargo is not installed. Rust functions will be skipped."; }
|
|
||||||
@if [ -z "$(PYTHON)" ]; then echo "⚠️ Python is not installed. Python functions will be skipped."; else echo "✅ Python found: $(PYTHON)"; fi
|
|
||||||
@if [ -z "$(PIP)" ]; then echo "⚠️ pip is not installed. Python dependencies cannot be installed."; else echo "✅ pip found: $(PIP)"; fi
|
|
||||||
@echo "✅ Dependency check complete!"
|
|
||||||
|
|
||||||
$(DIST_DIR):
|
|
||||||
@mkdir -p $(DIST_DIR)/go $(DIST_DIR)/rust $(DIST_DIR)/python
|
|
||||||
|
|
||||||
build-go: $(DIST_DIR)
|
|
||||||
@if ! command -v go >/dev/null 2>&1; then \
|
|
||||||
echo "⚠️ Go not found, skipping Go functions..."; \
|
|
||||||
exit 0; \
|
|
||||||
else \
|
|
||||||
echo "🔨 Building Go functions..."; \
|
|
||||||
for func_main in $(GO_FUNCTIONS); do \
|
|
||||||
func_dir=$$(dirname $$func_main); \
|
|
||||||
func_name=$$(basename $$func_dir); \
|
|
||||||
echo " Building Go function: $$func_name"; \
|
|
||||||
cd $$func_dir && \
|
|
||||||
GOOS=linux GOARCH=arm64 go build -o bootstrap main.go && \
|
|
||||||
zip -r ../../../$(DIST_DIR)/go/$$func_name.zip bootstrap && \
|
|
||||||
rm bootstrap && \
|
|
||||||
cd - > /dev/null; \
|
|
||||||
done; \
|
|
||||||
echo "✅ Go functions built successfully!"; \
|
|
||||||
fi
|
|
||||||
|
|
||||||
build-rust: $(DIST_DIR)
|
|
||||||
@if ! command -v cargo >/dev/null 2>&1; then \
|
|
||||||
echo "⚠️ Cargo not found, skipping Rust functions..."; \
|
|
||||||
exit 0; \
|
|
||||||
else \
|
|
||||||
echo "🦀 Building Rust functions..."; \
|
|
||||||
for cargo_toml in $(RUST_FUNCTIONS); do \
|
|
||||||
func_dir=$$(dirname $$cargo_toml); \
|
|
||||||
func_name=$$(basename $$func_dir); \
|
|
||||||
echo " Building Rust function: $$func_name"; \
|
|
||||||
cd $$func_dir && \
|
|
||||||
if command -v cargo-lambda >/dev/null 2>&1; then \
|
|
||||||
echo " Using cargo-lambda..."; \
|
|
||||||
cargo lambda build --release --arm64; \
|
|
||||||
if [ -f "target/lambda/$$func_name/bootstrap" ]; then \
|
|
||||||
cp target/lambda/$$func_name/bootstrap .; \
|
|
||||||
elif [ -f "target/lambda/release/bootstrap" ]; then \
|
|
||||||
cp target/lambda/release/bootstrap .; \
|
|
||||||
else \
|
|
||||||
echo " Searching for bootstrap binary..."; \
|
|
||||||
find target -name "bootstrap" -type f | head -1 | xargs -I {} cp {} .; \
|
|
||||||
fi; \
|
|
||||||
else \
|
|
||||||
echo " Using regular cargo build..."; \
|
|
||||||
cargo build --release; \
|
|
||||||
cp target/release/$$func_name bootstrap; \
|
|
||||||
fi && \
|
|
||||||
if [ ! -f bootstrap ]; then \
|
|
||||||
echo " ❌ Bootstrap binary not found!"; \
|
|
||||||
ls -la target/ || true; \
|
|
||||||
exit 1; \
|
|
||||||
fi && \
|
|
||||||
zip -r ../../../$(DIST_DIR)/rust/$$func_name.zip bootstrap && \
|
|
||||||
rm bootstrap && \
|
|
||||||
cd - > /dev/null; \
|
|
||||||
done; \
|
|
||||||
echo "✅ Rust functions built successfully!"; \
|
|
||||||
fi
|
|
||||||
|
|
||||||
build-python: $(DIST_DIR)
|
|
||||||
@if [ -z "$(PYTHON)" ]; then \
|
|
||||||
echo "⚠️ Python not found, skipping Python functions..."; \
|
|
||||||
exit 0; \
|
|
||||||
else \
|
|
||||||
echo "🐍 Building Python functions..."; \
|
|
||||||
for func_py in $(PYTHON_FUNCTIONS); do \
|
|
||||||
func_dir=$$(dirname $$func_py); \
|
|
||||||
func_name=$$(basename $$func_dir); \
|
|
||||||
echo " Building Python function: $$func_name"; \
|
|
||||||
cd $$func_dir && \
|
|
||||||
if [ -f requirements.txt ] && [ -n "$(PIP)" ]; then \
|
|
||||||
echo " Installing Python dependencies..."; \
|
|
||||||
$(PIP) install -r requirements.txt -t . --quiet; \
|
|
||||||
elif [ -f requirements.txt ]; then \
|
|
||||||
echo " ⚠️ pip not found, skipping dependency installation"; \
|
|
||||||
fi && \
|
|
||||||
zip -r ../../../$(DIST_DIR)/python/$$func_name.zip . -x "*.pyc" "__pycache__/*" "*.git*" && \
|
|
||||||
cd - > /dev/null; \
|
|
||||||
done; \
|
|
||||||
echo "✅ Python functions built successfully!"; \
|
|
||||||
fi
|
|
||||||
|
|
||||||
build-all: check-deps clean build-go build-rust build-python
|
|
||||||
@echo "🎉 All available functions built successfully!"
|
|
||||||
|
|
||||||
clean:
|
|
||||||
@echo "🧹 Cleaning build artifacts..."
|
|
||||||
@rm -rf $(DIST_DIR)
|
|
||||||
@find functions -name "bootstrap" -delete 2>/dev/null || true
|
|
||||||
@find functions -name "target" -type d -exec rm -rf {} + 2>/dev/null || true
|
|
||||||
@find functions -name "__pycache__" -type d -exec rm -rf {} + 2>/dev/null || true
|
|
||||||
@find functions -name "*.pyc" -delete 2>/dev/null || true
|
|
||||||
@rm -rf build node_modules/.cache 2>/dev/null || true
|
|
||||||
@echo "✅ Cleaned successfully!"
|
|
||||||
|
|
||||||
test:
|
|
||||||
@echo "🧪 Running tests..."
|
|
||||||
@npm test -- --coverage --watchAll=false || echo "Frontend tests completed"
|
|
||||||
@if command -v go >/dev/null 2>&1; then \
|
|
||||||
echo "Testing Go functions..."; \
|
|
||||||
cd functions/go && go test ./... || echo "Go tests completed"; \
|
|
||||||
fi
|
|
||||||
@if command -v cargo >/dev/null 2>&1; then \
|
|
||||||
echo "Testing Rust functions..."; \
|
|
||||||
cd functions/rust && find . -name Cargo.toml -execdir cargo test \; || echo "Rust tests completed"; \
|
|
||||||
fi
|
|
||||||
@if [ -n "$(PYTHON)" ]; then \
|
|
||||||
echo "Testing Python functions..."; \
|
|
||||||
cd tests/integration && $(PYTHON) -m pytest . || echo "Python tests completed"; \
|
|
||||||
fi
|
|
||||||
|
|
||||||
install-deps:
|
|
||||||
@echo "📦 Installing dependencies..."
|
|
||||||
@npm install
|
|
||||||
@if command -v go >/dev/null 2>&1; then \
|
|
||||||
echo "Installing Go dependencies..."; \
|
|
||||||
cd functions/go && find . -name go.mod -execdir go mod tidy \; 2>/dev/null || true; \
|
|
||||||
fi
|
|
||||||
@if command -v cargo >/dev/null 2>&1; then \
|
|
||||||
echo "Installing Rust tools..."; \
|
|
||||||
cargo install cargo-lambda 2>/dev/null || echo "cargo-lambda installation skipped"; \
|
|
||||||
fi
|
|
||||||
@if [ -n "$(PIP)" ]; then \
|
|
||||||
echo "Installing Python tools..."; \
|
|
||||||
$(PIP) install pytest boto3 2>/dev/null || echo "Python packages installation skipped"; \
|
|
||||||
fi
|
|
||||||
@echo "✅ Dependencies installation completed!"
|
|
||||||
|
|
||||||
dev:
|
|
||||||
@echo "🚀 Starting development environment..."
|
|
||||||
@echo "Starting Amplify sandbox in background..."
|
|
||||||
@npx ampx sandbox > amplify-sandbox.log 2>&1 &
|
|
||||||
@echo "Starting React development server..."
|
|
||||||
@npm start
|
|
||||||
|
|
||||||
deploy: build-all
|
|
||||||
@echo "🚀 Deploying to Amplify..."
|
|
||||||
@npx ampx pipeline-deploy --branch main
|
|
||||||
|
|
||||||
# Platform-specific Python installation helpers
|
|
||||||
install-python-mac:
|
|
||||||
@echo "Installing Python on macOS..."
|
|
||||||
@if command -v brew >/dev/null 2>&1; then \
|
|
||||||
brew install python3; \
|
|
||||||
else \
|
|
||||||
echo "Homebrew not found. Please install Python manually from https://python.org"; \
|
|
||||||
fi
|
|
||||||
|
|
||||||
install-python-ubuntu:
|
|
||||||
@echo "Installing Python on Ubuntu..."
|
|
||||||
@sudo apt update && sudo apt install -y python3 python3-pip
|
|
||||||
|
|
||||||
install-python-centos:
|
|
||||||
@echo "Installing Python on CentOS/RHEL..."
|
|
||||||
@sudo yum install -y python3 python3-pip
|
|
||||||
|
|
||||||
install-python-windows:
|
|
||||||
@echo "For Windows, please install Python from https://python.org"
|
|
||||||
@echo "Make sure to check 'Add Python to PATH' during installation"
|
|
||||||
-213
@@ -1,213 +0,0 @@
|
|||||||
version: 0.2
|
|
||||||
|
|
||||||
env:
|
|
||||||
variables:
|
|
||||||
# Runtime versions
|
|
||||||
NODE_VERSION: "18"
|
|
||||||
PYTHON_VERSION: "3.9"
|
|
||||||
GO_VERSION: "1.21"
|
|
||||||
# Build configuration
|
|
||||||
BUILD_ENV: "production"
|
|
||||||
RUST_BACKTRACE: "1"
|
|
||||||
|
|
||||||
phases:
|
|
||||||
install:
|
|
||||||
runtime-versions:
|
|
||||||
nodejs: 18
|
|
||||||
python: 3.9
|
|
||||||
golang: 1.21
|
|
||||||
commands:
|
|
||||||
- echo "Installing build dependencies..."
|
|
||||||
|
|
||||||
# Install Rust with error handling
|
|
||||||
- |
|
|
||||||
if ! command -v rustc &> /dev/null; then
|
|
||||||
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
|
|
||||||
source $HOME/.cargo/env
|
|
||||||
rustup update stable
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Install AWS CDK globally
|
|
||||||
- npm install -g aws-cdk@latest
|
|
||||||
|
|
||||||
# Verify runtime versions
|
|
||||||
- echo "=== Runtime Versions ==="
|
|
||||||
- node --version
|
|
||||||
- npm --version
|
|
||||||
- python3 --version
|
|
||||||
- go version
|
|
||||||
- rustc --version || echo "Rust not available"
|
|
||||||
- cdk --version
|
|
||||||
|
|
||||||
pre_build:
|
|
||||||
commands:
|
|
||||||
- echo "Pre-build phase started on $(date)"
|
|
||||||
|
|
||||||
# Install React dependencies with clean install
|
|
||||||
- echo "Installing React dependencies..."
|
|
||||||
- npm ci --prefer-offline --no-audit
|
|
||||||
|
|
||||||
# Install Python dependencies for Lambda functions
|
|
||||||
- |
|
|
||||||
if [ -d "functions/python" ] && [ -f "functions/python/requirements.txt" ]; then
|
|
||||||
echo "Installing Python dependencies..."
|
|
||||||
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
|
|
||||||
- |
|
|
||||||
if [ -d "functions/go" ] && [ -f "functions/go/go.mod" ]; then
|
|
||||||
echo "Downloading Go dependencies..."
|
|
||||||
cd functions/go
|
|
||||||
go mod download
|
|
||||||
go mod verify
|
|
||||||
cd ../..
|
|
||||||
else
|
|
||||||
echo "No Go Lambda function found, skipping..."
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check Rust dependencies
|
|
||||||
- |
|
|
||||||
if [ -d "functions/rust" ] && [ -f "functions/rust/Cargo.toml" ]; then
|
|
||||||
echo "Checking Rust dependencies..."
|
|
||||||
cd functions/rust
|
|
||||||
cargo check --release
|
|
||||||
cd ../..
|
|
||||||
else
|
|
||||||
echo "No Rust Lambda function found, skipping..."
|
|
||||||
fi
|
|
||||||
|
|
||||||
build:
|
|
||||||
commands:
|
|
||||||
- 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
|
|
||||||
- echo "Building React application..."
|
|
||||||
- npm run build
|
|
||||||
|
|
||||||
# Build Lambda functions in parallel where possible
|
|
||||||
- echo "Building Lambda functions..."
|
|
||||||
|
|
||||||
# Build Go Lambda function
|
|
||||||
- |
|
|
||||||
if [ -d "functions/go" ]; then
|
|
||||||
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 -9 go-lambda.zip bootstrap
|
|
||||||
cd ../..
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Build Rust Lambda function
|
|
||||||
- |
|
|
||||||
if [ -d "functions/rust" ]; then
|
|
||||||
echo "Building Rust Lambda function..."
|
|
||||||
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
|
|
||||||
- |
|
|
||||||
if [ -d "functions/python" ]; then
|
|
||||||
echo "Packaging Python Lambda function..."
|
|
||||||
cd functions/python
|
|
||||||
zip -r9 ../python-lambda.zip . -x "*.pyc" "__pycache__/*" "*.git*" "*.DS_Store*"
|
|
||||||
cd ../..
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Build CDK infrastructure
|
|
||||||
- echo "Synthesizing CDK infrastructure..."
|
|
||||||
- npx cdk synth --all
|
|
||||||
|
|
||||||
post_build:
|
|
||||||
commands:
|
|
||||||
- echo "Post-build phase started on $(date)"
|
|
||||||
|
|
||||||
# Create deployment package structure
|
|
||||||
- mkdir -p dist/{react,lambdas,infrastructure}
|
|
||||||
|
|
||||||
# Copy React build artifacts
|
|
||||||
- |
|
|
||||||
if [ -d "build" ]; then
|
|
||||||
cp -r build/* dist/react/
|
|
||||||
else
|
|
||||||
echo "No React build directory found"
|
|
||||||
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
|
|
||||||
- |
|
|
||||||
if [ -d "cdk.out" ]; then
|
|
||||||
cp -r cdk.out/* dist/infrastructure/
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Generate build metadata
|
|
||||||
- |
|
|
||||||
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)"
|
|
||||||
|
|
||||||
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-$CODEBUILD_BUILD_NUMBER
|
|
||||||
|
|
||||||
cache:
|
|
||||||
paths:
|
|
||||||
- node_modules/**/*
|
|
||||||
- ~/.npm/**/*
|
|
||||||
- ~/.cache/pip/**/*
|
|
||||||
- ~/.cargo/**/*
|
|
||||||
- functions/go/go.mod
|
|
||||||
- functions/go/go.sum
|
|
||||||
- functions/rust/target/**/*
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
module go-functions
|
|
||||||
|
|
||||||
go 1.21
|
|
||||||
|
|
||||||
require github.com/aws/aws-lambda-go v1.41.0
|
|
||||||
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
github.com/aws/aws-lambda-go v1.41.0 h1:l/5fyVb6Ud9uYd411xdHZzSf2n86TakxzpvIoz7l+3Y=
|
|
||||||
github.com/aws/aws-lambda-go v1.41.0/go.mod h1:jwFe2KmMsHmffA1X2R09hH6lFzJQxzI8qK17ewzbQMM=
|
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
|
||||||
github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s=
|
|
||||||
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
|
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/aws/aws-lambda-go/lambda"
|
|
||||||
)
|
|
||||||
|
|
||||||
type MyEvent struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type MyResponse struct {
|
|
||||||
Message string `json:"message"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func HandleRequest(ctx context.Context, event MyEvent) (MyResponse, error) {
|
|
||||||
return MyResponse{
|
|
||||||
Message: fmt.Sprintf("Hello %s from Go Lambda!", event.Name),
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
lambda.Start(HandleRequest)
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
from fastapi import FastAPI
|
|
||||||
from mangum import Mangum
|
|
||||||
|
|
||||||
app = FastAPI(title="portfolio-python-api")
|
|
||||||
|
|
||||||
|
|
||||||
@app.get("/health")
|
|
||||||
async def health() -> dict[str, str]:
|
|
||||||
return {"status": "ok", "service": "portfolio-python-api"}
|
|
||||||
|
|
||||||
|
|
||||||
handler = Mangum(app)
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
fastapi>=0.110.0
|
|
||||||
mangum>=0.17.0
|
|
||||||
uvicorn>=0.29.0
|
|
||||||
Generated
-7
@@ -1,7 +0,0 @@
|
|||||||
# This file is automatically @generated by Cargo.
|
|
||||||
# It is not intended for manual editing.
|
|
||||||
version = 4
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "portfolio-rust-engine"
|
|
||||||
version = "0.1.0"
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "portfolio-rust-engine"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2021"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
fn main() {
|
|
||||||
println!("Portfolio Rust engine started");
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
{"rustc_fingerprint":11425412769582563416,"outputs":{"17747080675513052775":{"success":true,"status":"","code":0,"stdout":"rustc 1.95.0 (59807616e 2026-04-14)\nbinary: rustc\ncommit-hash: 59807616e1fa2540724bfbac14d7976d7e4a3860\ncommit-date: 2026-04-14\nhost: aarch64-apple-darwin\nrelease: 1.95.0\nLLVM version: 22.1.2\n","stderr":""},"7971740275564407648":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.dylib\nlib___.dylib\nlib___.a\nlib___.dylib\n/Users/gjcampbell/.rustup/toolchains/stable-aarch64-apple-darwin\noff\npacked\nunpacked\n___\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_abi=\"\"\ntarget_arch=\"aarch64\"\ntarget_endian=\"little\"\ntarget_env=\"\"\ntarget_family=\"unix\"\ntarget_feature=\"aes\"\ntarget_feature=\"crc\"\ntarget_feature=\"dit\"\ntarget_feature=\"dotprod\"\ntarget_feature=\"dpb\"\ntarget_feature=\"dpb2\"\ntarget_feature=\"fcma\"\ntarget_feature=\"fhm\"\ntarget_feature=\"flagm\"\ntarget_feature=\"fp16\"\ntarget_feature=\"frintts\"\ntarget_feature=\"jsconv\"\ntarget_feature=\"lor\"\ntarget_feature=\"lse\"\ntarget_feature=\"neon\"\ntarget_feature=\"paca\"\ntarget_feature=\"pacg\"\ntarget_feature=\"pan\"\ntarget_feature=\"pmuv3\"\ntarget_feature=\"ras\"\ntarget_feature=\"rcpc\"\ntarget_feature=\"rcpc2\"\ntarget_feature=\"rdm\"\ntarget_feature=\"sb\"\ntarget_feature=\"sha2\"\ntarget_feature=\"sha3\"\ntarget_feature=\"ssbs\"\ntarget_feature=\"vh\"\ntarget_has_atomic=\"128\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"macos\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"apple\"\nunix\n","stderr":""}},"successes":{}}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
Signature: 8a477f597d28d172789f06886806bc55
|
|
||||||
# This file is a cache directory tag created by cargo.
|
|
||||||
# For information about cache directory tags see https://bford.info/cachedir/
|
|
||||||
BIN
Binary file not shown.
-1
@@ -1 +0,0 @@
|
|||||||
This file has an mtime of when this was started.
|
|
||||||
-1
@@ -1 +0,0 @@
|
|||||||
3b24766a91ce7e17
|
|
||||||
-1
@@ -1 +0,0 @@
|
|||||||
{"rustc":2179919275645516985,"features":"[]","declared_features":"[]","target":12280563477853291191,"profile":15057526963834790232,"path":4942398508502643691,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/portfolio-rust-engine-d47120c580687ac1/dep-test-bin-portfolio-rust-engine","checksum":false}}],"rustflags":[],"config":8247474407144887393,"compile_kind":0}
|
|
||||||
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -1,5 +0,0 @@
|
|||||||
/Users/gjcampbell/Repos/personal_site_gh/functions/rust/target/debug/deps/portfolio_rust_engine-d47120c580687ac1.d: src/main.rs
|
|
||||||
|
|
||||||
/Users/gjcampbell/Repos/personal_site_gh/functions/rust/target/debug/deps/portfolio_rust_engine-d47120c580687ac1: src/main.rs
|
|
||||||
|
|
||||||
src/main.rs:
|
|
||||||
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -1,190 +0,0 @@
|
|||||||
// infrastructure/api-gateway-stack.ts
|
|
||||||
import { Stack, StackProps, CfnOutput } from 'aws-cdk-lib'
|
|
||||||
import { Construct } from 'constructs'
|
|
||||||
import * as apigateway from 'aws-cdk-lib/aws-apigateway'
|
|
||||||
import * as lambda from 'aws-cdk-lib/aws-lambda'
|
|
||||||
import * as logs from 'aws-cdk-lib/aws-logs'
|
|
||||||
import * as iam from 'aws-cdk-lib/aws-iam'
|
|
||||||
|
|
||||||
export interface ApiGatewayStackProps extends StackProps {
|
|
||||||
// Reference to your Lambda functions from another stack
|
|
||||||
goFunction: lambda.Function
|
|
||||||
pythonFunction: lambda.Function
|
|
||||||
rustFunction: lambda.Function
|
|
||||||
}
|
|
||||||
|
|
||||||
export class ApiGatewayStack extends Stack {
|
|
||||||
public readonly api: apigateway.RestApi
|
|
||||||
public readonly apiUrl: string
|
|
||||||
|
|
||||||
constructor(scope: Construct, id: string, props: ApiGatewayStackProps) {
|
|
||||||
super(scope, id, props)
|
|
||||||
|
|
||||||
// Create CloudWatch Log Group for API Gateway
|
|
||||||
const logGroup = new logs.LogGroup(this, 'ApiGatewayLogGroup', {
|
|
||||||
logGroupName: `/aws/apigateway/${id}`,
|
|
||||||
retention: logs.RetentionDays.ONE_WEEK,
|
|
||||||
})
|
|
||||||
|
|
||||||
// Create API Gateway
|
|
||||||
this.api = new apigateway.RestApi(this, 'MyApi', {
|
|
||||||
restApiName: 'My Multi-Language API',
|
|
||||||
description: 'API Gateway for Go, Python, and Rust Lambda functions',
|
|
||||||
|
|
||||||
// Enable CORS for frontend integration
|
|
||||||
defaultCorsPreflightOptions: {
|
|
||||||
allowOrigins: [
|
|
||||||
'http://localhost:3000', // Local development
|
|
||||||
'https://your-amplify-domain.amplifyapp.com', // Your Amplify domain
|
|
||||||
],
|
|
||||||
allowMethods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
|
|
||||||
allowHeaders: [
|
|
||||||
'Content-Type',
|
|
||||||
'X-Amz-Date',
|
|
||||||
'Authorization',
|
|
||||||
'X-Api-Key',
|
|
||||||
'X-Amz-Security-Token',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
|
|
||||||
// Deploy automatically
|
|
||||||
deploy: true,
|
|
||||||
deployOptions: {
|
|
||||||
stageName: 'prod',
|
|
||||||
loggingLevel: apigateway.MethodLoggingLevel.INFO,
|
|
||||||
dataTraceEnabled: true,
|
|
||||||
metricsEnabled: true,
|
|
||||||
accessLogDestination: new apigateway.LogGroupLogDestination(logGroup),
|
|
||||||
accessLogFormat: apigateway.AccessLogFormat.jsonWithStandardFields(),
|
|
||||||
},
|
|
||||||
|
|
||||||
// Enable endpoint configuration
|
|
||||||
endpointConfiguration: {
|
|
||||||
types: [apigateway.EndpointType.REGIONAL],
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
// Create API resources and methods
|
|
||||||
this.createGoEndpoints(props.goFunction)
|
|
||||||
this.createPythonEndpoints(props.pythonFunction)
|
|
||||||
this.createRustEndpoints(props.rustFunction)
|
|
||||||
|
|
||||||
// Add a health check endpoint
|
|
||||||
this.createHealthEndpoint()
|
|
||||||
|
|
||||||
// Store API URL for output
|
|
||||||
this.apiUrl = this.api.url
|
|
||||||
|
|
||||||
// Output the API URL
|
|
||||||
new CfnOutput(this, 'ApiUrl', {
|
|
||||||
value: this.apiUrl,
|
|
||||||
description: 'API Gateway URL',
|
|
||||||
exportName: `${this.stackName}-ApiUrl`,
|
|
||||||
})
|
|
||||||
|
|
||||||
// Output individual endpoint URLs
|
|
||||||
new CfnOutput(this, 'GoEndpoint', {
|
|
||||||
value: `${this.apiUrl}go`,
|
|
||||||
description: 'Go Lambda endpoint',
|
|
||||||
})
|
|
||||||
|
|
||||||
new CfnOutput(this, 'PythonEndpoint', {
|
|
||||||
value: `${this.apiUrl}python`,
|
|
||||||
description: 'Python Lambda endpoint',
|
|
||||||
})
|
|
||||||
|
|
||||||
new CfnOutput(this, 'RustEndpoint', {
|
|
||||||
value: `${this.apiUrl}rust`,
|
|
||||||
description: 'Rust Lambda endpoint',
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
private createGoEndpoints(goFunction: lambda.Function) {
|
|
||||||
// Create /go resource
|
|
||||||
const goResource = this.api.root.addResource('go')
|
|
||||||
|
|
||||||
// Create Lambda integration
|
|
||||||
const goIntegration = new apigateway.LambdaIntegration(goFunction, {
|
|
||||||
requestTemplates: { 'application/json': '{ "statusCode": "200" }' },
|
|
||||||
proxy: true, // Enable Lambda proxy integration
|
|
||||||
})
|
|
||||||
|
|
||||||
// Add methods
|
|
||||||
goResource.addMethod('GET', goIntegration)
|
|
||||||
goResource.addMethod('POST', goIntegration)
|
|
||||||
|
|
||||||
// Add sub-resources if needed
|
|
||||||
const goHealthResource = goResource.addResource('health')
|
|
||||||
goHealthResource.addMethod('GET', goIntegration)
|
|
||||||
}
|
|
||||||
|
|
||||||
private createPythonEndpoints(pythonFunction: lambda.Function) {
|
|
||||||
// Create /python resource
|
|
||||||
const pythonResource = this.api.root.addResource('python')
|
|
||||||
|
|
||||||
// Create Lambda integration
|
|
||||||
const pythonIntegration = new apigateway.LambdaIntegration(pythonFunction, {
|
|
||||||
proxy: true,
|
|
||||||
})
|
|
||||||
|
|
||||||
// Add methods
|
|
||||||
pythonResource.addMethod('GET', pythonIntegration)
|
|
||||||
pythonResource.addMethod('POST', pythonIntegration)
|
|
||||||
pythonResource.addMethod('PUT', pythonIntegration)
|
|
||||||
|
|
||||||
// Add sub-resources
|
|
||||||
const pythonDataResource = pythonResource.addResource('data')
|
|
||||||
pythonDataResource.addMethod('GET', pythonIntegration)
|
|
||||||
pythonDataResource.addMethod('POST', pythonIntegration)
|
|
||||||
}
|
|
||||||
|
|
||||||
private createRustEndpoints(rustFunction: lambda.Function) {
|
|
||||||
// Create /rust resource
|
|
||||||
const rustResource = this.api.root.addResource('rust')
|
|
||||||
|
|
||||||
// Create Lambda integration
|
|
||||||
const rustIntegration = new apigateway.LambdaIntegration(rustFunction, {
|
|
||||||
proxy: true,
|
|
||||||
})
|
|
||||||
|
|
||||||
// Add methods
|
|
||||||
rustResource.addMethod('GET', rustIntegration)
|
|
||||||
rustResource.addMethod('POST', rustIntegration)
|
|
||||||
rustResource.addMethod('DELETE', rustIntegration)
|
|
||||||
|
|
||||||
// Add sub-resources
|
|
||||||
const rustProcessResource = rustResource.addResource('process')
|
|
||||||
rustProcessResource.addMethod('POST', rustIntegration)
|
|
||||||
}
|
|
||||||
|
|
||||||
private createHealthEndpoint() {
|
|
||||||
// Create a simple health check endpoint
|
|
||||||
const healthResource = this.api.root.addResource('health')
|
|
||||||
|
|
||||||
// Mock integration for health check (no Lambda needed)
|
|
||||||
const healthIntegration = new apigateway.MockIntegration({
|
|
||||||
integrationResponses: [{
|
|
||||||
statusCode: '200',
|
|
||||||
responseTemplates: {
|
|
||||||
'application/json': JSON.stringify({
|
|
||||||
status: 'healthy',
|
|
||||||
timestamp: '$context.requestTime',
|
|
||||||
requestId: '$context.requestId'
|
|
||||||
})
|
|
||||||
},
|
|
||||||
}],
|
|
||||||
requestTemplates: {
|
|
||||||
'application/json': '{ "statusCode": 200 }'
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
healthResource.addMethod('GET', healthIntegration, {
|
|
||||||
methodResponses: [{
|
|
||||||
statusCode: '200',
|
|
||||||
responseModels: {
|
|
||||||
'application/json': apigateway.Model.EMPTY_MODEL,
|
|
||||||
},
|
|
||||||
}],
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
// infrastructure/app.ts
|
|
||||||
import * as cdk from 'aws-cdk-lib'
|
|
||||||
import { LambdaStack } from './lambda-stack'
|
|
||||||
import { ApiGatewayStack } from './api-gateway-stack'
|
|
||||||
|
|
||||||
const app = new cdk.App()
|
|
||||||
|
|
||||||
// Create Lambda functions first
|
|
||||||
const lambdaStack = new LambdaStack(app, 'LambdaStack', {
|
|
||||||
env: {
|
|
||||||
account: process.env.CDK_DEFAULT_ACCOUNT,
|
|
||||||
region: process.env.CDK_DEFAULT_REGION,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
// Create API Gateway and connect to Lambda functions
|
|
||||||
const apiStack = new ApiGatewayStack(app, 'ApiGatewayStack', {
|
|
||||||
goFunction: lambdaStack.goFunction,
|
|
||||||
pythonFunction: lambdaStack.pythonFunction,
|
|
||||||
rustFunction: lambdaStack.rustFunction,
|
|
||||||
env: {
|
|
||||||
account: process.env.CDK_DEFAULT_ACCOUNT,
|
|
||||||
region: process.env.CDK_DEFAULT_REGION,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
// Ensure Lambda stack is deployed before API Gateway
|
|
||||||
apiStack.addDependency(lambdaStack)
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
// infrastructure/lambda-stack.ts
|
|
||||||
import { Stack, StackProps, Duration } from 'aws-cdk-lib'
|
|
||||||
import { Construct } from 'constructs'
|
|
||||||
import * as lambda from 'aws-cdk-lib/aws-lambda'
|
|
||||||
|
|
||||||
export class LambdaStack extends Stack {
|
|
||||||
public readonly goFunction: lambda.Function
|
|
||||||
public readonly pythonFunction: lambda.Function
|
|
||||||
public readonly rustFunction: lambda.Function
|
|
||||||
|
|
||||||
constructor(scope: Construct, id: string, props?: StackProps) {
|
|
||||||
super(scope, id, props)
|
|
||||||
|
|
||||||
// Go function
|
|
||||||
this.goFunction = new lambda.Function(this, 'GoFunction', {
|
|
||||||
runtime: lambda.Runtime.PROVIDED_AL2023,
|
|
||||||
handler: 'bootstrap',
|
|
||||||
code: lambda.Code.fromAsset('../functions/go-functions'),
|
|
||||||
timeout: Duration.minutes(15),
|
|
||||||
memorySize: 1024,
|
|
||||||
})
|
|
||||||
|
|
||||||
// Python function
|
|
||||||
this.pythonFunction = new lambda.Function(this, 'PythonFunction', {
|
|
||||||
runtime: lambda.Runtime.PYTHON_3_12,
|
|
||||||
handler: 'handler.handler',
|
|
||||||
code: lambda.Code.fromAsset('../functions/python-function'),
|
|
||||||
timeout: Duration.minutes(5),
|
|
||||||
memorySize: 512,
|
|
||||||
})
|
|
||||||
|
|
||||||
// Rust function
|
|
||||||
this.rustFunction = new lambda.Function(this, 'RustFunction', {
|
|
||||||
runtime: lambda.Runtime.PROVIDED_AL2023,
|
|
||||||
handler: 'bootstrap',
|
|
||||||
code: lambda.Code.fromAsset('../functions/rust-function'),
|
|
||||||
timeout: Duration.minutes(10),
|
|
||||||
memorySize: 2048,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user