major-domo-v2/BUILD_AND_PUSH.md
Cal Corum 5924249481 CLAUDE: Add comprehensive Docker deployment infrastructure
Implements production-ready Docker setup with multi-stage builds and
separate development/production configurations.

New Files:
- Dockerfile: Multi-stage build with Python 3.13
  * Builder stage: Compiles dependencies with build tools
  * Runtime stage: Minimal image (~150-200MB) with non-root user
  * Health checks and security hardening
- docker-compose.yml: Production config (pulls from Docker Hub)
  * Image: manticorum67/major-domo-discordapp:latest
  * Resource limits: 512MB RAM, 1 CPU
  * Volumes: /app/data (ro), /app/logs (rw)
- docker-compose.dev.yml: Development config (builds locally)
  * Higher resource limits: 1GB RAM, 2 CPU
  * DEBUG log level by default
- .dockerignore: Excludes unnecessary files from build context
- build-and-push.sh: Interactive build/push script for Docker Hub
- DOCKER.md: Comprehensive deployment guide (13K)
- BUILD_AND_PUSH.md: Docker Hub build/push guide (7.7K)

Configuration Updates:
- config.py: Updated sheets_credentials_path to /app/data location
- requirements.txt: Pinned all package versions for reproducibility
- .env.example: Added Docker-specific configuration

Key Features:
- Multi-stage build for optimized image size
- Non-root user (botuser, UID 1000) for security
- Separate dev/prod compose files
- Volume mounts for persistence (/app/data, /app/logs)
- Health checks and automatic restarts
- Resource limits and log rotation
- Docker Hub integration for production deployments

Docker Hub Repository: manticorum67/major-domo-discordapp

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-16 00:54:56 -05:00

7.6 KiB

Building and Pushing to Docker Hub

This guide covers building the Docker image and pushing it to Docker Hub for production deployment.

Prerequisites

  • Docker installed and running
  • Docker Hub account (username: manticorum67)
  • Write access to manticorum67/major-domo-discordapp repository

Docker Hub Repository

Repository: manticorum67/major-domo-discordapp URL: https://hub.docker.com/r/manticorum67/major-domo-discordapp

Login to Docker Hub

# Login to Docker Hub
docker login

# Enter your username: manticorum67
# Enter your password/token: [your-password-or-token]

Build and Push Workflow

1. Tag the Release

# Determine version number (use semantic versioning)
VERSION="2.0.0"

# Create git tag (optional but recommended)
git tag -a "v${VERSION}" -m "Release v${VERSION}"
git push origin "v${VERSION}"

2. Build the Image

# Build for production
docker build -t manticorum67/major-domo-discordapp:latest .

# Build with version tag
docker build -t manticorum67/major-domo-discordapp:${VERSION} .

# Or build both at once
docker build \
  -t manticorum67/major-domo-discordapp:latest \
  -t manticorum67/major-domo-discordapp:${VERSION} \
  .

3. Test the Image Locally

# Test with docker run
docker run --rm \
  --env-file .env \
  -v $(pwd)/data:/data:ro \
  -v $(pwd)/logs:/logs:rw \
  manticorum67/major-domo-discordapp:latest

# Or test with docker-compose (development)
docker-compose -f docker-compose.dev.yml up

4. Push to Docker Hub

# Push latest tag
docker push manticorum67/major-domo-discordapp:latest

# Push version tag
docker push manticorum67/major-domo-discordapp:${VERSION}

# Or push all tags
docker push manticorum67/major-domo-discordapp --all-tags

Complete Build and Push Script

#!/bin/bash
# build-and-push.sh

set -e  # Exit on error

# Configuration
VERSION="${1:-latest}"  # Use argument or default to 'latest'
DOCKER_REPO="manticorum67/major-domo-discordapp"

echo "🔨 Building Docker image..."
echo "Version: ${VERSION}"
echo "Repository: ${DOCKER_REPO}"
echo ""

# Build image with both tags
docker build \
  -t ${DOCKER_REPO}:latest \
  -t ${DOCKER_REPO}:${VERSION} \
  .

echo ""
echo "✅ Build complete!"
echo ""
echo "📤 Pushing to Docker Hub..."

# Push both tags
docker push ${DOCKER_REPO}:latest
docker push ${DOCKER_REPO}:${VERSION}

echo ""
echo "✅ Push complete!"
echo ""
echo "🎉 Image available at:"
echo "   docker pull ${DOCKER_REPO}:latest"
echo "   docker pull ${DOCKER_REPO}:${VERSION}"

Using the Build Script

# Make script executable
chmod +x build-and-push.sh

