Skip to content

Add Docker Compose stack for complete application deployment#6

Merged
Giannoudis merged 10 commits intoPayroll-Engine:mainfrom
versohq:feature/docker-stack
Jul 17, 2025
Merged

Add Docker Compose stack for complete application deployment#6
Giannoudis merged 10 commits intoPayroll-Engine:mainfrom
versohq:feature/docker-stack

Conversation

@gsayer
Copy link
Copy Markdown
Contributor

@gsayer gsayer commented Jul 9, 2025

Overview

This PR implements a complete Docker Compose stack for the PayrollEngine application, addressing the community request for containerized deployment.

What's Changed

  • ✅ Added comprehensive docker-compose.yml for full stack deployment
  • ✅ Created database initialization script with multi-role user setup
  • ✅ Configured health checks for all services
  • ✅ Added SQL Server database service with persistent storage
  • ✅ Integrated all components (Backend, WebApp, DbQuery, Database)

Code Changes Explanation

These changes integrate Docker support without modifying existing functionality:

1. Docker Compose Configuration

  • File added: docker-compose.yml
  • Purpose: Orchestrates all services (database, backend, webapp, db-query) with proper dependencies
  • Features: Health checks, environment variables, persistent storage, service networking
  • Impact: Enables full stack deployment with single command

2. Database Initialization Script

  • File added: init-database.sh
  • Purpose: Automated database setup with multi-role user creation
  • Features:
    • Creates database schema using DbQuery tool
    • Sets up default tenant
    • Creates users with different roles (Admin, TenantAdmin, Employee, User)
  • Impact: Eliminates manual setup steps for new deployments

3. Submodule Integration

  • Files modified: References to submodules (Backend, WebApp, DbQuery)
  • Changes: Updated submodule pointers to include Docker-compatible versions
  • Why: Ensures all components work together in containerized environment
  • Impact: Maintains version consistency across all components

4. Environment Configuration

  • Approach: All configuration through environment variables
  • Benefits: No hardcoded values, supports different deployment environments
  • Security: Database credentials configurable, no secrets in code

Why These Changes

  • Addresses community request for Docker containerization
  • Enables one-command deployment for development and testing
  • Provides consistent environment across different systems
  • Simplifies onboarding for new developers
  • Facilitates easier production deployment

Features

  • One-command deployment with docker-compose up
  • Health checks for all services
  • Multi-role user system (Admin, TenantAdmin, Employee, User)
  • SQL Server database with automated initialization
  • Development and production ready configurations
  • Persistent database storage

How to Test

  1. Prerequisites: Docker and Docker Compose installed

  2. Clone and start services:

    git clone https://github.com/Payroll-Engine/PayrollEngine.git
    cd PayrollEngine
    git submodule update --init --recursive
    docker-compose up -d
  3. Initialize database:

    chmod +x init-database.sh
    ./init-database.sh
  4. Verify services:

  5. Test login with created users:

    • System Admin: admin / Admin123!
    • Tenant Admin: tenant_admin / TenantAdmin123!
    • Employee: employee / Employee123!
    • User: user / User123!
  6. Cleanup:

    docker-compose down -v

Breaking Changes

None - existing deployment methods remain unchanged.

Related Issues

Part of #2 - Request for Docker Compose Stack implementation

gsayer added 6 commits July 8, 2025 20:57
- Replace custom DbQuery tool with standard sqlcmd for database initialization
- Use mcr.microsoft.com/mssql-tools image for more reliable db-init service
- Configure services to use HTTP only (remove HTTPS to avoid certificate issues)
- Add restart policy for webapp service
- Add .env file with database password configuration
- Improve service dependencies and startup order
remove Docker doc > Docker.md
@gsayer
Copy link
Copy Markdown
Contributor Author

gsayer commented Jul 9, 2025

My init-database.sh

#!/bin/bash

# Configuration
API_URL="http://localhost:5001/api"
TENANT_ID="SimplePayroll"

echo "=== Initializing the PayrollEngine database ==="

# Wait for the API to be available
echo "Waiting for backend API..."
until curl -s "$API_URL/tenants" > /dev/null; do
  echo -n "."
  sleep 1
done
echo "Backend API ready."

# 1. Create the tenant
echo "Creating tenant..."
TENANT_RESPONSE=$(curl -s -X POST "$API_URL/tenants" \
  -H "Content-Type: application/json" \
  -d "{
    \"identifier\": \"$TENANT_ID\",
    \"culture\": \"en-US\",
    \"calendar\": \"Gregorian\",
    \"attributes\": {}
  }")

TENANT_DB_ID=$(echo "$TENANT_RESPONSE" | jq -r '.id' 2>/dev/null)

if [ "$TENANT_DB_ID" = "null" ] || [ -z "$TENANT_DB_ID" ]; then
  # Check if the tenant already exists
  if echo "$TENANT_RESPONSE" | grep -q "already exists"; then
    echo "Tenant already exists, retrieving ID..."
    TENANT_DB_ID=$(curl -s "$API_URL/tenants" | jq -r ".[] | select(.identifier==\"$TENANT_ID\") | .id")
    if [ "$TENANT_DB_ID" = "null" ] || [ -z "$TENANT_DB_ID" ]; then
      echo "Error: Unable to retrieve existing tenant ID."
      exit 1
    fi
    echo "Tenant found with ID: $TENANT_DB_ID"
  else
    echo "Error: Failed to create tenant. API response:"
    echo $TENANT_RESPONSE
    exit 1
  fi
