Skill站外收录 @skilllib/skill-2117939930272411692
juicebox-multi-env-setup
实现 Juicebox 多环境配置管理,支持开发、预发布和生产环境的隔离部署,涵盖环境变量注入、密钥分级存储、Kubernetes 配置覆盖及运行时环境校验,确保各环境配置安全、可复现且符合最小权限原则。
开发运维 AI 技能
Skills.MD
# Juicebox Multi-Environment Setup
## Overview
Configure Juicebox across development, staging, and production environments with proper isolation and security.
## Prerequisites
- Separate Juicebox accounts or API keys per environment
- Secret management solution (Vault, AWS Secrets Manager, etc.)
- CI/CD pipeline with environment variables
- Environment detection in application
## Environment Strategy
| Environment | Purpose | API Key | Rate Limits | Data |
|-------------|---------|---------|-------------|------|
| Development | Local dev | Sandbox | Relaxed | Mock/Test |
| Staging | Pre-prod testing | Test | Production | Subset |
| Production | Live system | Production | Full | Real |
## Instructions
### Step 1: Environment Configuration
```typescript
// config/environments.ts
interface JuiceboxEnvConfig {
apiKey: string;
baseUrl: string;
timeout: number;
retries: number;
sandbox: boolean;
}
const configs: Record<string, JuiceboxEnvConfig> = {
development: {
apiKey: process.env.JUICEBOX_API_KEY_DEV!,
baseUrl: 'https://sandbox.api.juicebox.ai',
timeout: 30000,
retries: 1,
sandbox: true
},
staging: {
apiKey: process.env.JUICEBOX_API_KEY_STAGING!,
baseUrl: 'https://api.juicebox.ai',
timeout: 30000,
retries: 2,
sandbox: false
},
production: {
apiKey: process.env.JUICEBOX_API_KEY_PROD!,
baseUrl: 'https://api.juicebox.ai',
timeout: 60000,
retries: 3,
sandbox: false
}
};
export function getConfig(): JuiceboxEnvConfig {
const env = process.env.NODE_ENV || 'development';
const config = configs[env];
if (!config) {
throw new Error(`Unknown environment: ${env}`);
}
if (!config.apiKey) {
throw new Error(`JUICEBOX_API_KEY not set for ${env}`);
}
return config;
}
```
### Step 2: Secret Management by Environment
```typescript
// lib/secrets.ts
import { SecretsManager } from '@aws-sdk/client-secrets-manager';
const secretPaths: Record<string, string> = {
development: 'juicebox/dev/api-key',
staging: 'juicebox/staging/api-key',
production: 'juicebox/prod/api-key'
};
export async function getApiKey(): Promise<string> {
const env = process.env.NODE_ENV || 'development';
// In development, allow env var fallback
if (env === 'development' && process.env.JUICEBOX_API_KEY_DEV) {
return process.env.JUICEBOX_API_KEY_DEV;
}
// Production environments must use secret manager
const client = new SecretsManager({ region: process.env.AWS_REGION });
const result = await client.getSecretValue({
SecretId: secretPaths[env]
});
return JSON.parse(result.SecretString!).apiKey;
}
```
### Step 3: Environment-Aware Client Factory
```typescript
// lib/client-factory.ts
import { JuiceboxClient } from '@juicebox/sdk';
import { getConfig } from '../config/environments';
import { getApiKey } from './secrets';
let clientInstance: JuiceboxClient | null = null;
export async function getJuiceboxClient(): Promise<JuiceboxClient> {
if (clientInstance) return clientInstance;
const config = getConfig();
const apiKey = await getApiKey();
clientInstance = new JuiceboxClient({
apiKey,
baseUrl: config.baseUrl,
timeout: config.timeout,
retries: config.retries
});
// Add environment-specific middleware
if (process.env.NODE_ENV === 'development') {
clientInstance.use(logRequestsMiddleware);
}
return clientInstance;
}
```
### Step 4: Kubernetes ConfigMaps
```yaml
# k8s/base/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: juicebox-config
data:
JUICEBOX_TIMEOUT: "30000"
JUICEBOX_RETRIES: "3"
---
# k8s/overlays/development/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: juicebox-config
data:
JUICEBOX_BASE_URL: "https://sandbox.api.juicebox.ai"
JUICEBOX_SANDBOX: "true"
---
# k8s/overlays/staging/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: juicebox-config
data:
JUICEBOX_BASE_URL: "https://api.juicebox.ai"
JUICEBOX_SANDBOX: "false"
---
# k8s/overlays/production/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: juicebox-config
data:
JUICEBOX_BASE_URL: "https://api.juicebox.ai"
JUICEBOX_SANDBOX: "false"
JUICEBOX_TIMEOUT: "60000"
```
### Step 5: Environment Guards
```typescript
// lib/environment-guards.ts
export function requireProduction(): void {
if (process.env.NODE_ENV !== 'production') {
throw new Error('This operation is only allowed in production');
}
}
export function preventProduction(): void {
if (process.env.NODE_ENV === 'production') {
throw new Error('This operation is not allowed in production');
}
}
// Usage
async function resetTestData(): Promise<void> {
preventProduction();
await db.profiles.deleteMany({});
}
async function sendBulkOutreach(): Promise<void> {
requireProduction();
// ... production-only logic
}
```
## Environment Checklist
```markdown
## Environment Setup Verification
### Development
- [ ] Sandbox API key configured
- [ ] Mock data available
- [ ] Debug logging enabled
- [ ] Rate limits relaxed
### Staging
- [ ] Test API key configured
- [ ] Production-like data subset
- [ ] Monitoring enabled
- [ ] Matches production config
### Production
- [ ] Production API key in secret manager
- [ ] All guards enabled
- [ ] Monitoring and alerting
- [ ] Backup and recovery tested
```
## Output
- Environment-specific configurations
- Secret management per environment
- Kubernetes overlays
- Environment guards
## Resources
- [Multi-Environment Guide](https://juicebox.ai/docs/environments)
- [12-Factor App Config](https://12factor.net/config)
## Next Steps
After environment setup, see `juicebox-observability` for monitoring.
评论 0
还没有评论,来抢沙发。
相关内容
同类或同场景的收录内容
building-with-kafka-strimzi
在 Kubernetes 上构建基于 Apache Kafka 的事件驱动系统,支持高可靠的消息传递、事务性处理与精确一次语义,结合 Strimzi 运营商实现集群自动化管理,利用 Schema Registry 保障事件模式演进,适用于微服务间解耦通信与实时数据流处理场景。
站外数据与分析
609 0.0
personal-tool-builder
专注于从个人真实痛点出发快速构建实用工具,涵盖命令行程序、本地优先应用和自动化脚本的开发与演进,强调先满足自身需求再逐步扩展,通过持续自用打磨功能,避免过度设计,确保工具简洁有效且长期可维护。
站外商业与营销
196 0.0
threejs-lighting
实现三维场景中的光照与阴影控制,支持多种光源类型及环境光照明,提供从基础布光到高级阴影优化的完整方案,适用于需要真实感渲染或性能平衡的可视化项目。
站外效率工具
442 0.0
aggregation-helper
提供数据聚合场景的自动化辅助能力,涵盖 SQL 查询编写、统计分析建模、可视化方案设计及商业智能配置,支持从需求理解到生产级代码生成的全流程指导。
站外效率工具数据与分析
217 0.0
举报「juicebox-multi-env-setup」
举报信息仅审核团队可见,同一资产 24 小时内仅可举报一次