Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 56 additions & 2 deletions docker-init-windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@ param (
[Parameter(Mandatory=$true)][string]$api_host,
[Parameter(Mandatory=$true)][string]$token,
[Parameter(Mandatory=$true)][string]$dns_name,
[Parameter(Mandatory=$true)][string]$ip
[Parameter(Mandatory=$true)][string]$ip,
[bool]$use_tempdir_symlink = $true
)

Update-StorageProviderCache -DiscoveryLevel Full
$offlineDisks = Get-Disk | Where-Object PartitionStyle -Eq 'RAW'
$disksCount = $offlineDisks.Number.Count
$docker_root = "D:/docker"
$sourceTmp = if (-not [string]::IsNullOrWhiteSpace($env:SYSTEMTEMP)) { $env:SYSTEMTEMP } else { 'C:\Windows\SystemTemp' }
$targetTmp = if (-not [string]::IsNullOrWhiteSpace($env:DOCKER_TMPDIR)) { $env:DOCKER_TMPDIR } else { 'D:\SystemTemp' }

if (($disksCount -eq 0) -and (!(Test-Path D:))) {$dockerRoot = "C:/ProgramData/docker"}

if (($disksCount -eq 0) -and (!(Test-Path D:))) {
$docker_root = "C:/ProgramData/docker"
$targetTmp = $sourceTmp
}
Elseif ($disksCount -gt 1) {
$PhysicalDisks = Get-StorageSubSystem -FriendlyName "Windows Storage*" | Get-PhysicalDisk -CanPool $True
New-StoragePool -FriendlyName CodefreshData -StorageSubsystemFriendlyName "Windows Storage*" -PhysicalDisks $PhysicalDisks
Expand All @@ -23,6 +30,53 @@ ElseIf ($disksCount -eq 1) {
New-Partition -DiskNumber 1 -UseMaximumSize -AssignDriveLetter | Format-Volume -NewFileSystemLabel "Drive" -FileSystem NTFS
}

function createSymlink(){

if ($sourceTmp -eq $targetTmp) {
return
}

Stop-Service docker -ErrorAction SilentlyContinue

if (-not (Test-Path -LiteralPath $targetTmp)) {
New-Item -ItemType Directory -Path $targetTmp | Out-Null
}

$srcItem = Get-Item -LiteralPath $sourceTmp -ErrorAction SilentlyContinue
$normalize = { param($p) ([IO.Path]::GetFullPath($p)).TrimEnd('\') }

if ($srcItem) {
$isReparse = ($srcItem.Attributes -band [IO.FileAttributes]::ReparsePoint) -ne 0
if ($isReparse) {
$curTargetTmp = $srcItem.Target
if ($curTargetTmp -is [array]) { $curTargetTmp = $curTargetTmp[0] }
if ($curTargetTmp -and & $normalize $curTargetTmp -ieq (& $normalize $targetTmp)) {
Write-Host "Link exists yet: $sourceTmp → $curTargetTmp."
} else {
Write-Host "Link exists yet but points to wrong target: $sourceTmp → $curTargetTmp."
}
} else {
$oldSourceTmp = "$sourceTmp.old"
if (Test-Path -LiteralPath $oldSourceTmp) {
$oldSourceTmp = "$sourceTmp.old_{0:yyyyMMdd_HHmmss}" -f (Get-Date)
}
Write-Host "Renaming '$sourceTmp' -> '$(Split-Path -Leaf $oldSourceTmp)'..."
Rename-Item -LiteralPath $sourceTmp -NewName (Split-Path -Leaf $oldSourceTmp) -Force

Write-Host "Creating junction $sourceTmp → $targetTmp ..."
cmd /c "mklink /J `"$sourceTmp`" `"$targetTmp`"" | Out-Null
}
} else {
Write-Host "Creating junction $sourceTmp → $targetTmp ..."
cmd /c "mklink /J `"$sourceTmp`" `"$targetTmp`"" | Out-Null
}
Start-Service docker -ErrorAction SilentlyContinue
}

if ($use_tempdir_symlink) {
createSymlink
}

$release_id = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion').ReleaseId
$script_path = ($pwd.Path + '\cloud-init.sh').Replace('\', '/');

Expand Down
53 changes: 52 additions & 1 deletion hybrid/hybrid-windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ param (
[string]$token = $(Read-Host "`nInput the node registration token, please"),
[string]$api_host = $(Read-Host "`nInput the codefresh installation hostname, please. Default: g.codefresh.io"),
[string]$docker_root = $(Read-Host "`nInput the docker root path, please. It is recommended to have it on a separate disk. Default: C:/ProgramData/Docker"),
[string]$ip = $(Read-Host "`nInput the IP of the node. It must be reachable by the CF application")
[string]$ip = $(Read-Host "`nInput the IP of the node. It must be reachable by the CF application"),
[bool]$use_tempdir_symlink = $true
)

$sourceTmp = if (-not [string]::IsNullOrWhiteSpace($env:SYSTEMTEMP)) { $env:SYSTEMTEMP } else { 'C:\Windows\SystemTemp' }
$targetTmp = if (-not [string]::IsNullOrWhiteSpace($env:DOCKER_TMPDIR)) { $env:DOCKER_TMPDIR } else { 'D:\SystemTemp' }

function installCygwin() {
Write-Host "`nInstalling Cygwin...";

Expand All @@ -28,6 +32,49 @@ function checkDockerInstalled() {
}
}

function createSymlink(){

if ($sourceTmp -eq $targetTmp) {
return
}

Stop-Service docker -ErrorAction SilentlyContinue

if (-not (Test-Path -LiteralPath $targetTmp)) {
New-Item -ItemType Directory -Path $targetTmp | Out-Null
}

$srcItem = Get-Item -LiteralPath $sourceTmp -ErrorAction SilentlyContinue
$normalize = { param($p) ([IO.Path]::GetFullPath($p)).TrimEnd('\') }

if ($srcItem) {
$isReparse = ($srcItem.Attributes -band [IO.FileAttributes]::ReparsePoint) -ne 0
if ($isReparse) {
$curTargetTmp = $srcItem.Target
if ($curTargetTmp -is [array]) { $curTargetTmp = $curTargetTmp[0] }
if ($curTargetTmp -and & $normalize $curTargetTmp -ieq (& $normalize $targetTmp)) {
Write-Host "Link exists yet: $sourceTmp → $curTargetTmp."
} else {
Write-Host "Link exists yet but points to wrong target: $sourceTmp → $curTargetTmp."
}
} else {
$oldSourceTmp = "$sourceTmp.old"
if (Test-Path -LiteralPath $oldSourceTmp) {
$oldSourceTmp = "$sourceTmp.old_{0:yyyyMMdd_HHmmss}" -f (Get-Date)
}
Write-Host "Renaming '$sourceTmp' -> '$(Split-Path -Leaf $oldSourceTmp)'..."
Rename-Item -LiteralPath $sourceTmp -NewName (Split-Path -Leaf $oldSourceTmp) -Force

Write-Host "Creating junction $sourceTmp → $targetTmp ..."
cmd /c "mklink /J `"$sourceTmp`" `"$targetTmp`"" | Out-Null
}
} else {
Write-Host "Creating junction $sourceTmp → $targetTmp ..."
cmd /c "mklink /J `"$sourceTmp`" `"$targetTmp`"" | Out-Null
}
Start-Service docker -ErrorAction SilentlyContinue
}

function writeEmbeddedRegScript() {
$global:script_path = ($pwd.Path + '\cloud-init.sh').Replace('\', '/');

Expand Down Expand Up @@ -461,6 +508,10 @@ function configureNode() {
throw "Your Windows Server release is not supported"
}

if ($use_tempdir_symlink) {
createSymlink
}

Write-Host "`nStarting Codefresh node installation...`n";

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Expand Down