diff --git a/dev/windows-local.compose.yml b/dev/windows-local.compose.yml new file mode 100644 index 00000000..61118187 --- /dev/null +++ b/dev/windows-local.compose.yml @@ -0,0 +1,99 @@ +# Standalone local project: do not combine with production Compose or its .env. +services: + database: + image: mariadb:12.2.2@sha256:42a27baaba3e8f3f0159d16381d5a7156661aa91dcc65f663cabb6a6f9503c00 + environment: + MARIADB_ROOT_PASSWORD: ${JT_LOCAL_DB_ROOT_PASSWORD:?Run rebuild-windows-docker.ps1 first} + MARIADB_DATABASE: jobtracker + MARIADB_USER: jobtracker + MARIADB_PASSWORD: ${JT_LOCAL_DB_PASSWORD:?Run rebuild-windows-docker.ps1 first} + volumes: + - database:/var/lib/mysql + command: ["--character-set-server=utf8mb4", "--collation-server=utf8mb4_unicode_ci"] + healthcheck: + test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"] + interval: 3s + timeout: 5s + retries: 45 + start_period: 20s + restart: unless-stopped + + backend: + image: jobjakt-windows-local-backend:latest + build: + context: .. + dockerfile: JobTrackerApi/Dockerfile + environment: + ASPNETCORE_ENVIRONMENT: Development + ASPNETCORE_URLS: http://+:8080 + Database__Provider: mariadb + Database__ServerVersion: "12.2.2" + ConnectionStrings__JobTracker: Server=database;Database=jobtracker;User ID=jobtracker;Password=${JT_LOCAL_DB_PASSWORD};SslMode=None + Data__Root: /data + AccountLifecycle__TombstonesRoot: /account-lifecycle/tombstones + Auth__Require: "true" + Auth__JwtKey: ${JT_LOCAL_JWT_KEY:?Run rebuild-windows-docker.ps1 first} + Auth__AdminEmail: ${JT_LOCAL_ADMIN_EMAIL:?Run rebuild-windows-docker.ps1 first} + Auth__AdminPassword: ${JT_LOCAL_ADMIN_PASSWORD:?Run rebuild-windows-docker.ps1 first} + Auth__AllowRegistration: "false" + App__PublicBaseUrl: http://localhost:${JT_LOCAL_PORT:-3000} + App__Version: windows-local + App__CommitSha: ${JT_LOCAL_COMMIT:-unknown} + HttpsRedirection__Enabled: "false" + Proxy__TrustForwardedHeaders: "false" + Ai__BaseUrl: http://127.0.0.1:9 + Summarizer__BaseUrl: http://127.0.0.1:9 + Ai__ExternalProcessingEnabled: "false" + Email__Enabled: "false" + AccountLifecycle__DeletionEnabled: "false" + Workers__RulesEnabled: "false" + Workers__FollowUpRemindersEnabled: "false" + Workers__SavedJobSearchAlertsEnabled: "false" + Workers__DailyExportEnabled: "false" + Workers__JobEnrichmentEnabled: "false" + Workers__AiOperationsEnabled: "false" + Workers__CvDocumentImportsEnabled: "false" + volumes: + - files:/data + - tombstones:/account-lifecycle/tombstones + depends_on: + database: + condition: service_healthy + networks: + default: + aliases: [backend-web] + healthcheck: + test: ["CMD", "curl", "-fsS", "http://127.0.0.1:8080/ready"] + interval: 5s + timeout: 5s + retries: 45 + start_period: 90s + restart: unless-stopped + + frontend: + image: jobjakt-windows-local-frontend:latest + build: + context: ../job-tracker-ui + shm_size: 1gb + args: + NEXT_PUBLIC_API_BASE_URL: /api + environment: + APP_PUBLIC_BASE_URL: http://localhost:${JT_LOCAL_PORT:-3000} + INGRESS_MODE: direct + ports: + - "127.0.0.1:${JT_LOCAL_PORT:-3000}:80" + depends_on: + backend: + condition: service_healthy + healthcheck: + test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1/health"] + interval: 3s + timeout: 5s + retries: 20 + start_period: 10s + restart: unless-stopped + +volumes: + database: + files: + tombstones: diff --git a/docs/development/WINDOWS_DOCKER.md b/docs/development/WINDOWS_DOCKER.md new file mode 100644 index 00000000..1fc6ee02 --- /dev/null +++ b/docs/development/WINDOWS_DOCKER.md @@ -0,0 +1,37 @@ +# Rebuild and run locally on Windows + +Start Docker Desktop in **Linux containers** mode, then run PowerShell: + +```powershell +powershell -NoProfile -ExecutionPolicy Bypass -File "C:\Users\Connor\.codex\worktrees\direct-roadmap-integration\Job tracker\scripts\rebuild-windows-docker.ps1" +``` + +Open http://localhost:3000 after the script finishes. It rebuilds backend/frontend from that checkout, reports its branch/commit and starts a separate `jobjakt-windows-local` project. It neither pulls Git changes nor selects `main`; run it again after development checkpoints are integrated into this checkout. Working-copy changes are included in Docker's ordinary build context. First build needs internet for existing base images and locked dependencies. + +Login is `local-admin@example.test`. The generated password is the `JT_LOCAL_ADMIN_PASSWORD` value in `.env.windows-local` at the checkout root; open that private file locally to read it. The file is ignored by Git. Keep it and use the same checkout for subsequent rebuilds: changing database credentials after volumes exist prevents connection. The separate local database starts empty; existing production accounts/data are not imported. + +Useful options: + +```powershell +# Use another local port if3000 is occupied. +.\scripts\rebuild-windows-docker.ps1 -Port 3001 + +# Validate configuration without building or starting containers. +.\scripts\rebuild-windows-docker.ps1 -ValidateOnly + +# Rebuild without Docker layer cache when needed. +.\scripts\rebuild-windows-docker.ps1 -NoCache + +# Stop this local project, retaining its database/files and credentials. +docker --context desktop-linux compose --project-name jobjakt-windows-local --env-file .env.windows-local -f dev/windows-local.compose.yml stop +``` + +The last commands run from the same checkout root. `-DockerContext default` is available if that is your local Linux Docker context. The start path rejects remote Docker endpoints and non-Linux engines. The script never deletes volumes or pushes images. Database/files/tombstones have separate named volumes owned by this project; only frontend port3000 is exposed, on127.0.0.1. The API/database are internal. + +This stack intentionally has no AI sidecar/Ollama, mail delivery or background provider/model workers. Existing manual application/Career/CV/PDF workflows remain available; generative and sidecar-dependent import functions need their separately approved test stack. AI activation remains a separate owner decision, including model identity and local-only routing. No production Compose/environment is loaded. + +## Verification + +18November2026: PowerShell parser and rendered Compose contract tests **2/2 PASSED**, zero skips; `-ValidateOnly` twice PASSED, preserving the credential file. Checks cover exact build contexts, three-service allowlist, loopback port, internal API/database, persistent project-owned volumes, same-origin routing, authentication and disabled external/background processing. `python scripts/test-windows-docker.py` executes no build/container commands. + +**Docker build/start NOT RUN:** local Docker Desktop Linux engine pipe was absent when inspected. Start Docker Desktop before running the script. Source/static checks do not establish container startup, image builds, Node20 compatibility, database migration parity, PDF fidelity or full release qualification. diff --git a/scripts/rebuild-windows-docker.ps1 b/scripts/rebuild-windows-docker.ps1 new file mode 100644 index 00000000..59be012b --- /dev/null +++ b/scripts/rebuild-windows-docker.ps1 @@ -0,0 +1,83 @@ +[CmdletBinding()] +param( + [ValidateRange(1024, 65535)][int]$Port = 3000, + [ValidateSet('desktop-linux', 'default')][string]$DockerContext = 'desktop-linux', + [switch]$NoCache, + [switch]$ValidateOnly +) + +$ErrorActionPreference = 'Stop' +$repo = Split-Path -Parent $PSScriptRoot +$composeFile = Join-Path $repo 'dev/windows-local.compose.yml' +$envFile = Join-Path $repo '.env.windows-local' +$project = 'jobjakt-windows-local' + +function Invoke-DockerChecked { + param([string[]]$DockerArguments) + & docker --context $DockerContext @DockerArguments + if ($LASTEXITCODE -ne 0) { throw "Docker failed (exit $LASTEXITCODE). Existing data volumes have been retained." } +} + +function New-LocalSecret { + $bytes = New-Object byte[] 32 + $random = [System.Security.Cryptography.RandomNumberGenerator]::Create() + try { $random.GetBytes($bytes) } finally { $random.Dispose() } + return ([BitConverter]::ToString($bytes)).Replace('-', '').ToLowerInvariant() +} + +Get-Command docker -ErrorAction Stop | Out-Null +$sourceCommit = & git -C $repo rev-parse HEAD +if ($LASTEXITCODE -ne 0) { throw 'Run this script from its existing Git checkout.' } +$sourceBranch = & git -C $repo branch --show-current +Write-Host "Building checkout $sourceBranch at $sourceCommit" +Write-Host 'No fetch, reset, production Compose, image push or volume deletion is performed.' + +if (-not (Test-Path -LiteralPath $envFile)) { + # Reuse on later runs: replacing these passwords would break existing volumes. + $lines = @( + "JT_LOCAL_DB_ROOT_PASSWORD=$(New-LocalSecret)", + "JT_LOCAL_DB_PASSWORD=$(New-LocalSecret)", + "JT_LOCAL_JWT_KEY=$(New-LocalSecret)", + 'JT_LOCAL_ADMIN_EMAIL=local-admin@example.test', + "JT_LOCAL_ADMIN_PASSWORD=Jt1!$(New-LocalSecret)" + ) + [IO.File]::WriteAllLines($envFile, $lines, (New-Object Text.UTF8Encoding($false))) + Write-Host "Created private local credentials: $envFile" +} + +$previousPort = $env:JT_LOCAL_PORT +$previousCommit = $env:JT_LOCAL_COMMIT +try { + $env:JT_LOCAL_PORT = [string]$Port + $env:JT_LOCAL_COMMIT = $sourceCommit + $composeArgs = @('compose', '--project-name', $project, + '--env-file', $envFile, '-f', $composeFile) + Invoke-DockerChecked -DockerArguments ($composeArgs + @('config', '--quiet')) + if ($ValidateOnly) { + Write-Host 'Compose configuration is valid; no images built or containers started.' + return + } + + $contextJson = & docker context inspect $DockerContext + if ($LASTEXITCODE -ne 0) { throw "Docker context '$DockerContext' was not found. Start Docker Desktop in Linux containers mode." } + $endpoint = ($contextJson | ConvertFrom-Json)[0].Endpoints.docker.Host + if ($endpoint -notlike 'npipe://*') { throw 'This script only starts a local Windows Docker named-pipe engine.' } + $engine = & docker --context $DockerContext info --format '{{.OSType}}' 2>$null + if ($LASTEXITCODE -ne 0 -or $engine -ne 'linux') { + throw 'Start Docker Desktop, select Linux containers, wait until the engine is ready, then rerun this script.' + } + + $buildArgs = @('build', 'backend', 'frontend') + if ($NoCache) { $buildArgs = @('build', '--no-cache', 'backend', 'frontend') } + Invoke-DockerChecked -DockerArguments ($composeArgs + $buildArgs) + Invoke-DockerChecked -DockerArguments ($composeArgs + @('up', '-d', '--wait', '--wait-timeout', '300', 'database', 'backend', 'frontend')) + Invoke-DockerChecked -DockerArguments ($composeArgs + @('ps')) + Write-Host "Open http://localhost:$Port" + Write-Host 'Login: local-admin@example.test (password is JT_LOCAL_ADMIN_PASSWORD in the private credentials file).' + Write-Host "Credentials: $envFile" + Write-Host 'Re-running this script rebuilds the current checkout and retains the local database/files.' +} +finally { + $env:JT_LOCAL_PORT = $previousPort + $env:JT_LOCAL_COMMIT = $previousCommit +} diff --git a/scripts/test-windows-docker.py b/scripts/test-windows-docker.py new file mode 100644 index 00000000..1a40551e --- /dev/null +++ b/scripts/test-windows-docker.py @@ -0,0 +1,65 @@ +"""Offline configuration checks; never build images or start containers.""" +import json +import os +from pathlib import Path +import shutil +import subprocess +import tempfile +import unittest + +ROOT = Path(__file__).resolve().parents[1] + + +class WindowsDockerTests(unittest.TestCase): + def test_powershell_script_parses(self): + shell = shutil.which('powershell') or shutil.which('pwsh') + if not shell: + self.skipTest('PowerShell is not installed') + script = ROOT / 'scripts/rebuild-windows-docker.ps1' + code = ('$errors=$null; $tokens=$null; ' + '[System.Management.Automation.Language.Parser]::ParseFile(' + + "'" + str(script).replace("'", "''") + "'" + + ', [ref]$tokens, [ref]$errors) | Out-Null; ' + 'if ($errors.Count) { $errors | Write-Error; exit 1 }') + result = subprocess.run([shell, '-NoProfile', '-Command', code], capture_output=True, text=True) + self.assertEqual(0, result.returncode, result.stderr) + + def test_rendered_compose_is_local_persistent_and_uses_this_checkout(self): + with tempfile.TemporaryDirectory() as folder: + env_file = Path(folder) / '.env' + env_file.write_text('\n'.join([ + 'JT_LOCAL_DB_ROOT_PASSWORD=fixture-root', 'JT_LOCAL_DB_PASSWORD=fixture-database', + 'JT_LOCAL_JWT_KEY=fixture-signing-key-not-a-real-secret', + 'JT_LOCAL_ADMIN_EMAIL=local-admin@example.test', 'JT_LOCAL_ADMIN_PASSWORD=Fixture1!', + 'JT_LOCAL_PORT=3100', 'JT_LOCAL_COMMIT=fixture-commit', + ]), encoding='utf-8') + environment = {key: value for key, value in os.environ.items() if not key.startswith('JT_LOCAL_')} + result = subprocess.run([ + 'docker', 'compose', '--project-name', 'jobjakt-windows-local', '--env-file', str(env_file), + '-f', str(ROOT / 'dev/windows-local.compose.yml'), 'config', '--format', 'json', + ], capture_output=True, text=True, env=environment) + self.assertEqual(0, result.returncode, result.stderr) + config = json.loads(result.stdout) + services = config['services'] + self.assertEqual({'database', 'backend', 'frontend'}, set(services)) + self.assertEqual('jobjakt-windows-local', config['name']) + self.assertFalse(services['database'].get('ports')) + self.assertFalse(services['backend'].get('ports')) + port = services['frontend']['ports'][0] + self.assertEqual(('127.0.0.1', '3100', 80), (port['host_ip'], port['published'], port['target'])) + self.assertEqual(ROOT.resolve(), Path(services['backend']['build']['context']).resolve()) + self.assertEqual((ROOT / 'job-tracker-ui').resolve(), Path(services['frontend']['build']['context']).resolve()) + backend = services['backend']['environment'] + self.assertEqual('Server=database;Database=jobtracker;User ID=jobtracker;Password=fixture-database;SslMode=None', backend['ConnectionStrings__JobTracker']) + self.assertEqual('true', backend['Auth__Require']) + self.assertEqual('http://localhost:3100', backend['App__PublicBaseUrl']) + self.assertEqual('false', backend['Ai__ExternalProcessingEnabled']) + self.assertTrue(all(value == 'false' for key, value in backend.items() if key.startswith('Workers__'))) + self.assertEqual('direct', services['frontend']['environment']['INGRESS_MODE']) + self.assertEqual('/api', services['frontend']['build']['args']['NEXT_PUBLIC_API_BASE_URL']) + self.assertEqual({'database', 'files', 'tombstones'}, set(config['volumes'])) + self.assertFalse(any(volume.get('external') for volume in config['volumes'].values())) + + +if __name__ == '__main__': + unittest.main()