From 8b8c6dc00e647adee6eb8898980ff46a40934b59 Mon Sep 17 00:00:00 2001 From: Harrison Affel Date: Tue, 1 Oct 2024 16:57:50 -0400 Subject: [PATCH] improve run.ps1, update windows build scripts, update CI --- .github/workflows/ci-on-pull-requset.yaml | 6 +- .github/workflows/release.yaml | 6 +- Dockerfile-windows.dapper | 46 ---- make.ps1 | 41 ++-- package/Dockerfile.windows | 4 +- package/run.ps1 | 260 ++++++++++++++++++---- scripts/windows/build.ps1 | 6 +- scripts/windows/download.ps1 | 6 +- scripts/windows/manifest.ps1 | 2 +- scripts/windows/package.ps1 | 8 +- scripts/windows/publish.ps1 | 4 +- scripts/windows/version.ps1 | 13 +- 12 files changed, 267 insertions(+), 135 deletions(-) delete mode 100644 Dockerfile-windows.dapper diff --git a/.github/workflows/ci-on-pull-requset.yaml b/.github/workflows/ci-on-pull-requset.yaml index c91778c..e06ab48 100644 --- a/.github/workflows/ci-on-pull-requset.yaml +++ b/.github/workflows/ci-on-pull-requset.yaml @@ -55,10 +55,10 @@ jobs: strategy: matrix: include: - - SERVERCORE_VERSION: 1809 + - NANOSERVER_VERSION: 1809 TAG_SUFFIX: windows-1809-amd64 RUNNER: windows-2019 - - SERVERCORE_VERSION: ltsc2022 + - NANOSERVER_VERSION: ltsc2022 TAG_SUFFIX: windows-ltsc2022-amd64 RUNNER: windows-2022 runs-on: ${{ matrix.RUNNER }} @@ -83,7 +83,7 @@ jobs: run: | docker image build ` -f package/Dockerfile.windows ` - --build-arg SERVERCORE_VERSION=${{ matrix.SERVERCORE_VERSION }} ` + --build-arg NANOSERVER_VERSION=${{ matrix.NANOSERVER_VERSION }} ` -t ${{ env.IMAGE }}:${{ env.VERSION }}-${{ matrix.TAG_SUFFIX }} . - name: Inspect image diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 5c6899e..07d85fd 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -68,10 +68,10 @@ jobs: strategy: matrix: include: - - SERVERCORE_VERSION: 1809 + - NANOSERVER_VERSION: 1809 TAG_SUFFIX: windows-1809-amd64 RUNNER: windows-2019 - - SERVERCORE_VERSION: ltsc2022 + - NANOSERVER_VERSION: ltsc2022 TAG_SUFFIX: windows-ltsc2022-amd64 RUNNER: windows-2022 runs-on: ${{ matrix.RUNNER }} @@ -110,7 +110,7 @@ jobs: run: | docker image build ` -f package/Dockerfile.windows ` - --build-arg SERVERCORE_VERSION=${{ matrix.SERVERCORE_VERSION }} ` + --build-arg NANOSERVER_VERSION=${{ matrix.NANOSERVER_VERSION }} ` -t ${{ env.IMAGE }}:${{ env.VERSION }}-${{ matrix.TAG_SUFFIX }} . docker push ${{ env.IMAGE }}:${{ env.VERSION }}-${{ matrix.TAG_SUFFIX }} diff --git a/Dockerfile-windows.dapper b/Dockerfile-windows.dapper deleted file mode 100644 index 131b7cd..0000000 --- a/Dockerfile-windows.dapper +++ /dev/null @@ -1,46 +0,0 @@ -ARG SERVERCORE_VERSION - -FROM mcr.microsoft.com/windows/servercore:${SERVERCORE_VERSION} as download - -SHELL ["powershell", "-NoLogo", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"] - -ENV ARCH amd64 - -# Create a symbolic link pwsh.exe that points to powershell.exe for consistency -RUN New-Item -ItemType SymbolicLink -Target "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -Path "C:\Windows\System32\WindowsPowerShell\v1.0\pwsh.exe" - - -RUN pushd c:\; \ - $URL = 'https://github.com/StefanScherer/docker-cli-builder/releases/download/20.10.5/docker.exe'; \ - \ - Write-Host ('Downloading docker from {0} ...' -f $URL); \ - curl.exe -sfL $URL -o c:\Windows\docker.exe; \ - \ - Write-Host 'Complete.'; \ - popd; - -# upgrade git -RUN pushd c:\; \ - $URL = 'https://github.com/git-for-windows/git/releases/download/v2.33.0.windows.2/MinGit-2.33.0.2-64-bit.zip'; \ - \ - Write-Host ('Downloading git from {0} ...' -f $URL); \ - curl.exe -sfL $URL -o c:\git.zip; \ - \ - Write-Host 'Expanding ...'; \ - Expand-Archive -Force -Path c:\git.zip -DestinationPath c:\git\.; \ - \ - Write-Host 'Cleaning ...'; \ - Remove-Item -Force -Recurse -Path c:\git.zip; \ - \ - Write-Host 'Complete.'; \ - popd; - -ENV DAPPER_ENV REPO OS ARCH TAG DRONE_TAG LOCAL_ARTIFACTS DOCKER_USERNAME DOCKER_PASSWORD -ENV DAPPER_SOURCE /go/src/github.com/rancher/system-agent-installer-rke2/ -ENV DAPPER_DOCKER_SOCKET true -ENV HOME ${DAPPER_SOURCE} - -WORKDIR ${DAPPER_SOURCE} - -ENTRYPOINT ["powershell", "-NoLogo", "-NonInteractive", "-File", "./scripts/windows/entry.ps1"] -CMD ["build"] \ No newline at end of file diff --git a/make.ps1 b/make.ps1 index c57269c..9852c36 100644 --- a/make.ps1 +++ b/make.ps1 @@ -1,7 +1,25 @@ -if (!(Test-Path .dapper.exe)) { - $dapperURL = "https://releases.rancher.com/dapper/latest/dapper-Windows-x86_64.exe" - Write-Host "no .dapper.exe, downloading $dapperURL" - curl.exe -sfL -o .dapper.exe $dapperURL +# Github action CI does not utilize these scripts, however they're still useful for local development. + +Write-Host " +To build locally the following environment varables must be set + `$env:TAG - The rke2 tag that should be packaged within the installer image. This should match a released version of rke2 (i.e. v1.30.2+rke2r1) + `$env:NANOSERVER_VERSION (can be either ltsc2019 or 1809 for Windows server 2019 or ltsc2022 for Windows server 2022) + `$env:REPO - The dockerhub repo the image will be pushed to (this probably shouldn't be 'rancher') +" + +if ((-not $env:TAG) -or ($env:TAG -eq "")) { + Write-Host "`$env:TAG must be set to a valid RKE2 release (such as 'v1.30.2+rke2r1')" + exit 1 +} + +if ((-not $env:NANOSERVER_VERSION) -or ($env:NANOSERVER_VERSION -eq "")) { + Write-Host "`$env:NANOSERVER_VERSION must be set to a valid server core base image version (Either 1809, ltsc2019, or ltsc2022)" + exit 1 +} + +if ((-not $env:REPO) -or ($env:REPO -eq "")) { + Write-Host "`$env:REPO must be set to a valid dockerhub repository. This likely shouldn't be 'rancher'" + exit 1 } if ($args.Count -eq 0) { @@ -10,24 +28,19 @@ if ($args.Count -eq 0) { if ($args[0] -eq "build") { Write-Host "Running build" - .dapper.exe -f Dockerfile-windows.dapper build scripts\windows\build.ps1 exit } if ($args[0] -eq "publish") { Write-Host "Running publish" - .dapper.exe -f Dockerfile-windows.dapper publish scripts\windows\publish.ps1 exit } -if ($args[0] -eq "clean") { - Remove-Item .dapper.exe - Remove-Item Dockerfile-windows.dapper* -Exclude "Dockerfile-windows.dapper" -} - -if (Test-Path scripts\$($args[0]).ps1) { - .dapper.exe -f Dockerfile-windows.dapper $($args[0]) - exit +$script = $args[0] +if (Test-Path scripts\$($script).ps1) { + scripts\$($args[0]).ps1 +} else { + Write-Host "Could not find script $script.ps1" } \ No newline at end of file diff --git a/package/Dockerfile.windows b/package/Dockerfile.windows index 501dff8..ae641a9 100644 --- a/package/Dockerfile.windows +++ b/package/Dockerfile.windows @@ -1,6 +1,6 @@ -ARG SERVERCORE_VERSION +ARG NANOSERVER_VERSION -FROM mcr.microsoft.com/windows/nanoserver:${SERVERCORE_VERSION} +FROM mcr.microsoft.com/windows/nanoserver:${NANOSERVER_VERSION} COPY package/run.ps1 /bin/run.ps1 COPY artifacts/* /bin/ \ No newline at end of file diff --git a/package/run.ps1 b/package/run.ps1 index d3b4b94..eadd10e 100644 --- a/package/run.ps1 +++ b/package/run.ps1 @@ -1,21 +1,60 @@ +<# +.SYNOPSIS + Installs, upgrades, and configures rke2 on a windows node + +.NOTES + Optional Environment Variables: + - $env:WINS_RESTART_STAMP + - A hash generated by Rancher representing the current configuration of the node plan and control plane + - $env:RKE2_DATA_DIR + - The directory where rke2 should be installed. This must be a valid Windows path. Defaults to c:/var/lib/rancher/rke2 + - $env:INSTALL_RKE2_VERSION + - The version of rke2 that the cluster is running on. This is a string value in the format of vX.Y.Z+rke2rW + - If this is not provided, the install script will always stop and reinstall rke2 + +#> + $ErrorActionPreference = 'Stop' Set-StrictMode -Version Latest +function Get-StringHash { + [CmdletBinding()] + param ( + [Parameter()] + [string] + $Value + ) + $stringAsStream = [System.IO.MemoryStream]::new() + $writer = [System.IO.StreamWriter]::new($stringAsStream) + $writer.write($Value) + $writer.Flush() + $stringAsStream.Position = 0 + return (Get-FileHash -InputStream $stringAsStream -Algorithm SHA256).Hash.ToLower() +} + function Write-LogInfo { - Write-Host -NoNewline -ForegroundColor Blue "INFO: " + $ts = (Get-Date).ToString("hh:mm:ss.fff") + Write-Host -NoNewline -ForegroundColor Blue "[INFO $ts] " Write-Host -ForegroundColor Gray ("{0,-44}" -f ($args -join " ")) } + function Write-LogWarn { - Write-Host -NoNewline -ForegroundColor DarkYellow "WARN: " + $ts = (Get-Date).ToString("hh:mm:ss.fff") + Write-Host -NoNewline -ForegroundColor DarkYellow "[WARN $ts] " Write-Host -ForegroundColor Gray ("{0,-44}" -f ($args -join " ")) } + function Write-LogError { - Write-Host -NoNewline -ForegroundColor DarkRed "ERROR: " + $ts = (Get-Date).ToString("hh:mm:ss.fff") + Write-Host -NoNewline -ForegroundColor DarkRed "[ERRO $ts] " Write-Host -ForegroundColor Gray ("{0,-44}" -f ($args -join " ")) } + function Write-LogFatal { - Write-Host -NoNewline -ForegroundColor DarkRed "FATA: " + $ts = (Get-Date).ToString("hh:mm:ss.fff") + Write-Host -NoNewline -ForegroundColor DarkRed "[FATA $ts] " Write-Host -ForegroundColor Gray ("{0,-44}" -f ($args -join " ")) + exit 255 } @@ -31,28 +70,111 @@ function New-Directory { } } -function Get-StringHash { +function Get-CurrentEnvHash { [CmdletBinding()] param ( [Parameter()] [string] - $Value + $rke2ServiceName ) - $stringAsStream = [System.IO.MemoryStream]::new() - $writer = [System.IO.StreamWriter]::new($stringAsStream) - $writer.write($Value) - $writer.Flush() - $stringAsStream.Position = 0 - return (Get-FileHash -InputStream $stringAsStream -Algorithm SHA256).Hash.ToLower() + try + { + $currentEnv = Get-ItemProperty HKLM:SYSTEM\CurrentControlSet\Services\$rke2ServiceName -ErrorAction SilentlyContinue + if ($null -eq $currentEnv) + { + # either no environment variables have been set, or rke2 hasn't been installed + return "" + } + $envString = ($currentEnv).Environment | Out-String + return Get-StringHash -Value ($envString) + } catch { + return "" + } +} + +function Determine-Upgrading { + $CURRENT_RKE2_VERSION = "" + try + { + $RKE2_VERSION_OUTPUT = $(c:\usr\local\bin\rke2.exe --version) + if ($RKE2_VERSION_OUTPUT -eq "") { + Write-LogInfo "Could not determine current $rke2 version as 'rke2 --version' did not return the expected content" + return $true + } + + $CURRENT_RKE2_VERSION = $($RKE2_VERSION_OUTPUT.Split(" ") -Like "v1.*") + Write-LogInfo "Detected $rke2ServiceName version $CURRENT_RKE2_VERSION" + } catch { + Write-LogInfo "Could not determine current $rke2ServiceName version" + return $true + } + + # INSTALL_RKE2_VERSION denotes the version of rke2 that we are + # upgrading towards. This comes from the v1 cluster object, + # and is not provided when deploying clusters from rancher versions < v2.10. + $INCOMING_RKE2_VERSION = $env:INSTALL_RKE2_VERSION + if ((-not $INCOMING_RKE2_VERSION) -or ($INCOMING_RKE2_VERSION -eq "")) { + Write-LogWarn "`$env:INSTALL_RKE2_VERSION was empty, cannot determine if we are upgrading" + return $true + } else { + Write-LogInfo "Given plan specifies $rke2ServiceName version $INCOMING_RKE2_VERSION" + } + + # If we can't find the current version, we assume it's not installed. If the incoming and existing versions do not match, + # we must be upgrading so we need to stop rke2 and re-run the install script. When executed by older versions of Rancher which do not provide + # CATTLE_INCOMING_RKE2_VERSION, the service will always be stopped and reinstalled, which is the long standing behavior. + if ((-not $CURRENT_RKE2_VERSION) -or ($CURRENT_RKE2_VERSION -ne $INCOMING_RKE2_VERSION)) { + Write-LogInfo "'$INCOMING_RKE2_VERSION' does not match '$CURRENT_RKE2_VERSION'. Will upgrade $rke2ServiceName version" + return $true + } + return $false +} + +function Stop-RKE2 { + Stop-Service -Name $rke2ServiceName + while ((Get-Service $rke2ServiceName).Status -ne 'Stopped') + { + Write-LogInfo "Waiting for $rke2ServiceName agent service to stop" + Start-Sleep -s 5 + } + Write-LogInfo "$rke2ServiceName agent service has stopped" + + # Ensure the binary has exited + while (Get-Process -Name rke2 -ErrorAction SilentlyContinue) { + Write-LogInfo "Waiting for $rke2ServiceName agent process to stop" + Start-Sleep -s 5 + } + Write-LogInfo "$rke2ServiceName agent process has exited" +} + +function Configure-DelayedServiceStartType { + [CmdletBinding()] + param ( + [Parameter()] + [string] + $ServiceName + ) + + $startType = (sc.exe qc $ServiceName | Select-String "START_TYPE" | ForEach-Object { ($_ -replace '\s+', ' ').trim().Split(" ") | Select-Object -Last 1 }) + if (-Not $startType) { + Write-LogError "could not determine current $ServiceName service start type, will not attempt to reconfigure start type" + return + } + + if ($startType -and ($startType -ne "(DELAYED)")) { + Write-LogInfo "Changing $ServiceName service start type to 'Automatic (Delayed)'" + sc.exe config $serviceName start= delayed-auto + } else { + Write-LogInfo "$ServiceName is already configured with a start type of 'Automatic (Delayed)'" + } } $rke2ServiceName = "rke2" -$SA_INSTALL_PREFIX = "c:/usr/local" +$SA_INSTALL_PREFIX = if($env:SA_INSTALL_PREFIX) { $env:SA_INSTALL_PREFIX } else { "c:/usr/local" } $RKE2_DATA_DIR = if ($env:RKE2_DATA_DIR) { $env:RKE2_DATA_DIR } else { "c:/var/lib/rancher/rke2" }; $SAI_FILE_DIR = "$RKE2_DATA_DIR/system-agent-installer" $RESTART_STAMP_FILE = "$SAI_FILE_DIR/rke2_restart_stamp" $PRIOR_RESTART_STAMP = "" -$RESTART = $false New-Directory -Path "$RKE2_DATA_DIR" New-Directory -Path "$SAI_FILE_DIR" @@ -61,13 +183,28 @@ if (Test-Path $RESTART_STAMP_FILE) { $PRIOR_RESTART_STAMP = Get-Content -Path $RESTART_STAMP_FILE } -if ($env:RESTART_STAMP -and ($PRIOR_RESTART_STAMP -ne $env:RESTART_STAMP)) { - $RESTART = true +# RESTART denotes whether we should restart the rke2 +# service. This needs to be done during an upgrade, or if +# environment variables change. +$RESTART = $false +$MISMATCHED_RESTART_STAMPS = $false +if ($env:WINS_RESTART_STAMP) +{ + if ($PRIOR_RESTART_STAMP -ne $env:WINS_RESTART_STAMP) { + Write-LogInfo "Detected new Restart Stamp (old stamp: [$PRIOR_RESTART_STAMP], new stamp: [$env:WINS_RESTART_STAMP])" + $RESTART = $true + $MISMATCHED_RESTART_STAMPS = $true + } else { + Write-LogInfo "Restart stamps match ($env:WINS_RESTART_STAMP)" + } +} else { + Write-LogWarn("`$env:WINS_RESTART_STAMP was not provided, cannot update restart stamp file") } -$currentEnv = Get-ItemProperty HKLM:SYSTEM\CurrentControlSet\Services\$rke2ServiceName -Name Environment -ErrorAction SilentlyContinue -$currentHash = Get-StringHash -Value $($currentEnv | Out-String) +# Check if any environment variables have changed. We need to restart the service if they have +$currentEnvHash = Get-CurrentEnvHash -rke2ServiceName $rke2ServiceName +# Build a string array of environment variables to be set in the registry for the rke2 service $newEnv = @() $RKE2_ENV = Get-ChildItem env: | Where-Object { $_.Name -Like "RKE2_*" } | ForEach-Object { "$($_.Name)=$($_.Value)" } if ($RKE2_ENV) { @@ -79,59 +216,96 @@ if ($PROXY_ENV_INFO) { $newEnv += $PROXY_ENV_INFO } -$newHash = Get-StringHash -Value $($newEnv | Out-String) -if ($newEnv -and ($newHash -ne $currentHash)) { - if(Test-Path -Path HKLM:SYSTEM\CurrentControlSet\Services\$rke2ServiceName) { - Set-ItemProperty HKLM:SYSTEM\CurrentControlSet\Services\$rke2ServiceName -Name Environment -Value $newEnv +$newEnvHash = Get-StringHash -Value $($newEnv | Out-String) +if ($newEnv -and ($newEnvHash -ne $currentEnvHash)) { + if (Test-Path -Path HKLM:SYSTEM\CurrentControlSet\Services\$rke2ServiceName) { + # In the event that no environment variables were specified during the initial rke2 installation, the 'Environment' property + # will not yet exist in the registry. + if (-Not (Get-ItemProperty HKLM:SYSTEM\CurrentControlSet\Services\$rke2ServiceName -Name Environment -ErrorAction Ignore)){ + Write-Host "$rke2ServiceName Environment registry property not found, adding now" + New-ItemProperty HKLM:SYSTEM\CurrentControlSet\Services\$rke2ServiceName -Name Environment -PropertyType MultiString -Value $newEnv + } else { + Write-Host "updating existing $rke2ServiceName Environment registry property" + Set-ItemProperty HKLM:SYSTEM\CurrentControlSet\Services\$rke2ServiceName -Name Environment -Value $newEnv + } } else { New-Item HKLM:SYSTEM\CurrentControlSet\Services\$rke2ServiceName New-ItemProperty HKLM:SYSTEM\CurrentControlSet\Services\$rke2ServiceName -Name Environment -PropertyType MultiString -Value $newEnv } $RESTART = $true + Write-LogInfo "Detected updated environment variable hash. Previous hash: $currentEnvHash, new hash: $newEnvHash. Will restart the $rke2ServiceName service as needed" } -Write-LogInfo "Checking if RKE2 agent service exists" -if ((Get-Service -Name $rke2ServiceName -ErrorAction SilentlyContinue)) { - Write-LogInfo "RKE2 agent service found, stopping now" - Stop-Service -Name $rke2ServiceName - while ((Get-Service $rke2ServiceName).Status -ne 'Stopped') { - Write-LogInfo "Waiting for RKE2 agent service to stop" - Start-Sleep -s 5 +# If the user has removed all environnment variables from the cluster configuration, +# we need to ensure we do not leave the old ones in the registry +if ((-Not $newEnv) -or ($null -eq $newEnv)) { + Write-LogInfo "No $rke2ServiceName environment variables have been provided" + if(Get-ItemProperty HKLM:SYSTEM\CurrentControlSet\Services\$rke2ServiceName -Name Environment -ErrorAction Ignore) + { + Write-LogInfo "Clearing existing $rke2ServiceName environment variables" + Remove-ItemProperty HKLM:SYSTEM\CurrentControlSet\Services\$rke2ServiceName -Name Environment + $RESTART = $true + } else { + Write-LogInfo "No $rke2ServiceName environment variables have been set in the registry" } } -# if service doesn't exist, then install, otherwise check the binary and determine if it needs to be reinstalled, otherwise fall through to restart, skil enable, skip start -./installer.ps1 -TarPrefix $SA_INSTALL_PREFIX -ArtifactPath $env:CATTLE_AGENT_EXECUTION_PWD +$UPGRADING_VERSION=(Determine-Upgrading) +$SERVICE_EXISTS = ($null -ne (Get-Service -Name $rke2ServiceName -ErrorAction Ignore)) +Write-LogInfo "Restart: [$RESTART], Upgrading Version: [$UPGRADING_VERSION], Service Exists: [$SERVICE_EXISTS]" +if (($RESTART -or $UPGRADING_VERSION) -and ($SERVICE_EXISTS)) +{ + Write-LogInfo "$rke2ServiceName agent service found, stopping now" + Stop-RKE2 +} + +if (($UPGRADING_VERSION -eq $true) -or ($SERVICE_EXISTS -eq $false)) +{ + Write-LogInfo "Executing the $rke2ServiceName Install Script" + ./installer.ps1 -TarPrefix $SA_INSTALL_PREFIX -ArtifactPath $env:CATTLE_AGENT_EXECUTION_PWD +} else { + Write-LogInfo "Skipping $rke2ServiceName install script as the service already exists and we are not upgrading" +} -if ($env:RESTART_STAMP) { - Set-Content -Path $env:RESTART_STAMP_FILE -Value $env:RESTART_STAMP +if ($MISMATCHED_RESTART_STAMPS -eq $true) { + Write-LogInfo "Detected mismatched restart hashes. Updating the restart hash file with value [$env:WINS_RESTART_STAMP]" + Set-Content -Path $RESTART_STAMP_FILE -Value $env:WINS_RESTART_STAMP } if ($env:INSTALL_RKE2_SKIP_ENABLE -eq $true) { - Write-LogInfo "Skipping RKE2 Service installation" + Write-LogInfo "Skipping $rke2ServiceName Service installation" exit 0 } -else { + +if (-not $SERVICE_EXISTS) { # Create Windows Service Write-LogInfo "RKE2 agent service not found, enabling agent service" Push-Location c:\usr\local\bin rke2.exe agent service --add Pop-Location - Start-Sleep -s 5 } +# ensure rke2 service uses a delayed start type +Configure-DelayedServiceStartType -ServiceName $rke2ServiceName + if ($env:INSTALL_RKE2_SKIP_START -and ($env:INSTALL_RKE2_SKIP_START -eq $true)) { - Write-LogInfo "Skipping starting of the RKE2 Service" + Write-LogInfo "Skipping starting of the $rke2ServiceName Service" exit 0 } -if ((Get-Service -Name $rke2ServiceName -ErrorAction SilentlyContinue)) { - if ((Get-Service $rke2ServiceName).Status -eq 'Stopped') { - Write-LogInfo "Starting for RKE2 agent service" +if ((Get-Service $rke2ServiceName).Status -eq 'Stopped') { + Write-LogInfo "Starting the $rke2ServiceName agent service" + try + { Start-Service -Name $rke2ServiceName + } catch { + Write-LogError "Failed to start $rke2ServiceName" + Write-LogError "Run the following command to export the RKE2 service logs: Get-EventLog -LogName Application -Source rke2 | Select-Object timewritten,replacementstrings | Format-Table -Wrap | Out-File rke2-logs.txt" + throw } - elseif (($RESTART = $true) -and ((Get-Service $rke2ServiceName).Status -eq 'Running')) { - Restart-Service -Name $rke2ServiceName - } + Write-LogInfo "Successfully started the $rke2ServiceName service" +} elseif (($RESTART -eq $true) -and ((Get-Service $rke2ServiceName).Status -eq 'Running')) { + Write-LogInfo "Restarting $rke2ServiceName` (RESTART: [$RESTART], UPGRADING_VERSION [$UPGRADING_VERSION])" + Restart-Service -Name $rke2ServiceName } diff --git a/scripts/windows/build.ps1 b/scripts/windows/build.ps1 index e6a867a..4b1374d 100644 --- a/scripts/windows/build.ps1 +++ b/scripts/windows/build.ps1 @@ -1,6 +1,4 @@ $ErrorActionPreference = 'Stop' -Push-Location $PSScriptRoot - -./download.ps1 -./package.ps1 +./scripts/windows/download.ps1 +./scripts/windows/package.ps1 diff --git a/scripts/windows/download.ps1 b/scripts/windows/download.ps1 index 58b0e4b..00e0e67 100644 --- a/scripts/windows/download.ps1 +++ b/scripts/windows/download.ps1 @@ -1,10 +1,6 @@ $ErrorActionPreference = 'Stop' -.$PSScriptRoot/version.ps1 - -Set-Location $PSScriptRoot/../.. - -# This script serves to download/stage the installer +./scripts/windows/version.ps1 mkdir -p artifacts -f diff --git a/scripts/windows/manifest.ps1 b/scripts/windows/manifest.ps1 index 57bcd5c..6741d5c 100644 --- a/scripts/windows/manifest.ps1 +++ b/scripts/windows/manifest.ps1 @@ -6,7 +6,7 @@ Set-Location $PSScriptRoot/.. docker login -u $env:DOCKER_USERNAME -p $env:DOCKER_PASSWORD -DOCKER_CLI_EXPERIMENTAL=enabled docker manifest create --amend $env:IMAGE $env:IMAGE-$env:OS-$env:ARCH +DOCKER_CLI_EXPERIMENTAL=enabled docker manifest create --amend $env:IMAGE $env:IMAGE-windows-$env:ARCH DOCKER_CLI_EXPERIMENTAL=enabled docker manifest push $env:IMAGE Write-Host "Pushed manifest list for $env:IMAGE" diff --git a/scripts/windows/package.ps1 b/scripts/windows/package.ps1 index bd3d7ee..261cc21 100644 --- a/scripts/windows/package.ps1 +++ b/scripts/windows/package.ps1 @@ -2,10 +2,8 @@ $ErrorActionPreference = 'Stop' .$PSScriptRoot/version.ps1 -Set-Location $PSScriptRoot/.. +$DOCKERFILE = "package/Dockerfile.windows" -$DOCKERFILE = package/Dockerfile.windows +docker image build --build-arg NANOSERVER_VERSION=$env:NANOSERVER_VERSION -f $DOCKERFILE -t $env:IMAGE-windows-$env:ARCH . -docker image build -f $DOCKERFILE -t $env:IMAGE-$env:OS-$env:ARCH . - -Write-Host "Built $env:IMAGE-$env:OS-$env:ARCH" +Write-Host "Built $env:IMAGE-windows-$env:ARCH" diff --git a/scripts/windows/publish.ps1 b/scripts/windows/publish.ps1 index c68ffdb..64a5191 100644 --- a/scripts/windows/publish.ps1 +++ b/scripts/windows/publish.ps1 @@ -6,6 +6,6 @@ Set-Location $PSScriptRoot/.. docker login -u $env:DOCKER_USERNAME -p $env:DOCKER_PASSWORD -docker push $env:IMAGE-$env:OS-$env:ARCH +docker push $env:IMAGE-windows-$env:ARCH -Write-Host "Pushed $env:IMAGE-$env:OS-$env:ARCH" +Write-Host "Pushed $env:IMAGE-windows-$env:ARCH" diff --git a/scripts/windows/version.ps1 b/scripts/windows/version.ps1 index ab5f447..1ce202f 100644 --- a/scripts/windows/version.ps1 +++ b/scripts/windows/version.ps1 @@ -3,14 +3,13 @@ $ErrorActionPreference = 'Stop' if (-not $env:ARCH) { $env:ARCH = "amd64" } -$env:OS = "windows" -$FALLBACK_VERSION = "v1.20.4+rke2r1" +$FALLBACK_VERSION = "v1.30.2+rke2r1" # This version script expects either a tag of format: or no tag at all. $TREE_STATE = "clean" -$COMMIT = $env:DRONE_COMMIT -$TAG = $env:DRONE_TAG +$COMMIT = $env:GITHUB_SHA +$TAG = $env:TAG if (-not $COMMIT -and $env:GITHUB_SHA) { $COMMIT = $env:GITHUB_SHA @@ -82,14 +81,14 @@ else { $VERSION = $TAG } -$env:URI_VERSION = [uri]::EscapeDataString($VERSION) +$env:URI_VERSION = $VERSION +# Docker tags cannot include '+' $VERSION = $VERSION.Replace('+', '-') #export stuff out $env:VERSION = $VERSION $env:COMMIT = $COMMIT -$env:REPO = "rancher" -$env:IMAGE = "$REPO/system-agent-installer-rke2:$VERSION" +$env:IMAGE = "$env:REPO/system-agent-installer-rke2:$VERSION" if ( $env:GITHUB_ENV ) { "VERSION=$env:VERSION" | Out-File -FilePath $env:GITHUB_ENV -Append