Infra deployment specialist

From NaveedTechLab/skills-library · View interactive version

Infra deployment specialist is an AI agent skill from the GitHub repository NaveedTechLab/skills-library. Expert in Docker containerization, Neon PostgreSQL database management, Hugging Face Spaces deployment, and environment variable configuration. Use when: (1) Dockerizing applications with Dockerfile or docker-compose.yml, (2) Setting up Neon PostgreSQL connections, migrations, or schema management,

How to use this skill

Skill file

Infra & Deployment Specialist

Expert guidance for Docker containerization, Neon PostgreSQL integration, Hugging Face Spaces deployment, and environment management.

Quick Start

Docker Containerization

FastAPI Backend Only
# Copy Dockerfile template
cp assets/docker-templates/Dockerfile.fastapi ./backend/Dockerfile

# Build and run
cd backend
docker build -t backend .
docker run -p 8000:8000 --env-file .env backend
Next.js Frontend Only
# Copy Dockerfile template
cp assets/docker-templates/Dockerfile.nextjs ./frontend/Dockerfile

# Update next.config.js for standalone output
# Add: output: 'standalone'

# Build and run
cd frontend
docker build -t frontend .
docker run -p 3000:3000 frontend
Full-Stack Application

Use docker-compose for multi-service setup:

# Copy docker-compose template
cp assets/docker-templates/docker-compose.yml ./

# Start all services
docker-compose up -d

# View logs
docker-compose logs -f

# Stop services
docker-compose down

Neon PostgreSQL Setup

For complete Neon integration patterns, connection pooling, and best practices, see neon-postgresql.md.

Quick Connection Setup
# app/core/config.py
from sqlalchemy.ext.asyncio import create_async_engine
import os

DATABASE_URL = os.getenv("DATABASE_URL", "").replace(
    "postgresql://", "postgresql+asyncpg://"
)

engine = create_async_engine(
    DATABASE_URL,
    pool_pre_ping=True,
    echo=False,
)
Database Initialization
# Initialize database tables
python scripts/init_db.py init

# Seed with initial data
python scripts/init_db.py seed

# Reset database (destructive)
python scripts/init_db.py reset
Database Migrations
# Make script executable
chmod +x scripts/migrate.sh

# Create new migration
./scripts/migrate.sh create "add users table"

# Apply migrations
./scripts/migrate.sh apply

# Rollback last migration
./scripts/migrate.sh rollback

# View migration history
./scripts/migrate.sh history

Hugging Face Spaces Deployment

For complete deployment guide, configuration options, and troubleshooting, see huggingface-spaces.md.

Quick Deployment
  1. Copy HF Spaces templates
cp assets/hf-spaces-templates/Dockerfile ./
cp assets/hf-spaces-templates/README.md ./
  1. Configure README.md frontmatter
---
title: Your App Name
emoji: 🤖
colorFrom: blue
colorTo: purple
sdk: docker
pinned: false
---
  1. Set secrets in Space settings
  1. Deploy via Git
git clone https://huggingface.co/spaces/username/space-name
cd space-name
# Copy your files
git add .
git commit -m "Initial deployment"
git push
Important: Port 7860

Hugging Face Spaces requires apps to run on port 7860:

# main.py
if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=7860)

Environment Variable Management

For comprehensive environment management patterns, validation, and security practices, see environment-management.md.

Setup Environment Files
# Create .env from example
cp .env.example .env

# Edit with your values
nano .env
Environment File Structure
# .env
DATABASE_URL=postgresql://user:pass@host/db?sslmode=require
SECRET_KEY=your-secret-key-min-32-chars
ALLOWED_ORIGINS=http://localhost:3000

# OAuth2
TWITTER_CLIENT_ID=your_client_id
TWITTER_CLIENT_SECRET=your_client_secret
LINKEDIN_CLIENT_ID=your_client_id
LINKEDIN_CLIENT_SECRET=your_client_secret
Load in Python (FastAPI)
from pydantic_settings import BaseSettings

class Settings(BaseSettings):
    database_url: str
    secret_key: str
    allowed_origins: list[str] = ["http://localhost:3000"]

    class Config:
        env_file = ".env"

settings = Settings()
Load in TypeScript (Next.js)
// lib/env.ts
export const env = {
  NEXT_PUBLIC_API_URL: process.env.NEXT_PUBLIC_API_URL!,
  DATABASE_URL: process.env.DATABASE_URL!,
};

Docker Best Practices

Multi-Stage Builds

Reduce image size with multi-stage builds:

# Build stage
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build

# Production stage
FROM node:20-alpine
WORKDIR /app
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/node_modules ./node_modules
CMD ["npm", "start"]

Layer Caching

Optimize build times by ordering Dockerfile commands:

# Copy dependencies first (changes less frequently)
COPY requirements.txt .
RUN pip install -r requirements.txt

# Copy code last (changes frequently)
COPY . .

Health Checks

Add health checks to containers:

HEALTHCHECK --interval=30s --timeout=10s --start-period=5s \
  CMD python -c "import requests; requests.get('http://localhost:8000/health')"

Database Workflows

Initial Setup

  1. Set DATABASE_URL in .env
  2. Run python scripts/init_db.py init
  3. Verify tables created

Schema Changes

  1. Modify models in app/models/
  2. Create migration: ./scripts/migrate.sh create "description"
  3. Review generated migration in alembic/versions/
  4. Apply: ./scripts/migrate.sh apply

Production Migrations

# Use direct connection (not pooled) for migrations
export DATABASE_URL="postgresql://user:pass@ep-xxx.neon.tech/db"

# Apply migrations
./scripts/migrate.sh apply

# Verify
./scripts/migrate.sh current

Deployment Checklist

Pre-Deployment

Docker Deployment

Neon PostgreSQL

Hugging Face Spaces

Troubleshooting

Docker Issues

Build fails with dependency errors

# Clear Docker cache
docker builder prune -a

# Rebuild without cache
docker build --no-cache -t image-name .

Container exits immediately

# Check logs
docker logs container-name

# Run interactively
docker run -it image-name /bin/bash

Port already in use

# Find process using port
lsof -i :8000  # macOS/Linux
netstat -ano | findstr :8000  # Windows

# Use different port
docker run -p 8001:8000 image-name

Database Issues

Connection refused

Migration conflicts

# View current state
./scripts/migrate.sh current

# Resolve conflicts
alembic merge heads -m "merge migrations"
./scripts/migrate.sh apply

Too many connections

Hugging Face Spaces Issues

Build timeout

App not accessible

Environment variables not loading

Security Best Practices

Secrets Management

Database Security

Docker Security

API Security

Performance Optimization

Docker

Database

Deployment

Reference Documentation

When NOT to Use This Skill

Common Mistakes

Related Skills

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.