Skip to main content

Deployment Guide

Learn how to deploy applications using Devcogent in various environments and platforms.

Pre-Deployment Checklist

Before deploying your Devcogent-integrated application:

  • API Keys: Ensure production API keys are configured
  • Environment Variables: Set up proper environment configuration
  • Error Handling: Implement comprehensive error handling
  • Rate Limiting: Configure appropriate rate limits
  • Monitoring: Set up logging and monitoring
  • Security: Review security configurations
  • Testing: Run integration tests against production APIs

Environment Configuration

Production Environment Variables

# Required
DEVCOGENT_API_KEY=prod_your_api_key_here
DEVCOGENT_ENVIRONMENT=production

# Optional but recommended
DEVCOGENT_BASE_URL=https://api.devcogent.com
DEVCOGENT_TIMEOUT=30000
DEVCOGENT_RETRIES=3
DEVCOGENT_DEBUG=false

# Security
DEVCOGENT_WEBHOOK_SECRET=your_webhook_secret
DEVCOGENT_ENCRYPT_KEYS=true

Configuration Management

// config/production.js
module.exports = {
devcogent: {
apiKey: process.env.DEVCOGENT_API_KEY,
environment: 'production',
timeout: parseInt(process.env.DEVCOGENT_TIMEOUT) || 30000,
retries: parseInt(process.env.DEVCOGENT_RETRIES) || 3,
logging: {
level: 'error',
destination: 'file'
}
}
};

Platform-Specific Deployments

AWS

Using AWS Lambda

// lambda-function.js
const { Devcogent } = require('@devcogent/sdk');

const client = new Devcogent({
apiKey: process.env.DEVCOGENT_API_KEY,
timeout: 25000 // Lambda timeout - 5 seconds buffer
});

exports.handler = async (event) => {
try {
const result = await client.processRequest(event.body);

return {
statusCode: 200,
headers: {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*'
},
body: JSON.stringify(result)
};
} catch (error) {
console.error('Error:', error);

return {
statusCode: 500,
body: JSON.stringify({ error: 'Internal server error' })
};
}
};

Using AWS ECS

# Dockerfile
FROM node:18-alpine

WORKDIR /app

COPY package*.json ./
RUN npm ci --only=production

COPY . .

EXPOSE 3000

CMD ["node", "server.js"]
# docker-compose.yml
version: '3.8'
services:
app:
build: .
ports:
- "3000:3000"
environment:
- DEVCOGENT_API_KEY=${DEVCOGENT_API_KEY}
- DEVCOGENT_ENVIRONMENT=production
deploy:
replicas: 3
resources:
limits:
memory: 512M
reservations:
memory: 256M

Google Cloud Platform

Using Cloud Functions

// index.js
const functions = require('@google-cloud/functions-framework');
const { Devcogent } = require('@devcogent/sdk');

const client = new Devcogent({
apiKey: process.env.DEVCOGENT_API_KEY
});

functions.http('devcogentHandler', async (req, res) => {
try {
const result = await client.processRequest(req.body);
res.json(result);
} catch (error) {
console.error(error);
res.status(500).json({ error: 'Internal server error' });
}
});

Using Cloud Run

# cloudbuild.yaml
steps:
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '-t', 'gcr.io/$PROJECT_ID/devcogent-app', '.']
- name: 'gcr.io/cloud-builders/docker'
args: ['push', 'gcr.io/$PROJECT_ID/devcogent-app']
- name: 'gcr.io/cloud-builders/gcloud'
args:
- 'run'
- 'deploy'
- 'devcogent-app'
- '--image'
- 'gcr.io/$PROJECT_ID/devcogent-app'
- '--region'
- 'us-central1'
- '--set-env-vars'
- 'DEVCOGENT_API_KEY=$$DEVCOGENT_API_KEY'
secretEnv: ['DEVCOGENT_API_KEY']

availableSecrets:
secretManager:
- versionName: projects/$PROJECT_ID/secrets/devcogent-api-key/versions/latest
env: 'DEVCOGENT_API_KEY'