else
  echo "Tenant created with ID: $TENANT_DB_ID"
fi

# Function to create a user
create_user() {
  local user_identifier="$1"
  local display_name="$2"
  local password="$3"
  local user_type="$4"
  local role_name="$5"
  
  echo "Creating user $role_name ($user_identifier)..."
  
  # Check if user already exists and delete if needed
  EXISTING_USER_ID=$(curl -s "$API_URL/tenants/$TENANT_DB_ID/users" | jq -r ".[] | select(.identifier==\"$user_identifier\") | .id" 2>/dev/null)
  if [ "$EXISTING_USER_ID" != "null" ] && [ ! -z "$EXISTING_USER_ID" ]; then
    echo "User $user_identifier already exists (ID: $EXISTING_USER_ID), deleting..."
    curl -s -X DELETE "$API_URL/tenants/$TENANT_DB_ID/users/$EXISTING_USER_ID"
    echo "Existing user deleted."
  fi

  # Create user
  USER_RESPONSE=$(curl -s -X POST "$API_URL/tenants/$TENANT_DB_ID/users" \
    -H "Content-Type: application/json" \
    -d "{
      \"identifier\": \"$user_identifier\",
      \"firstName\": \"$display_name\",
      \"lastName\": \"Demo\",
      \"password\": \"\",
      \"culture\": \"en-US\",
      \"userType\": $user_type,
      \"attributes\": {}
    }")

  USER_DB_ID=$(echo "$USER_RESPONSE" | jq -r '.id' 2>/dev/null)

  if [ "$USER_DB_ID" = "null" ] || [ -z "$USER_DB_ID" ]; then
    echo "Error: Failed to create user $user_identifier. API response:"
    echo $USER_RESPONSE
    return 1
  else
    echo "User $user_identifier created with ID: $USER_DB_ID"
  fi

  # Set password
  echo "Setting password for $user_identifier..."
  PASSWORD_RESPONSE=$(curl -s -X PUT "$API_URL/tenants/$TENANT_DB_ID/users/$USER_DB_ID/password" \
    -H "Content-Type: application/json" \
    -d "{
      \"newPassword\": \"$password\"
    }")

  PASSWORD_CHECK=$(echo "$PASSWORD_RESPONSE" | jq -r '.password' 2>/dev/null)

  if [ "$PASSWORD_CHECK" = "null" ] || [ -z "$PASSWORD_CHECK" ]; then
    echo "Error: Failed to set password for $user_identifier. API response:"
    echo $PASSWORD_RESPONSE
    return 1
  fi
  echo "Password successfully set for $user_identifier."

  # Test authentication
  echo "Testing authentication for $user_identifier..."
  AUTH_TEST=$(curl -s -X POST "$API_URL/tenants/$TENANT_DB_ID/users/$USER_DB_ID/password" \
    -H "Content-Type: application/json" \
    -d "\"$password\"")

  if [ $? -eq 0 ]; then
    echo "Authentication test successful for $user_identifier."
  else
    echo "Warning: Authentication test failed for $user_identifier."
  fi
  
  echo "✅ User $role_name successfully created!"
  echo ""
}

# 2. Create all users
echo ""
echo "=== Creating users by role ==="

# Employee (userType: 0)
create_user "employee" "Employee" "@mployee3nginE" "0" "Employee"

# User (userType: 1)  
create_user "user" "User" "@ser3nginE" "1" "User"

# TenantAdministrator (userType: 2)
create_user "tenant_admin" "TenantAdmin" "@enantAdmin3nginE" "2" "TenantAdministrator"

# SystemAdministrator (userType: 3)
create_user "system_admin" "SystemAdmin" "@ystemAdmin3nginE" "3" "SystemAdministrator"

echo "=== Initialization complete ==="
echo ""
echo "🎉 All users have been successfully created!"
echo ""
echo "You can now log in at http://localhost:8081 with:"
echo ""
echo "👤 Employee (limited access):"
echo "   Username: employee"
echo "   Password: @mployee3nginE"
echo ""
echo "👤 User (standard access):"
echo "   Username: user"  
echo "   Password: @ser3nginE"
echo ""
echo "👤 Tenant Administrator (full tenant access):"
echo "   Username: tenant_admin"
echo "   Password: @enantAdmin3nginE"
echo ""
echo "👤 System Administrator (full system access):"
echo "   Username: system_admin"
echo "   Password: @ystemAdmin3nginE"

gsayer added 4 commits July 13, 2025 21:03
- Force linux/amd64 platform for SQL Server and SQL Tools containers
- Improves database connection reliability across different architectures
- Adds connection test before database initialization
- Addresses cross-platform issues reported in PayrollEngine/PayrollEngine#2
- Update docker-compose.yml to use SQL Server 2022 compatible tools
- Replace obsolete mssql-tools with mssql/server:2022-latest image
- Update all sqlcmd references to sqlcmd18 for SQL Server 2022 compatibility
- Add MSSQL_PID=Developer environment variable for proper configuration
- Force platform: linux/amd64 for cross-platform compatibility

Resolves GitHub discussion Payroll-Engine#2 point 1: SA login authentication failures
- Add password requirements to avoid special characters
- Document alphanumeric-only password policy
- Include SQL Server connection verification command
- Address authentication issues that appear as 'sqlcmd not found' errors

Resolves authentication failures caused by special characters in passwords
that were reported in GitHub Discussion Payroll-Engine#2.
@Giannoudis Giannoudis merged commit e805ea1 into Payroll-Engine:main Jul 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants