home / skills / jeremylongshore / claude-code-plugins-plus-skills / vastai-multi-env-setup

This skill configures Vast.ai across development, staging, and production, enabling secure per-environment secrets and automated environment detection.

npx playbooks add skill jeremylongshore/claude-code-plugins-plus-skills --skill vastai-multi-env-setup

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
5.2 KB
---
name: vastai-multi-env-setup
description: |
  Configure Vast.ai across development, staging, and production environments.
  Use when setting up multi-environment deployments, configuring per-environment secrets,
  or implementing environment-specific Vast.ai configurations.
  Trigger with phrases like "vastai environments", "vastai staging",
  "vastai dev prod", "vastai environment setup", "vastai config by env".
allowed-tools: Read, Write, Edit, Bash(aws:*), Bash(gcloud:*), Bash(vault:*)
version: 1.0.0
license: MIT
author: Jeremy Longshore <[email protected]>
---

# Vast.ai Multi-Environment Setup

## Overview
Configure Vast.ai across development, staging, and production environments.

## Prerequisites
- Separate Vast.ai 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 Keys | Data |
|-------------|---------|----------|------|
| Development | Local dev | Test keys | Sandbox |
| Staging | Pre-prod validation | Staging keys | Test data |
| Production | Live traffic | Production keys | Real data |

## Configuration Structure

```
config/
├── vastai/
│   ├── base.json           # Shared config
│   ├── development.json    # Dev overrides
│   ├── staging.json        # Staging overrides
│   └── production.json     # Prod overrides
```

### base.json
```json
{
  "timeout": 30000,
  "retries": 3,
  "cache": {
    "enabled": true,
    "ttlSeconds": 60
  }
}
```

### development.json
```json
{
  "apiKey": "${VASTAI_API_KEY}",
  "baseUrl": "https://api-sandbox.vastai.com",
  "debug": true,
  "cache": {
    "enabled": false
  }
}
```

### staging.json
```json
{
  "apiKey": "${VASTAI_API_KEY_STAGING}",
  "baseUrl": "https://api-staging.vastai.com",
  "debug": false
}
```

### production.json
```json
{
  "apiKey": "${VASTAI_API_KEY_PROD}",
  "baseUrl": "https://api.vastai.com",
  "debug": false,
  "retries": 5
}
```

## Environment Detection

```typescript
// src/vastai/config.ts
import baseConfig from '../../config/vastai/base.json';

type Environment = 'development' | 'staging' | 'production';

function detectEnvironment(): Environment {
  const env = process.env.NODE_ENV || 'development';
  const validEnvs: Environment[] = ['development', 'staging', 'production'];
  return validEnvs.includes(env as Environment)
    ? (env as Environment)
    : 'development';
}

export function getVast.aiConfig() {
  const env = detectEnvironment();
  const envConfig = require(`../../config/vastai/${env}.json`);

  return {
    ...baseConfig,
    ...envConfig,
    environment: env,
  };
}
```

## Secret Management by Environment

### Local Development
```bash
# .env.local (git-ignored)
VASTAI_API_KEY=sk_test_dev_***
```

### CI/CD (GitHub Actions)
```yaml
env:
  VASTAI_API_KEY: ${{ secrets.VASTAI_API_KEY_${{ matrix.environment }} }}
```

### Production (Vault/Secrets Manager)
```bash
# AWS Secrets Manager
aws secretsmanager get-secret-value --secret-id vastai/production/api-key

# GCP Secret Manager
gcloud secrets versions access latest --secret=vastai-api-key

# HashiCorp Vault
vault kv get -field=api_key secret/vastai/production
```

## Environment Isolation

```typescript
// Prevent production operations in non-prod
function guardProductionOperation(operation: string): void {
  const config = getVast.aiConfig();

  if (config.environment !== 'production') {
    console.warn(`[vastai] ${operation} blocked in ${config.environment}`);
    throw new Error(`${operation} only allowed in production`);
  }
}

// Usage
async function deleteAllData() {
  guardProductionOperation('deleteAllData');
  // Dangerous operation here
}
```

## Feature Flags by Environment

```typescript
const featureFlags: Record<Environment, Record<string, boolean>> = {
  development: {
    newFeature: true,
    betaApi: true,
  },
  staging: {
    newFeature: true,
    betaApi: false,
  },
  production: {
    newFeature: false,
    betaApi: false,
  },
};
```

## Instructions

### Step 1: Create Config Structure
Set up the base and per-environment configuration files.

### Step 2: Implement Environment Detection
Add logic to detect and load environment-specific config.

### Step 3: Configure Secrets
Store API keys securely using your secret management solution.

### Step 4: Add Environment Guards
Implement safeguards for production-only operations.

## Output
- Multi-environment config structure
- Environment detection logic
- Secure secret management
- Production safeguards enabled

## Error Handling
| Issue | Cause | Solution |
|-------|-------|----------|
| Wrong environment | Missing NODE_ENV | Set environment variable |
| Secret not found | Wrong secret path | Verify secret manager config |
| Config merge fails | Invalid JSON | Validate config files |
| Production guard triggered | Wrong environment | Check NODE_ENV value |

## Examples

### Quick Environment Check
```typescript
const env = getVast.aiConfig();
console.log(`Running in ${env.environment} with ${env.baseUrl}`);
```

## Resources
- [Vast.ai Environments Guide](https://docs.vastai.com/environments)
- [12-Factor App Config](https://12factor.net/config)

## Next Steps
For observability setup, see `vastai-observability`.

Overview

This skill configures Vast.ai across development, staging, and production environments. It provides a structured config layout, environment detection, secret management patterns, and production safeguards to reduce risk and simplify deployments.

How this skill works

It centralizes a base configuration and merges environment-specific JSON overrides at runtime. The code detects NODE_ENV to load development, staging, or production configs, reads API keys from secure stores or CI secrets, and enforces guards to prevent dangerous operations outside production. Feature flags and retry/cache settings are applied per environment.

When to use it

  • Setting up Vast.ai for distinct dev / staging / prod deployments
  • Storing and retrieving per-environment API keys securely
  • Preventing destructive actions from running in non-production
  • Implementing environment-specific endpoints, timeouts, and retries
  • Integrating Vast.ai config with CI/CD pipelines

Best practices

  • Keep a minimal base config for shared defaults and override only what differs per environment
  • Store secrets in a managed secret store (Vault, AWS Secrets Manager, GCP Secret Manager) and inject via CI or runtime
  • Use NODE_ENV or an explicit environment variable and validate values before acting
  • Disable sensitive operations by default and require explicit production guards for dangerous tasks
  • Use feature flags per environment to test features progressively

Example use cases

  • Local development: use sandbox API keys and disable cache for faster iteration
  • Staging: mirror production config with test data and run integration tests against staging keys
  • Production: enable retries, use real API keys from a secrets manager, and enforce production-only guards
  • CI/CD: matrix builds that load environment-specific secrets and test deployment flows
  • Rollback safety: prevent deleteAllData or other destructive scripts from running unless environment === production

FAQ

How do I structure config files?

Create a config/vastai/base.json for defaults and per-environment JSON files named development.json, staging.json, production.json for overrides.

Where should API keys live?

Keep keys out of source. Use local .env for dev, CI secrets for pipelines, and a secret manager for staging/production.

How do I prevent running destructive operations in the wrong env?

Implement a guard that checks the detected environment and throws or rejects operations unless environment === 'production'.