#!/usr/bin/env node /** * Generate Docker Compose Files with Versioned Images * * This script generates docker-compose files with the appropriate image tags * based on the current version and git state. */ const fs = require('fs'); const path = require('path'); const { execSync } = require('child_process'); // Configuration const REGISTRY = 'euchre-camp'; const IMAGE_NAME = 'euchre-camp'; // Get current version from package.json function getCurrentVersion() { const packageJsonPath = path.join(__dirname, '..', 'package.json'); const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')); return packageJson.version; } // Get git tag (if any) function getGitTag() { try { const tag = execSync('git describe --tags --exact-match 2>/dev/null', { encoding: 'utf8' }).trim(); return tag; } catch (error) { return null; } } // Get image tag based on git state function getImageTag() { const version = getCurrentVersion(); const gitTag = getGitTag(); if (gitTag) { // Tagged commit - use version tag return version; } else { // Untagged commit - use .dev suffix return `${version}.dev`; } } // Generate docker-compose.casaos.yml function generateCasaosYml(imageTag) { return `# CasaOS Optimized Docker Compose Configuration # This file is optimized for deployment on CasaOS # Usage: docker-compose -f docker-compose.casaos.yml up -d # # IMPORTANT: This configuration requires an external PostgreSQL database. # Set DATABASE_URL environment variable to your PostgreSQL connection string. services: app: image: ${REGISTRY}/${IMAGE_NAME}:${imageTag} container_name: euchre-camp ports: - "51193:3000" environment: # Database Configuration (REQUIRED: Set via CasaOS environment variables) - DATABASE_PROVIDER=postgresql - DATABASE_URL="postgresql://euchre_camp:LINGO5row_hiding@dhg.lol:5432/euchre_camp" - DATABASE_SHADOW_URL="postgresql://euchre_camp:LINGO5row_hiding@dhg.lol:5432/euchre_camp_shadow" # Better Auth Configuration - BETTER_AUTH_SECRET=\${BETTER_AUTH_SECRET:-change-this-secret-in-production} - BETTER_AUTH_URL=\${BETTER_AUTH_URL:-http://localhost:3000} # Application Configuration - NODE_ENV=production # Trusted Origins for Better Auth - TRUSTED_ORIGINS=\${TRUSTED_ORIGINS:-http://localhost:3000,http://127.0.0.1:3000} # Version tracking - IMAGE_VERSION=${imageTag} volumes: # Persist uploaded files and static content - /DATA/AppData/euchre-camp/config:/app/public/uploads restart: unless-stopped networks: - euchre-network volumes: euchre_camp_app_data: driver: local networks: euchre-network: driver: bridge `; } // Generate docker-compose.yml (production with PostgreSQL) function generateDockerComposeYml(imageTag) { return `# Production Docker Compose Configuration # Usage: docker-compose up -d services: app: image: ${REGISTRY}/${IMAGE_NAME}:${imageTag} container_name: euchre-camp-app ports: - "3000:3000" environment: # Database Configuration - DATABASE_PROVIDER=postgresql - DATABASE_URL=postgresql://euchre_camp:password@db:5432/euchre_camp - DATABASE_SHADOW_URL=postgresql://euchre_camp:password@db:5432/euchre_camp_shadow # Better Auth Configuration - BETTER_AUTH_SECRET=\${BETTER_AUTH_SECRET:-change-this-secret-in-production} - BETTER_AUTH_URL=\${BETTER_AUTH_URL:-http://localhost:3000} # Application Configuration - NODE_ENV=production # Trusted Origins for Better Auth - TRUSTED_ORIGINS=\${TRUSTED_ORIGINS:-http://localhost:3000,http://127.0.0.1:3000} # Version tracking - IMAGE_VERSION=${imageTag} depends_on: - db restart: unless-stopped networks: - euchre-network db: image: postgres:15-alpine container_name: euchre-camp-db ports: - "5432:5432" environment: - POSTGRES_DB=euchre_camp - POSTGRES_USER=euchre_camp - POSTGRES_PASSWORD=password volumes: - euchre_camp_db_data:/var/lib/postgresql/data - ./scripts/init-postgres.sh:/docker-entrypoint-initdb.d/init-postgres.sh restart: unless-stopped networks: - euchre-network volumes: euchre_camp_db_data: driver: local networks: euchre-network: driver: bridge `; } // Generate docker-compose.dev.yml (development with hot reload) function generateDockerComposeDevYml(imageTag) { return `# Development Docker Compose Configuration # Usage: docker-compose -f docker-compose.dev.yml up -d services: app: build: context: . target: builder args: GIT_COMMIT: \${GIT_COMMIT:-dev} container_name: euchre-camp-dev ports: - "3000:3000" environment: # Database Configuration - DATABASE_PROVIDER=postgresql - DATABASE_URL=postgresql://euchre_camp:password@db:5432/euchre_camp - DATABASE_SHADOW_URL=postgresql://euchre_camp:password@db:5432/euchre_camp_shadow # Better Auth Configuration - BETTER_AUTH_SECRET=\${BETTER_AUTH_SECRET:-dev-secret-change-in-production} - BETTER_AUTH_URL=\${BETTER_AUTH_URL:-http://localhost:3000} # Application Configuration - NODE_ENV=development # Trusted Origins for Better Auth - TRUSTED_ORIGINS=\${TRUSTED_ORIGINS:-http://localhost:3000,http://127.0.0.1:3000} # Version tracking - IMAGE_VERSION=${imageTag}-dev volumes: # Mount source code for hot reload - .:/app - /app/node_modules - /app/.next depends_on: - db restart: unless-stopped networks: - euchre-network db: image: postgres:15-alpine container_name: euchre-camp-db-dev ports: - "5433:5432" # Different port to avoid conflicts environment: - POSTGRES_DB=euchre_camp - POSTGRES_USER=euchre_camp - POSTGRES_PASSWORD=password volumes: - euchre_camp_db_data_dev:/var/lib/postgresql/data - ./scripts/init-postgres.sh:/docker-entrypoint-initdb.d/init-postgres.sh restart: unless-stopped networks: - euchre-network volumes: euchre_camp_db_data_dev: driver: local networks: euchre-network: driver: bridge `; } // Main function function main() { const imageTag = getImageTag(); console.log('šŸ”§ Generating Docker Compose files...\n'); console.log(`Registry: ${REGISTRY}`); console.log(`Image: ${IMAGE_NAME}`); console.log(`Tag: ${imageTag}\n`); // Generate casaos configuration const casaosContent = generateCasaosYml(imageTag); fs.writeFileSync( path.join(__dirname, '..', 'docker-compose.casaos.yml'), casaosContent ); console.log('āœ“ Generated docker-compose.casaos.yml'); // Generate production configuration const prodContent = generateDockerComposeYml(imageTag); fs.writeFileSync( path.join(__dirname, '..', 'docker-compose.yml'), prodContent ); console.log('āœ“ Generated docker-compose.yml'); // Generate development configuration const devContent = generateDockerComposeDevYml(imageTag); fs.writeFileSync( path.join(__dirname, '..', 'docker-compose.dev.yml'), devContent ); console.log('āœ“ Generated docker-compose.dev.yml'); console.log('\nāœ… Docker Compose files generated successfully'); console.log('\nNext steps:'); console.log(' 1. Review the generated files'); console.log(' 2. Commit changes to git'); console.log(' 3. Run: docker-compose build'); console.log(' 4. Run: docker-compose push'); } // Run main function main();