Vercel

// api/devcogent.js
import { Devcogent } from '@devcogent/sdk';

const client = new Devcogent({
apiKey: process.env.DEVCOGENT_API_KEY
});

export default async function handler(req, res) {
if (req.method !== 'POST') {
return res.status(405).json({ error: 'Method not allowed' });
}

try {
const result = await client.processRequest(req.body);
res.status(200).json(result);
} catch (error) {
console.error('Devcogent error:', error);
res.status(500).json({ error: 'Internal server error' });
}
}
// vercel.json
{
"functions": {
"api/devcogent.js": {
"maxDuration": 30
}
},
"env": {
"DEVCOGENT_API_KEY": "@devcogent-api-key"
}
}

Netlify

// netlify/functions/devcogent.js
const { Devcogent } = require('@devcogent/sdk');

const client = new Devcogent({
apiKey: process.env.DEVCOGENT_API_KEY
});

exports.handler = async (event, context) => {
const headers = {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': 'Content-Type',
'Content-Type': 'application/json'
};

if (event.httpMethod === 'OPTIONS') {
return { statusCode: 200, headers, body: '' };
}

if (event.httpMethod !== 'POST') {
return {
statusCode: 405,
headers,
body: JSON.stringify({ error: 'Method not allowed' })
};
}

try {
const result = await client.processRequest(JSON.parse(event.body));
return {
statusCode: 200,
headers,
body: JSON.stringify(result)
};
} catch (error) {
console.error('Error:', error);
return {
statusCode: 500,
headers,
body: JSON.stringify({ error: 'Internal server error' })
};
}
};

Docker Deployment

Multi-stage Dockerfile

# Build stage
FROM node:18-alpine AS builder

WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production && npm cache clean --force

# Production stage
FROM node:18-alpine AS production

RUN addgroup -g 1001 -S nodejs
RUN adduser -S nextjs -u 1001

WORKDIR /app

COPY --from=builder /app/node_modules ./node_modules
COPY --chown=nextjs:nodejs . .

USER nextjs

EXPOSE 3000

ENV NODE_ENV=production
ENV DEVCOGENT_ENVIRONMENT=production

CMD ["node", "server.js"]

Docker Compose

version: '3.8'

services:
app:
build:
context: .
target: production
ports:
- "3000:3000"
environment:
- NODE_ENV=production
- DEVCOGENT_API_KEY=${DEVCOGENT_API_KEY}
- DEVCOGENT_ENVIRONMENT=production
restart: unless-stopped
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3000/health"]
interval: 30s
timeout: 10s
retries: 3

nginx:
image: nginx:alpine
ports:
- "80:80"
- "443:443"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
- ./ssl:/etc/nginx/ssl
depends_on:
- app
restart: unless-stopped

Kubernetes Deployment

Deployment Configuration

# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: devcogent-app
labels:
app: devcogent-app
spec:
replicas: 3
selector:
matchLabels:
app: devcogent-app
template:
metadata:
labels:
app: devcogent-app
spec:
containers:
- name: app
image: your-registry/devcogent-app:latest
ports:
- containerPort: 3000
env:
- name: DEVCOGENT_API_KEY
valueFrom:
secretKeyRef:
name: devcogent-secrets
key: api-key
- name: DEVCOGENT_ENVIRONMENT
value: "production"
resources:
requests:
memory: "256Mi"
cpu: "250m"
limits:
memory: "512Mi"
cpu: "500m"
livenessProbe:
httpGet:
path: /health
port: 3000
initialDelaySeconds: 30
periodSeconds: 10
readinessProbe:
httpGet:
path: /ready
port: 3000
initialDelaySeconds: 5
periodSeconds: 5

Service and Ingress

# service.yaml
apiVersion: v1
kind: Service
metadata:
name: devcogent-service
spec:
selector:
app: devcogent-app
ports:
- port: 80
targetPort: 3000
type: ClusterIP