# Build and push with version
./build-and-push.sh 2.0.0

# Build and push as latest only
./build-and-push.sh

Multi-Platform Builds (Optional)

To build for multiple architectures (amd64, arm64):

# Create a builder instance
docker buildx create --name multiarch --use

# Build and push for multiple platforms
docker buildx build \
  --platform linux/amd64,linux/arm64 \
  -t manticorum67/major-domo-discordapp:latest \
  -t manticorum67/major-domo-discordapp:${VERSION} \
  --push \
  .

Versioning Strategy

Semantic Versioning

Use semantic versioning (MAJOR.MINOR.PATCH):

  • MAJOR: Breaking changes
  • MINOR: New features (backwards compatible)
  • PATCH: Bug fixes

Examples:

  • 2.0.0 - Major release with scorecard submission
  • 2.1.0 - Added new command
  • 2.1.1 - Fixed bug in existing command

Tagging Strategy

Always maintain these tags:

  1. :latest - Most recent stable release
  2. :VERSION - Specific version (e.g., 2.0.0)
  3. :MAJOR.MINOR - Minor version (e.g., 2.0) - optional
  4. :MAJOR - Major version (e.g., 2) - optional

Example Tagging

VERSION="2.0.0"

# Tag with all versions
docker build \
  -t manticorum67/major-domo-discordapp:latest \
  -t manticorum67/major-domo-discordapp:2.0.0 \
  -t manticorum67/major-domo-discordapp:2.0 \
  -t manticorum67/major-domo-discordapp:2 \
  .

# Push all tags
docker push manticorum67/major-domo-discordapp --all-tags

GitHub Actions (Optional)

Automate builds with GitHub Actions:

# .github/workflows/docker-build.yml
name: Build and Push Docker Image

on:
  push:
    tags:
      - 'v*.*.*'

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v2

      - name: Login to Docker Hub
        uses: docker/login-action@v2
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}

      - name: Extract version
        id: version
        run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT

      - name: Build and push
        uses: docker/build-push-action@v4
        with:
          context: ./discord-app-v2
          push: true
          tags: |
            manticorum67/major-domo-discordapp:latest
            manticorum67/major-domo-discordapp:${{ steps.version.outputs.VERSION }}            

Production Deployment

After pushing to Docker Hub, deploy on production:

# On production server
cd /path/to/discord-app-v2

# Pull latest image
docker-compose pull

# Restart with new image
docker-compose up -d

# Verify it's running
docker-compose logs -f discord-bot

Rollback to Previous Version

If a release has issues:

# Stop current version
docker-compose down

# Edit docker-compose.yml to use specific version
# Change: image: manticorum67/major-domo-discordapp:latest
# To:     image: manticorum67/major-domo-discordapp:2.0.0

# Pull and start old version
docker-compose pull
docker-compose up -d

Or use a specific version directly:

docker-compose down

docker pull manticorum67/major-domo-discordapp:2.0.0

docker run -d \
  --name major-domo-discord-bot-v2 \
  --env-file .env \
  -v $(pwd)/data:/data:ro \
  -v $(pwd)/logs:/logs:rw \
  manticorum67/major-domo-discordapp:2.0.0

Image Size Optimization

The multi-stage build already optimizes size, but you can verify:

# Check image size
docker images manticorum67/major-domo-discordapp

# Expected size: ~150-200MB

# Inspect layers
docker history manticorum67/major-domo-discordapp:latest

Troubleshooting

Build Fails

# Build with verbose output
docker build --progress=plain -t manticorum67/major-domo-discordapp:latest .

# Check for errors in requirements.txt
docker build --no-cache -t manticorum67/major-domo-discordapp:latest .

Push Fails

# Check if logged in
docker info | grep Username

# Re-login
docker logout
docker login

# Check repository permissions
docker push manticorum67/major-domo-discordapp:latest

Image Won't Run

# Test image interactively
docker run -it --rm \
  --entrypoint /bin/bash \
  manticorum67/major-domo-discordapp:latest

# Inside container, check Python
python --version
pip list
ls -la /app

Security Best Practices

  1. Use Docker Hub Access Tokens instead of password
  2. Enable 2FA on Docker Hub account
  3. Scan images for vulnerabilities:
    docker scan manticorum67/major-domo-discordapp:latest
    
  4. Sign images (optional):
    docker trust sign manticorum67/major-domo-discordapp:latest
    

Cleanup

Remove old local images:

# Remove dangling images
docker image prune

# Remove all unused images
docker image prune -a

# Remove specific version
docker rmi manticorum67/major-domo-discordapp:1.0.0

Additional Resources