Skip to content

Commit

Permalink
(#230) Add ChocolateyCore Repo source
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
ryanrichter94 committed Jul 24, 2024
1 parent 19bf837 commit d2de05b
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 39 deletions.
22 changes: 11 additions & 11 deletions OfflineInstallPreparation.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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/'
}
Expand All @@ -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
Expand All @@ -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) {
Expand All @@ -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"
Expand All @@ -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
}
38 changes: 32 additions & 6 deletions Set-SslSecurity.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

}

Expand All @@ -201,22 +215,34 @@ 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
Remove-NexusRepositoryFolder -RepositoryName ChocolateyInternal -Name v3

Update-JsonFile -Path "$env:SystemDrive\choco-setup\logs\nexus.json" -Properties @{
NexusUri = "https://$($SubjectWithoutCn):8443"
NexusRepo = $RepositoryUrl
NexusRepo = $CoreRepositoryUrl
ChocoUserPassword = $NexusPw
}

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Start-C4bCcmSetup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions Start-C4bJenkinsSetup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions Start-C4bNexusSetup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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"
Expand Down
10 changes: 5 additions & 5 deletions Start-C4bSetup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down
File renamed without changes.
File renamed without changes.
21 changes: 14 additions & 7 deletions scripts/ClientSetup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -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'"
Expand Down
2 changes: 1 addition & 1 deletion scripts/Create-ChocoLicensePkg.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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()]
Expand Down
2 changes: 1 addition & 1 deletion tests/jenkins.test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 6 additions & 1 deletion tests/nexus.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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 "<Name> is in the repository" -ForEach @( $JointPackages + $RepositoryOnlyPackages ) {
Expand Down

0 comments on commit d2de05b

Please sign in to comment.