image-analysis-service
v1.0.0
Published
Serverless image analysis service
Readme
Image Analysis Service
This project provides a serverless image analysis API running on Google Cloud Functions. It allows pluggable AI providers (OpenAI, Google Cloud Vision, or AWS Rekognition) and is deployed using Terraform with CI/CD via GitHub Actions.
Features
- Analyze images for different request types (
describe,objects,nsfw,classify). - Provider-agnostic architecture via
ProviderInterface. - Prompt engineering layer to shape provider specific prompts.
- Deploy to Google Cloud Functions using Terraform.
- Automated testing and deployment with GitHub Actions.
Setup
Install dependencies
npm installEnvironment Variables
AI_PROVIDER–gcp,aws, oropenai.- Provider specific credentials should be supplied via standard environment variables/secrets.
Build & Test
npm run lint npm test npm run build
Running Locally
Use the Google Functions Framework to run locally:
npx @google-cloud/functions-framework --target=imageAnalysisSend a POST /analyze request with multipart/form-data containing image and requestType fields.
Terraform Deployment
- Configure variables in
infra/variables.tfor via aterraform.tfvarsfile:
project = "image-analysis-test-461112"
region = "us-central1"
bucket_name = "function-source-bucket"- Initialize and apply:
cd infra
terraform init
terraform applyThis uploads a zip file containing the built function to a GCS bucket and deploys the Cloud Function.
CI/CD
GitHub Actions workflow runs linting, tests, and Terraform deployment on push to main. It can deploy to either GCP or AWS. When triggering the workflow manually you can choose the provider input (either gcp or aws) to control which Terraform configuration is applied. Provide the relevant credentials (GCP_CREDENTIALS or AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY) in repository secrets.
Semantic-release runs whenever a pull request is merged into main or master. The workflow automatically determines the next version based on commit messages, updates the changelog and tags the release in GitHub.
Provider Configuration
Implement provider-specific API calls inside:
src/providers/OpenAIProvider.tssrc/providers/GCPVisionProvider.tssrc/providers/AWSRekognitionProvider.ts
Each implements the ProviderInterface and uses respective SDKs. Copy .env.example to .env and populate the variables for your chosen provider.
