From d2de05bd9ae9d70cd91eb3d19726f32536fd4081 Mon Sep 17 00:00:00 2001 From: Ryan Richter Date: Wed, 17 Jul 2024 08:02:47 -0400 Subject: [PATCH] (#230) Add ChocolateyCore Repo source Add ChocolateyCore repo as main repo for core packages Also add change to name main packages folder Change license package creation script to point to packages folder for output Signed-off-by: Ryan Richter --- OfflineInstallPreparation.ps1 | 22 ++++++++--------- Set-SslSecurity.ps1 | 38 ++++++++++++++++++++++++----- Start-C4bCcmSetup.ps1 | 2 +- Start-C4bJenkinsSetup.ps1 | 6 ++--- Start-C4bNexusSetup.ps1 | 10 +++++--- Start-C4bSetup.ps1 | 10 ++++---- {files => packages}/chocolatey.json | 0 {files => packages}/jenkins.json | 0 scripts/ClientSetup.ps1 | 21 ++++++++++------ scripts/Create-ChocoLicensePkg.ps1 | 2 +- tests/jenkins.test.ps1 | 2 +- tests/nexus.tests.ps1 | 7 +++++- 12 files changed, 81 insertions(+), 39 deletions(-) rename {files => packages}/chocolatey.json (100%) rename {files => packages}/jenkins.json (100%) diff --git a/OfflineInstallPreparation.ps1 b/OfflineInstallPreparation.ps1 index 10e71ff..a1c7d4e 100644 --- a/OfflineInstallPreparation.ps1 +++ b/OfflineInstallPreparation.ps1 @@ -90,8 +90,8 @@ if (-not $Licensed) { } Copy-Item $LicensePath $InstalledLicensePath -Force } - $ExtensionSource = if (Test-Path $PSScriptRoot\files\chocolatey.extension.*.nupkg) { - Convert-Path $PSScriptRoot\files\ + $ExtensionSource = if (Test-Path $PSScriptRoot\packages\chocolatey.extension.*.nupkg) { + Convert-Path $PSScriptRoot\packages\ } else { 'https://licensedpackages.chocolatey.org/api/v2/' } @@ -103,7 +103,7 @@ $PackageWorkingDirectory = Join-Path $WorkingDirectory "Packages" if (-not (Test-Path $PackageWorkingDirectory)) { $null = New-Item -Path $PackageWorkingDirectory -ItemType Directory -Force } -foreach ($Package in (Get-Content $PSScriptRoot\files\chocolatey.json | ConvertFrom-Json).packages) { +foreach ($Package in (Get-Content $PSScriptRoot\packages\chocolatey.json | ConvertFrom-Json).packages) { $ChocoArgs = @( "download", "$($Package.Name)" "--output-directory", $PackageWorkingDirectory @@ -118,7 +118,7 @@ foreach ($Package in (Get-Content $PSScriptRoot\files\chocolatey.json | ConvertF } try { - if (-not (Get-ChocolateyPackageMetadata -Path $PackageWorkingDirectory -Id $Package.Name) -and -not (Get-ChocolateyPackageMetadata -Path "$PSScriptRoot\files\" -Id $Package.Name)) { + if (-not (Get-ChocolateyPackageMetadata -Path $PackageWorkingDirectory -Id $Package.Name) -and -not (Get-ChocolateyPackageMetadata -Path "$PSScriptRoot\packages\" -Id $Package.Name)) { Write-Host "Downloading '$($Package.Name)'" while ((Get-ChildItem $PackageWorkingDirectory -Filter *.nupkg).Where{$_.CreationTime -gt (Get-Date).AddMinutes(-1)}.Count -gt 5) { @@ -132,18 +132,18 @@ foreach ($Package in (Get-Content $PSScriptRoot\files\chocolatey.json | ConvertF throw $_ } } -Move-Item -Path $PackageWorkingDirectory\*.nupkg -Destination $PSScriptRoot\files\ +Move-Item -Path $PackageWorkingDirectory\*.nupkg -Destination $PSScriptRoot\packages\ # Jenkins Plugins $PluginsWorkingDirectory = Join-Path $WorkingDirectory "JenkinsPlugins" if (-not (Test-Path $PluginsWorkingDirectory)) { $null = New-Item -Path $PluginsWorkingDirectory -ItemType Directory -Force } -if (Test-Path $PSScriptRoot\files\JenkinsPlugins.zip) { - Expand-Archive -Path $PSScriptRoot\files\JenkinsPlugins.zip -DestinationPath $PluginsWorkingDirectory -Force +if (Test-Path $PSScriptRoot\packages\JenkinsPlugins.zip) { + Expand-Archive -Path $PSScriptRoot\packages\JenkinsPlugins.zip -DestinationPath $PluginsWorkingDirectory -Force } $ProgressPreference = "Ignore" -foreach ($Plugin in (Get-Content $PSScriptRoot\files\jenkins.json | ConvertFrom-Json).plugins) { +foreach ($Plugin in (Get-Content $PSScriptRoot\packages\jenkins.json | ConvertFrom-Json).plugins) { $RestArgs = @{ Uri = "https://updates.jenkins-ci.org/latest/$($Plugin.Name).hpi" OutFile = Join-Path $PluginsWorkingDirectory "$($Plugin.Name).hpi" @@ -155,12 +155,12 @@ foreach ($Plugin in (Get-Content $PSScriptRoot\files\jenkins.json | ConvertFrom- Invoke-WebRequest @RestArgs -UseBasicParsing } } -Compress-Archive -Path $PluginsWorkingDirectory\* -Destination $PSScriptRoot\files\JenkinsPlugins.zip -Force +Compress-Archive -Path $PluginsWorkingDirectory\* -Destination $PSScriptRoot\packages\JenkinsPlugins.zip -Force # BCryptDll $null = Get-BcryptDll # License -if ($LicensePath -ne "$PSScriptRoot\files\chocolatey.license.xml") { - Copy-Item -Path (Convert-Path $LicensePath) -Destination $PSScriptRoot\files\chocolatey.license.xml +if ($LicensePath -ne "$PSScriptRoot\packages\chocolatey.license.xml") { + Copy-Item -Path (Convert-Path $LicensePath) -Destination $PSScriptRoot\packages\chocolatey.license.xml } \ No newline at end of file diff --git a/Set-SslSecurity.ps1 b/Set-SslSecurity.ps1 index 7a0afbc..12355c8 100644 --- a/Set-SslSecurity.ps1 +++ b/Set-SslSecurity.ps1 @@ -139,7 +139,10 @@ process { Write-Host "Nexus is ready!" choco source remove --name="'ChocolateyInternal'" - $RepositoryUrl = "https://${SubjectWithoutCn}:8443/repository/ChocolateyInternal/index.json" + $InternalRepositoryUrl = "https://${SubjectWithoutCn}:8443/repository/ChocolateyInternal/index.json" + + choco source remove --name="'ChocolateyCore'" + $CoreRepositoryUrl = "https://${SubjectWithoutCn}:8443/repository/ChocolateyCore/index.json" # Build Credential Object, Connect to Nexus $securePw = (Get-Content 'C:\programdata\sonatype-work\nexus3\admin.password') | ConvertTo-SecureString -AsPlainText -Force @@ -187,12 +190,23 @@ process { 'source', 'add', "--name='ChocolateyInternal'", - "--source='$RepositoryUrl'", + "--source='$InternalRepositoryUrl'", '--priority=1', "--user='chocouser'", "--password='$NexusPw'" ) & choco @ChocoArgs + + $ChocoArgs = @( + 'source', + 'add', + "--name='ChocolateyCore'", + "--source='$CoreRepositoryUrl'", + '--priority=0', + "--user='chocouser'", + "--password='$NexusPw'" + ) + & choco @ChocoArgs } @@ -201,14 +215,26 @@ process { 'source', 'add', "--name='ChocolateyInternal'", - "--source='$RepositoryUrl'", + "--source='$InternalRepositoryUrl'", '--priority=1' ) & choco @ChocoArgs + + $ChocoArgs = @( + 'source', + 'add', + "--name='ChocolateyCore'", + "--source='$CoreRepositoryUrl'", + '--priority=0' + ) + & choco @ChocoArgs } # Update Repository API key - $chocoArgs = @('apikey', "--source='$RepositoryUrl'", "--api-key='$NuGetApiKey'") + $chocoArgs = @('apikey', "--source='$InternalRepositoryUrl'", "--api-key='$NuGetApiKey'") + & choco @chocoArgs + + $chocoArgs = @('apikey', "--source='$CoreRepositoryUrl'", "--api-key='$NuGetApiKey'") & choco @chocoArgs # Reset the NuGet v3 cache, such that it doesn't capture localhost as the FQDN @@ -216,7 +242,7 @@ process { Update-JsonFile -Path "$env:SystemDrive\choco-setup\logs\nexus.json" -Properties @{ NexusUri = "https://$($SubjectWithoutCn):8443" - NexusRepo = $RepositoryUrl + NexusRepo = $CoreRepositoryUrl ChocoUserPassword = $NexusPw } @@ -271,7 +297,7 @@ process { # Touch NOTHING below this line `$User = 'chocouser' `$SecurePassword = `$NexusUserPW | ConvertTo-SecureString -AsPlainText -Force -`$RepositoryUrl = "https://`$(`$fqdn):8443/repository/ChocolateyInternal/index.json" +`$RepositoryUrl = "https://`$(`$fqdn):8443/repository/ChocolateyCore/index.json" `$credential = [pscredential]::new(`$user, `$securePassword) diff --git a/Start-C4bCcmSetup.ps1 b/Start-C4bCcmSetup.ps1 index 0d448a9..4ff7cbb 100644 --- a/Start-C4bCcmSetup.ps1 +++ b/Start-C4bCcmSetup.ps1 @@ -39,7 +39,7 @@ process { # Dot-source helper functions . .\scripts\Get-Helpers.ps1 - $Packages = (Get-Content $PSScriptRoot\files\chocolatey.json | ConvertFrom-Json).packages + $Packages = (Get-Content $PSScriptRoot\packages\chocolatey.json | ConvertFrom-Json).packages # DB Setup Write-Host "Installing SQL Server Express" diff --git a/Start-C4bJenkinsSetup.ps1 b/Start-C4bJenkinsSetup.ps1 index b225ce6..be25d6e 100644 --- a/Start-C4bJenkinsSetup.ps1 +++ b/Start-C4bJenkinsSetup.ps1 @@ -77,10 +77,10 @@ process { Stop-Service -Name Jenkins #region Jenkins Plugin Install & Update - $JenkinsPlugins = (Get-Content $PSScriptRoot\files\jenkins.json | ConvertFrom-Json).plugins + $JenkinsPlugins = (Get-Content $PSScriptRoot\packages\jenkins.json | ConvertFrom-Json).plugins - if (Test-Path $PSScriptRoot\files\JenkinsPlugins.zip) { - Expand-Archive -Path $PSScriptRoot\files\JenkinsPlugins.zip -DestinationPath $jenkinsHome\plugins\ -Force + if (Test-Path $PSScriptRoot\packages\JenkinsPlugins.zip) { + Expand-Archive -Path $PSScriptRoot\packages\JenkinsPlugins.zip -DestinationPath $jenkinsHome\plugins\ -Force } # Performance is killed by Invoke-WebRequest's progress bars, turning them off to speed this up diff --git a/Start-C4bNexusSetup.ps1 b/Start-C4bNexusSetup.ps1 index 3736f5e..e8bc63c 100644 --- a/Start-C4bNexusSetup.ps1 +++ b/Start-C4bNexusSetup.ps1 @@ -57,6 +57,7 @@ process { Enable-NexusRealm -Realm 'NuGet API-Key Realm' #Create Chocolatey repositories + New-NexusNugetHostedRepository -Name ChocolateyCore -DeploymentPolicy Allow New-NexusNugetHostedRepository -Name ChocolateyInternal -DeploymentPolicy Allow New-NexusNugetHostedRepository -Name ChocolateyTest -DeploymentPolicy Allow New-NexusRawHostedRepository -Name choco-install -DeploymentPolicy Allow -ContentDisposition Attachment @@ -65,12 +66,12 @@ process { $NuGetApiKey = (Get-NexusNuGetApiKey -Credential $Credential).apikey # Push all packages from previous steps to NuGet repo - Get-ChildItem -Path "$env:SystemDrive\choco-setup\files\files" -Filter *.nupkg | ForEach-Object { - choco push $_.FullName --source "$((Get-NexusRepository -Name 'ChocolateyInternal').url)/index.json" --apikey $NugetApiKey --force + Get-ChildItem -Path "$env:SystemDrive\choco-setup\files\packages" -Filter *.nupkg | ForEach-Object { + choco push $_.FullName --source "$((Get-NexusRepository -Name 'ChocolateyCore').url)/index.json" --apikey $NugetApiKey --force } # Temporary workaround to reset the NuGet v3 cache, such that it doesn't capture localhost as the FQDN - Remove-NexusRepositoryFolder -RepositoryName ChocolateyInternal -Name v3 + Remove-NexusRepositoryFolder -RepositoryName ChocolateyCore -Name v3 # Push latest ChocolateyInstall.ps1 to raw repo $ScriptDir = "$env:SystemDrive\choco-setup\files\scripts" @@ -91,6 +92,9 @@ process { # Add ChocolateyInternal as a source repository choco source add -n 'ChocolateyInternal' -s "$((Get-NexusRepository -Name 'ChocolateyInternal').url)/index.json" --priority 1 + # Add ChocolateyCore as a source repository + choco source add -n 'ChocolateyCore' -s "$((Get-NexusRepository -Name 'ChocolateyCore').url)/index.json" --priority 0 --admin-only + # Install a non-IE browser for browsing the Nexus web portal. if (-not (Test-Path 'C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe')) { Write-Host "Installing Microsoft Edge, to allow viewing the Nexus site" diff --git a/Start-C4bSetup.ps1 b/Start-C4bSetup.ps1 index 85c6121..24cfad0 100644 --- a/Start-C4bSetup.ps1 +++ b/Start-C4bSetup.ps1 @@ -21,9 +21,9 @@ param( [Parameter(ParameterSetName='Attended')] [string] $LicenseFile = $( - if (Test-Path $PSScriptRoot\files\chocolatey.license.xml) { + if (Test-Path $PSScriptRoot\packages\chocolatey.license.xml) { # Offline setup has been run, we should use that license. - Join-Path $PSScriptRoot "files\chocolatey.license.xml" + Join-Path $PSScriptRoot "packages\chocolatey.license.xml" } elseif (Test-Path $env:ChocolateyInstall\license\chocolatey.license.xml) { # Chocolatey is already installed, we can use that license. Join-Path $env:ChocolateyInstall "license\chocolatey.license.xml" @@ -106,7 +106,7 @@ try { Write-Host "Setting up initial directories in"$env:SystemDrive\choco-setup"" -ForegroundColor Green $ChocoPath = "$env:SystemDrive\choco-setup" $FilesDir = Join-Path $ChocoPath "files" - $PkgsDir = Join-Path $FilesDir "files" + $PkgsDir = Join-Path $FilesDir "packages" $TempDir = Join-Path $ChocoPath "temp" $TestDir = Join-Path $ChocoPath "tests" @($ChocoPath, $FilesDir, $PkgsDir, $TempDir, $TestDir) | ForEach-Object { @@ -133,8 +133,8 @@ try { & $FilesDir\OfflineInstallPreparation.ps1 -LicensePath $LicenseFile - if (Test-Path $FilesDir\files\*.nupkg) { - choco source add --name LocalChocolateySetup --source $FilesDir\files\ --Priority 1 + if (Test-Path $FilesDir\packages\*.nupkg) { + choco source add --name LocalChocolateySetup --source $FilesDir\packages\ --Priority 1 } # Set Choco Server Chocolatey Configuration diff --git a/files/chocolatey.json b/packages/chocolatey.json similarity index 100% rename from files/chocolatey.json rename to packages/chocolatey.json diff --git a/files/jenkins.json b/packages/jenkins.json similarity index 100% rename from files/jenkins.json rename to packages/jenkins.json diff --git a/scripts/ClientSetup.ps1 b/scripts/ClientSetup.ps1 index 45e1665..7136a46 100644 --- a/scripts/ClientSetup.ps1 +++ b/scripts/ClientSetup.ps1 @@ -86,13 +86,13 @@ if ($Credential) { $NupkgUrl = if (-not $ChocolateyVersion) { $QueryString = "((Id eq 'chocolatey') and (not IsPrerelease)) and IsLatestVersion" $Query = 'Packages()?$filter={0}' -f [uri]::EscapeUriString($queryString) - $QueryUrl = ($RepositoryUrl.TrimEnd('/index.json'), $Query) -join '/' + $QueryUrl = ($RepositoryUrl.Replace('/index.json',''), $Query) -join '/' [xml]$result = $webClient.DownloadString($QueryUrl) $result.feed.entry.content.src } else { # Otherwise, assume the URL - "$($RepositoryUrl.TrimEnd('/index.json'))/chocolatey/$($ChocolateyVersion)" + "$($RepositoryUrl.Replace('/index.json',''))/chocolatey/$($ChocolateyVersion)" } # Download the NUPKG @@ -111,6 +111,13 @@ $script = $webClient.DownloadString("https://${hostAddress}/repository/choco-ins choco config set cacheLocation $env:ChocolateyInstall\choco-cache choco config set commandExecutionTimeoutSeconds 14400 +if ($InternetEnabled) { + choco source add --name="'ChocolateyCore'" --source="'$RepositoryUrl'" --allow-self-service --admin-only --user="'$($Credential.UserName)'" --password="'$($Credential.GetNetworkCredential().Password)'" --priority=0 +} +else { + choco source add --name="'ChocolateyCore'" --source="'$RepositoryUrl'" --allow-self-service --admin-only --priority=0 +} + if ($InternetEnabled) { choco source add --name="'ChocolateyInternal'" --source="'$RepositoryUrl'" --allow-self-service --user="'$($Credential.UserName)'" --password="'$($Credential.GetNetworkCredential().Password)'" --priority=1 } @@ -121,12 +128,12 @@ else { choco source disable --name="'Chocolatey'" choco source disable --name="'chocolatey.licensed'" -choco upgrade chocolatey-license -y --source="'ChocolateyInternal'" -choco upgrade chocolatey.extension -y --params="'/NoContextMenu'" --source="'ChocolateyInternal'" --no-progress -choco upgrade chocolateygui -y --source="'ChocolateyInternal'" --no-progress -choco upgrade chocolateygui.extension -y --source="'ChocolateyInternal'" --no-progress +choco upgrade chocolatey-license -y --source="'ChocolateyCore'" +choco upgrade chocolatey.extension -y --params="'/NoContextMenu'" --source="'ChocolateyCore'" --no-progress +choco upgrade chocolateygui -y --source="'ChocolateyCore'" --no-progress +choco upgrade chocolateygui.extension -y --source="'ChocolateyCore'" --no-progress -choco upgrade chocolatey-agent -y --source="'ChocolateyInternal'" +choco upgrade chocolatey-agent -y --source="'ChocolateyCore'" # Chocolatey Package Upgrade Resilience choco feature enable --name="'excludeChocolateyPackagesDuringUpgradeAll'" diff --git a/scripts/Create-ChocoLicensePkg.ps1 b/scripts/Create-ChocoLicensePkg.ps1 index 3cc11f4..2eb1938 100644 --- a/scripts/Create-ChocoLicensePkg.ps1 +++ b/scripts/Create-ChocoLicensePkg.ps1 @@ -13,7 +13,7 @@ param( # Local path used to build the license package. [Parameter()] [string] - $PackagesPath = "$env:SystemDrive\choco-setup\files\files", + $PackagesPath = "$env:SystemDrive\choco-setup\files\packages", # Path to the license file. [Parameter()] diff --git a/tests/jenkins.test.ps1 b/tests/jenkins.test.ps1 index 7c48dc4..6a7c990 100644 --- a/tests/jenkins.test.ps1 +++ b/tests/jenkins.test.ps1 @@ -74,7 +74,7 @@ Describe "Jenkins Configuration" { Context "Required Plugins" { BeforeDiscovery { - $ExpectedPlugins = (Get-Content $PSScriptRoot\..\files\jenkins.json | ConvertFrom-Json).plugins.name + $ExpectedPlugins = (Get-Content $PSScriptRoot\..\packages\jenkins.json | ConvertFrom-Json).plugins.name } BeforeAll { diff --git a/tests/nexus.tests.ps1 b/tests/nexus.tests.ps1 index 72b4068..a7f8912 100644 --- a/tests/nexus.tests.ps1 +++ b/tests/nexus.tests.ps1 @@ -82,10 +82,15 @@ nexus-args=${jetty.etc}/jetty.xml,${jetty.etc}/jetty-https.xml,${jetty.etc}/jett $repositories = Get-NexusRepository } + It "ChocolateyInternal" { 'ChocolateyInternal' -in $repositories.Name | Should -Be $true } + It "ChocolateyCore" { + 'ChocolateyCore' -in $repositories.Name | Should -Be $true + } + It "ChocolateyTest" { 'ChocolateyTest' -in $repositories.Name | Should -Be $true } @@ -105,7 +110,7 @@ nexus-args=${jetty.etc}/jetty.xml,${jetty.etc}/jetty-https.xml,${jetty.etc}/jett choco cache remove } - $packages = choco.exe search -s ChocolateyInternal -r | ConvertFrom-Csv -Delimiter '|' -Header Package,Version + $packages = choco.exe search -s ChocolateyCore -r | ConvertFrom-Csv -Delimiter '|' -Header Package,Version } It " is in the repository" -ForEach @( $JointPackages + $RepositoryOnlyPackages ) {