From 8e730af85dc5dfe70550102a03615e2b2035b4da Mon Sep 17 00:00:00 2001 From: Frank Tovar Date: Mon, 18 May 2026 21:13:50 +0200 Subject: [PATCH] Fix Windows deploy remote script line endings --- scripts/deploy.ps1 | 50 ++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/scripts/deploy.ps1 b/scripts/deploy.ps1 index 84cb8b7..38f1854 100644 --- a/scripts/deploy.ps1 +++ b/scripts/deploy.ps1 @@ -24,6 +24,14 @@ function Invoke-NativeCommand { } } +function ConvertTo-LinuxLineEnding { + param( + [Parameter(Mandatory = $true)][string]$Value + ) + + return $Value.Replace("`r`n", "`n").Replace("`r", "`n") +} + function Get-RemoteScript { param( [Parameter(Mandatory = $true)][string]$RemoteReleaseDir, @@ -76,7 +84,7 @@ if ! docker run -d \ fi '@ - return $script. + $script = $script. Replace("__REMOTE_RELEASE_DIR__", $RemoteReleaseDir). Replace("__REMOTE_CURRENT_LINK__", $RemoteCurrentLink). Replace("__CONTAINER_NAME__", $ContainerName). @@ -85,6 +93,8 @@ fi Replace("__REMOTE_DATA_DIR__", $RemoteDataDir). Replace("__CONTAINER_PORT__", $ContainerPort). Replace("__HOST_PORT__", $HostPort) + + return ConvertTo-LinuxLineEnding -Value $script } $scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path @@ -119,7 +129,7 @@ try { dotnet publish $projectPath -c Release -o $localPublishDir } - @' + $dockerfile = @' FROM mcr.microsoft.com/dotnet/aspnet:10.0 WORKDIR /app ENV ASPNETCORE_URLS=http://+:8080 @@ -128,21 +138,10 @@ EXPOSE 8080 COPY publish/ ./ RUN mkdir -p /app/data ENTRYPOINT ["dotnet", "RpgRoller.dll"] -'@ | Set-Content -Path (Join-Path $localStageDir "Dockerfile") -NoNewline +'@ - Invoke-NativeCommand -Name "2) Preparing remote release directory..." -Action { - ssh $remoteHost "mkdir -p '$remoteReleasesDir' '$remoteDataDir' && test ! -e '$remoteReleaseDir' && mkdir -p '$remoteReleaseDir'" - } - - Invoke-NativeCommand -Name "3) Uploading release payload..." -Action { - Push-Location $localStageDir - try { - scp -r "Dockerfile" "publish" "${remoteHost}:$remoteReleaseDir/" - } - finally { - Pop-Location - } - } + ConvertTo-LinuxLineEnding -Value $dockerfile | + Set-Content -Path (Join-Path $localStageDir "Dockerfile") -NoNewline $remoteScript = Get-RemoteScript ` -RemoteReleaseDir $remoteReleaseDir ` @@ -154,8 +153,25 @@ ENTRYPOINT ["dotnet", "RpgRoller.dll"] -ContainerPort $containerPort ` -HostPort $hostPort + ConvertTo-LinuxLineEnding -Value $remoteScript | + Set-Content -Path (Join-Path $localStageDir "deploy-remote.sh") -NoNewline + + Invoke-NativeCommand -Name "2) Preparing remote release directory..." -Action { + ssh $remoteHost "mkdir -p '$remoteReleasesDir' '$remoteDataDir' && test ! -e '$remoteReleaseDir' && mkdir -p '$remoteReleaseDir'" + } + + Invoke-NativeCommand -Name "3) Uploading release payload..." -Action { + Push-Location $localStageDir + try { + scp -r "Dockerfile" "deploy-remote.sh" "publish" "${remoteHost}:$remoteReleaseDir/" + } + finally { + Pop-Location + } + } + Invoke-NativeCommand -Name "4) Building image and restarting container on remote host..." -Action { - $remoteScript | ssh $remoteHost "bash -se" + ssh $remoteHost "bash '$remoteReleaseDir/deploy-remote.sh'" } Write-Host "5) Deployment complete."