-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add spec and scripts for creating chocolatey package for crc
the package currently performs the setup steps like installing hyper-v creation of 'crc-users' group, adding current user to the hyper-v administrators group. It doesn't install or setup the tray it is a portable choco package and embedds the crc and crc-admin-helper-windows binaries
- Loading branch information
1 parent
f8b21f8
commit ad5d477
Showing
9 changed files
with
216 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Chocolatey package for CRC (non GUI) | ||
|
||
## Pre-requisite | ||
|
||
The host machine needs to have [Chocolatey](https://chocolatey.org/) installed and should be able to build `crc`. Follow [chocolatey install guide](https://chocolatey.org/install) to install it. | ||
|
||
## Steps to build the package | ||
|
||
Build steps for the chocolatey package is incorporated in the `Makefile` under the `choco` target. | ||
|
||
1. Run `make choco`: | ||
``` | ||
PS> make choco | ||
rm -rf /cygdrive/c/Users/anath/redhat/crc/docs/build | ||
rm -f packaging/darwin/Distribution | ||
rm -f packaging/darwin/Resources/welcome.html | ||
rm -f packaging/darwin/scripts/postinstall | ||
rm -rf packaging/darwin/root/ | ||
rm -rf packaging/windows/msi | ||
rm -f out/windows-amd64/split | ||
rm -f packaging/rpm/crc.spec images/rpmbuild/Containerfile | ||
rm -rf out | ||
rm -f C:\Users\anath\go/bin/crc | ||
rm -rf release | ||
GOARCH=amd64 GOOS=windows go build -tags "containers_image_openpgp" -ldflags="-X github.com/crc-org/crc/pkg/crc/version.crcVersion=2.12.0 -X github.com/crc-org/crc/pkg/crc/version.ocpVersion=4.11.18 -X github.com/crc-org/crc/pkg/crc/version.okdVersion=4.11.0-0.okd-2022-11-05-030711 -X github.com/crc-org/crc/pkg/crc/version.podmanVersion=4.2.0 -X github.com/crc-org/crc/pkg/crc/version.commitSha=40b730ce " -o out/windows-amd64/crc.exe ./cmd/crc | ||
go build --tags="build" -ldflags="-X github.com/crc-org/crc/pkg/crc/version.crcVersion=2.12.0 -X github.com/crc-org/crc/pkg/crc/version.ocpVersion=4.11.18 -X github.com/crc-org/crc/pkg/crc/version.okdVersion=4.11.0-0.okd-2022-11-05-030711 -X github.com/crc-org/crc/pkg/crc/version.podmanVersion=4.2.0 -X github.com/crc-org/crc/pkg/crc/version.commitSha=40b730ce " -o out/windows-amd64/crc-embedder ./cmd/crc-embedder | ||
out/windows-amd64/crc-embedder download --goos=windows packaging/chocolatey/crc/tools | ||
0 B / 97.26 MiB [______________________________________________________________________________________________________________________________________________________________________________________] 0.00% ? p/s | ||
cp out/windows-amd64/crc.exe packaging/chocolatey/crc/tools/crc.exe | ||
cd packaging/chocolatey/crc && choco pack | ||
Chocolatey v1.2.0 | ||
Attempting to build package from 'crc.nuspec'. | ||
Successfully created package 'C:\Users\anath\redhat\crc\packaging\chocolatey\crc\crc.2.12.0.nupkg' | ||
``` | ||
|
||
2. Above command will generated `crc.nupkg` in the `packaging/chocolatey/crc` folder | ||
|
||
## Steps to push the package to chocolatey community repo | ||
|
||
1. Create [account](https://community.chocolatey.org/account/Register) in the chocolatey community feed. | ||
3. Copy the API Key from the [accounts page](https://community.chocolatey.org/account) (Click on the Show API Key button). | ||
4. Associate your API key with community feed: | ||
``` | ||
PS> choco apikey --key <account_api_key> --source https://push.chocolatey.org/ | ||
``` | ||
5. Push the package using: | ||
``` | ||
PS> choco push crc.2.11.0.nupkg --source https://push.chocolatey.org/ | ||
``` | ||
|
||
> Note: Chocolatey has a moderation process and there might be a need to answer queries from the moderators, keep an eye on the [package queue](https://community.chocolatey.org/packages). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd"> | ||
<metadata> | ||
<id>crc</id> | ||
<version>__VERSION__</version> | ||
<owners>https://github.com/crc-org</owners> | ||
<title>CRC - Runs Containers</title> | ||
<authors>anjannath</authors> | ||
<projectUrl>https://crc.dev/blog/about</projectUrl> | ||
<iconUrl>https://i.ibb.co/m0b6dsL/crc-upstream-logo.png</iconUrl> | ||
<licenseUrl>https://github.com/crc-org/crc/blob/main/LICENSE</licenseUrl> | ||
<requireLicenseAcceptance>false</requireLicenseAcceptance> | ||
<tags>crc ocp openshift openshiftlocal okd podman</tags> | ||
<summary>CRC is a tool to run containers. It manages a local OpenShift 4.x cluster, OKD cluster or a Podman VM optimized for testing and development purposes.</summary> | ||
<description> | ||
## CRC - Runs Containers | ||
|
||
CRC is a tool to run containers. It manages a local OpenShift 4.x cluster, OKD cluster or a Podman VM optimized for testing and development purposes. | ||
Learn more and contribute on [GitHub](https://github.com/crc-org/crc). | ||
</description> | ||
<releaseNotes>https://github.com/crc-org/crc/releases/tag/v__VERSION__</releaseNotes> | ||
<copyright>2022 Red Hat, Inc</copyright> | ||
<packageSourceUrl>https://github.com/crc-org/crc/tree/main/packaging/chocolatey</packageSourceUrl> | ||
<projectSourceUrl>https://github.com/crc-org/crc</projectSourceUrl> | ||
<docsUrl>https://crc.dev/crc</docsUrl> | ||
</metadata> | ||
<files> | ||
<file src="tools\**" target="tools" /> | ||
</files> | ||
</package> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
VERIFICATION | ||
|
||
Verification is intended to assist the Chocolatey moderators and community | ||
in verifying that this package's contents are trustworthy. | ||
|
||
This package is published by the CRC project itself. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# This runs in 0.9.10+ before upgrade and uninstall. | ||
# Use this file to do things like stop services prior to upgrade or uninstall. | ||
# NOTE: It is an anti-pattern to call chocolateyUninstall.ps1 from here. If you | ||
# need to uninstall an MSI prior to upgrade, put the functionality in this | ||
# file without calling the uninstall script. Make it idempotent in the | ||
# uninstall script so that it doesn't fail when it is already uninstalled. | ||
# NOTE: For upgrades - like the uninstall script, this script always runs from | ||
# the currently installed version, not from the new upgraded package version. | ||
|
||
$ErrorActionPreference = 'SilentlyContinue'; | ||
|
||
# stop crc-admin-helper service and remove it | ||
Stop-Service -Name 'crcAdminHelper' -Force -Confirm:$false | Out-Null | ||
sc.exe delete "crcAdminHelper" | Out-Null | ||
|
||
# stop crc daemon scheduled task and remove it | ||
Stop-ScheduledTask -TaskName 'crcDaemon' | Out-Null | ||
Unregister-ScheduledTask -TaskName 'crcDaemon' -Confirm:$false | Out-Null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
$ErrorActionPreference = 'Stop'; # stop on all errors | ||
$toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)" | ||
$setupScript = Join-Path "$toolsDir" "crcprerequisitesetup.ps1" | ||
|
||
Import-Module $setupScript | ||
|
||
# generate ignore file for crc-admin-helper-windows.exe to avoid shim generation and addintion to PATH | ||
New-Item "$toolsDir\crc-admin-helper-windows.exe.ignore" -ItemType File -Force | Out-Null | ||
|
||
if (Test-ProcessAdminRights) { | ||
New-CrcGroup | ||
Install-Hyperv | ||
Install-AdminHelper -AdminHelperPath "$toolsDir\crc-admin-helper-windows.exe" | ||
New-VsockGuestCommunicationRegistry | ||
} else { | ||
Write-Host "CRC needs administrator privileges to enable Hyper-V, create new group and add current user to needed groups, please run the installation as administrator" | ||
Exit 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
$ErrorActionPreference = 'SilentlyContinue'; | ||
$toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)" | ||
$setupScript = Join-Path "$toolsDir" "crcprerequisitesetup.ps1" | ||
|
||
Import-Module $setupScript | ||
|
||
# remove crc-users group | ||
Remove-LocalGroup -Name 'crc-users' -Confirm:$false | Out-Null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
$CrcGroupName = 'crc-users' | ||
$CrcAdminHelperServiceName = 'crcAdminHelper' | ||
$VsockGuestCommunicationRegistryPath = "HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Virtualization\GuestCommunicationServices\00000400-FACB-11E6-BD58-64006A7986D3" | ||
|
||
function New-CrcGroup { | ||
$crcgrp = Get-LocalGroup -Name $CrcGroupName -ErrorAction SilentlyContinue | ||
if ($crcgrp) { | ||
Write-Host "crc-users group already exists" | ||
} else { | ||
New-LocalGroup -Name $CrcGroupName -Description 'Group for Red Hat OpenShift Local users' | Out-Null | ||
} | ||
} | ||
|
||
function Install-Hyperv { | ||
$osProductType = Get-ComputerInfo | Select-Object -ExpandProperty OSProductType | Out-String -Stream | Where-Object { $_.Trim().Length -gt 0 } | ||
switch ($osProductType) | ||
{ | ||
"WorkStation" { | ||
# check if hyperv is already enabled | ||
$enabled = (Get-WindowsOptionalFeature -FeatureName "Microsoft-Hyper-V" -online | Select-Object -ExpandProperty State).ToString().Equals("Enabled") | ||
if ($enabled) { | ||
Write-Host "Hyper-V is already enabled" | ||
} else { | ||
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All -NoRestart -ErrorAction SilentlyContinue | Out-Null | ||
} | ||
} | ||
"Server" { | ||
$enabled = (Get-WindowsFeature -Name "Hyper-V" | Select-Object -ExpandProperty InstallState).ToString().Equals("Installed") | ||
if ($enabled) { | ||
Write-Host "Hyper-V is already enabled" | ||
} else { | ||
Install-WindowsFeature -Name Hyper-V -IncludeManagementTools -ErrorAction SilentlyContinue | Out-Null | ||
} | ||
} | ||
} | ||
} | ||
|
||
function Install-AdminHelper([string]$AdminHelperPath) { | ||
$svc = Get-Service -Name "$CrcAdminHelperServiceName" -ErrorAction SilentlyContinue | ||
if ($svc) { | ||
Write-Host "Red Hat OpenShift Local Admin Helper service is already installed" | ||
} else { | ||
# New-Service cmdlet doesn't have a flag to set the arguments for admin-helper, it is passed using the -BinaryPathName itself | ||
New-Service -Name 'crcAdminHelper' -DisplayName "Red Hat OpenShift Local Admin Helper" -Description "Perform administrative tasks for the user" -StartupType Automatic -BinaryPathName "$AdminHelperPath daemon" | Out-Null | ||
} | ||
|
||
Start-Service -Name 'crcAdminHelper' -Confirm:$false | Out-Null | ||
} | ||
|
||
function New-VsockGuestCommunicationRegistry { | ||
# check if the registry path exists | ||
$pathExists = Test-Path -Path $VsockGuestCommunicationRegistryPath -ErrorAction SilentlyContinue | ||
# check if the property 'ElementName' exists at the path | ||
$property = Get-ItemProperty -Path $VsockGuestCommunicationRegistryPath -Name 'ElementName' -ErrorAction SilentlyContinue | ||
$propertyExists = $property.ElementName -eq "gvisor-tap-vsock" | ||
if ($pathExists -and $propertyExists) { | ||
Write-Host "Property ElementName in $VsockGuestCommunicationRegistryPath already exists" | ||
} else { | ||
# create the registry node | ||
New-Item -Path $VsockGuestCommunicationRegistryPath -ErrorAction SilentlyContinue | Out-Null | ||
# remove any pre-existing value | ||
Remove-ItemProperty -Path $VsockGuestCommunicationRegistryPath -Name 'ElementName' -ErrorAction SilentlyContinue | Out-Null | ||
# add the 'ElementName' property | ||
New-ItemProperty -Path $VsockGuestCommunicationRegistryPath -Name 'ElementName' -Value 'gvisor-tap-vsock' -PropertyType string -Confirm:$false | Out-Null | ||
} | ||
} |