---
# ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: devcogent-ingress
annotations:
kubernetes.io/ingress.class: "nginx"
cert-manager.io/cluster-issuer: "letsencrypt-prod"
spec:
tls:
- hosts:
- api.yourapp.com
secretName: devcogent-tls
rules:
- host: api.yourapp.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: devcogent-service
port:
number: 80

Monitoring and Logging

Application Monitoring

// monitoring.js
const { Devcogent } = require('@devcogent/sdk');

const client = new Devcogent({
apiKey: process.env.DEVCOGENT_API_KEY,
monitoring: {
enabled: true,
metricsEndpoint: '/metrics',
healthEndpoint: '/health'
}
});

// Custom metrics
client.on('request', (data) => {
// Log request metrics
console.log(`API Request: ${data.method} ${data.endpoint} - ${data.duration}ms`);
});

client.on('error', (error) => {
// Log errors for monitoring
console.error('Devcogent Error:', {
message: error.message,
stack: error.stack,
timestamp: new Date().toISOString()
});
});

Health Checks

// health.js
app.get('/health', async (req, res) => {
try {
// Check Devcogent API connectivity
await client.ping();

res.status(200).json({
status: 'healthy',
timestamp: new Date().toISOString(),
uptime: process.uptime(),
memory: process.memoryUsage()
});
} catch (error) {
res.status(503).json({
status: 'unhealthy',
error: error.message,
timestamp: new Date().toISOString()
});
}
});

app.get('/ready', async (req, res) => {
// Check if application is ready to receive traffic
if (client.isConnected()) {
res.status(200).json({ status: 'ready' });
} else {
res.status(503).json({ status: 'not ready' });
}
});

Security Considerations

Environment Variable Security

# Use secret management systems
export DEVCOGENT_API_KEY=$(aws secretsmanager get-secret-value --secret-id devcogent-api-key --query SecretString --output text)

# Or use encrypted environment files
gpg -d .env.prod.gpg > .env.prod
source .env.prod
rm .env.prod

API Key Rotation

// Graceful API key rotation
class ApiKeyManager {
constructor() {
this.currentKey = process.env.DEVCOGENT_API_KEY;
this.nextKey = process.env.DEVCOGENT_NEXT_API_KEY;
}

async rotateKey() {
if (!this.nextKey) return;

try {
// Test new key
const testClient = new Devcogent({ apiKey: this.nextKey });
await testClient.ping();

// Switch to new key
this.currentKey = this.nextKey;
this.nextKey = null;

console.log('API key rotated successfully');
} catch (error) {
console.error('Key rotation failed:', error);
}
}
}

Performance Optimization

Connection Pooling

const client = new Devcogent({
apiKey: process.env.DEVCOGENT_API_KEY,
pool: {
maxConnections: 100,
keepAlive: true,
timeout: 30000
}
});

Caching

const Redis = require('redis');
const redis = Redis.createClient();

async function getCachedData(key) {
try {
const cached = await redis.get(key);
if (cached) {
return JSON.parse(cached);
}

const data = await client.getData(key);
await redis.setex(key, 300, JSON.stringify(data)); // Cache for 5 minutes

return data;
} catch (error) {
console.error('Cache error:', error);
return await client.getData(key); // Fallback to direct API call
}
}

Troubleshooting Deployment Issues

Common Problems

  1. Environment Variable Issues

    • Verify all required environment variables are set
    • Check for typos in variable names
    • Ensure proper escaping of special characters
  2. Network Connectivity

    • Verify outbound HTTPS connectivity
    • Check firewall rules and security groups
    • Test DNS resolution for api.devcogent.com
  3. Resource Limits

    • Monitor memory and CPU usage
    • Adjust container/function limits as needed
    • Implement proper error handling for resource exhaustion
  4. API Rate Limits

    • Monitor API usage patterns
    • Implement exponential backoff
    • Consider upgrading API plan if needed

Next Steps

  • Review Troubleshooting Guide for specific issues
  • Set up monitoring and alerting
  • Plan for disaster recovery and backup strategies
  • Consider implementing CI/CD pipelines for automated deployments