-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_dockerfile.ps1
More file actions
35 lines (28 loc) · 1.43 KB
/
generate_dockerfile.ps1
File metadata and controls
35 lines (28 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Script PowerShell pour générer le Dockerfile (équivalent à generate_dockerfile.py)
# Utile pour tester localement sans Python installé
$config = Get-Content "config.json" -Raw | ConvertFrom-Json
$template = Get-Content "dockerfile.template" -Raw -Encoding UTF8
# Remplace PHP_VERSION
$dockerfile = $template -replace '%%PHP_VERSION%%', $config.php_version
# Remplace SYSTEM_TOOLS avec indentation correcte
$systemTools = ($config.system_tools | ForEach-Object { " $_ \" }) -join "`n"
# Retire le backslash du dernier élément
$systemTools = $systemTools.TrimEnd(' \')
$dockerfile = $dockerfile -replace '%%SYSTEM_TOOLS%%', $systemTools
# Remplace PHP_EXTENSIONS (Core + PECL ensemble, sur une seule ligne)
$phpExts = $config.php_extensions -join " "
$dockerfile = $dockerfile -replace '%%PHP_EXTENSIONS%%', $phpExts
# Remplace PHP_INI_SETTINGS (format INI simple)
$phpIniLines = @()
foreach ($setting in $config.php_ini_settings.PSObject.Properties) {
if ($setting.Name -eq 'date.timezone') {
$phpIniLines += "$($setting.Name) = `"$($setting.Value)`""
} else {
$phpIniLines += "$($setting.Name) = $($setting.Value)"
}
}
$phpIniContent = $phpIniLines -join "`n"
$dockerfile = $dockerfile -replace '%%PHP_INI_SETTINGS%%', $phpIniContent
# Écrit le Dockerfile
$dockerfile | Out-File -FilePath "dockerfile" -Encoding UTF8 -NoNewline
Write-Host "dockerfile generated successfully from config.json" -ForegroundColor Green