Add Docker Compose stack for complete application deployment#6
Merged
Giannoudis merged 10 commits intoPayroll-Engine:mainfrom Jul 17, 2025
Merged
Add Docker Compose stack for complete application deployment#6Giannoudis merged 10 commits intoPayroll-Engine:mainfrom
Giannoudis merged 10 commits intoPayroll-Engine:mainfrom
Conversation
- 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
Contributor
Author
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" |
- 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR implements a complete Docker Compose stack for the PayrollEngine application, addressing the community request for containerized deployment.
What's Changed
Code Changes Explanation
These changes integrate Docker support without modifying existing functionality:
1. Docker Compose Configuration
docker-compose.yml2. Database Initialization Script
init-database.sh3. Submodule Integration
4. Environment Configuration
Why These Changes
Features
docker-compose upHow to Test
Prerequisites: Docker and Docker Compose installed
Clone and start services:
git clone https://github.com/Payroll-Engine/PayrollEngine.git cd PayrollEngine git submodule update --init --recursive docker-compose up -dInitialize database:
Verify services:
Test login with created users:
Cleanup:
Breaking Changes
None - existing deployment methods remain unchanged.
Related Issues
Part of #2 - Request for Docker Compose Stack implementation