Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ clean:
fmt:
@gofmt -l -w $(SOURCE_DIRS)

.PHONY: lint
lint:
${CONTAINER_MANAGER} run -it --rm -v ${PWD}:/workspace:z --workdir=/workspace quay.io/app-sre/golangci-lint:v1.53.2-alpine \
golangci-lint run -v --timeout 10m
# Run golangci-lint against code
.PHONY: lint
lint: $(TOOLS_BINDIR)/golangci-lint
"$(TOOLS_BINDIR)"/golangci-lint run -v --timeout 10m

# Build the container image
.PHONY: oci-build
Expand Down
4 changes: 4 additions & 0 deletions cmd/cmd/azure/hosts/windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const (
defaultAdminUsername = "rhqpadmin"
paramSpot = "spot"
paramSpotDesc = "if spot is set the spot prices across all regions will be cheked and machine will be started on best spot option (price / eviction)"
paramProfile = "profile"
paramProfileDesc = "comma seperated list of profiles to apply on the target machine. Profiles available: crc"
)

func GetWindowsDesktopCmd() *cobra.Command {
Expand Down Expand Up @@ -75,6 +77,7 @@ func getCreate() *cobra.Command {
Feature: viper.GetString(paramFeature),
Username: viper.GetString(paramUsername),
AdminUsername: viper.GetString(paramAdminUsername),
Profiles: viper.GetStringSlice(paramProfile),
Spot: viper.IsSet(paramSpot)}); err != nil {
logging.Error(err)
}
Expand All @@ -90,6 +93,7 @@ func getCreate() *cobra.Command {
flagSet.StringP(paramFeature, "", defaultFeature, paramFeatureDesc)
flagSet.StringP(paramUsername, "", defaultUsername, paramUsernameDesc)
flagSet.StringP(paramAdminUsername, "", defaultAdminUsername, paramAdminUsernameDesc)
flagSet.StringSliceP(paramProfile, "", []string{}, paramProfileDesc)
flagSet.Bool(paramSpot, false, paramSpotDesc)
c.PersistentFlags().AddFlagSet(flagSet)
return c
Expand Down
18 changes: 15 additions & 3 deletions docs/azure.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,24 @@ It creates / destroy a windows dekstop edition ready to be included within the C
* Disable UAC
* Running ssh server as a startup process run by the worker user

## Profiles

It is possible to customize the initial setup for the target host based on profiles, a target host can created with several profiles:

### crc profile

This wil create the crc-users group and add the user to it, to avoid reboot during crc installation

Side note: the other requirements for reboot are done by default; hyper-v installation and add user to Admin group

### Operations

#### Create

This will create a windows desktop accordig to params specificed:

```bash
podman run -it --rm quay.io/rhqp/qenvs:v0.0.5 azure windows create -h
podman run -it --rm quay.io/rhqp/qenvs:v0.7.0 azure windows create -h
create

Usage:
Expand All @@ -31,11 +41,12 @@ Flags:
--conn-details-output string path to export host connection information (host, username and privateKey)
-h, --help help for create
--location string location for created resources within Windows desktop (default "West US")
--profile strings comma seperated list of profiles to apply on the target machine. Profiles available: crc
--spot if spot is set the spot prices across all regions will be cheked and machine will be started on best spot option (price / eviction)
--tags stringToString tags to add on each resource (--tags name1=value1,name2=value2) (default [])
--username string username for general user. SSH accessible + rdp with generated password (default "rhqp")
--vmsize string size for the VM. Type requires to allow nested virtualization (default "Standard_D8a_v4")
--windows-featurepack string windows feature pack (default "22h2-pro")
--vmsize string size for the VM. Type requires to allow nested virtualization (default "Standard_D8s_v4")
--windows-featurepack string windows feature pack (default "23h2-pro")
--windows-version string Major version for windows desktop 10 or 11 (default "11")

Global Flags:
Expand Down Expand Up @@ -69,6 +80,7 @@ podman run -d --rm \
--project-name "win-desk-11" \
--backed-url "file:///workspace" \
--conn-details-output "/workspace" \
--profile crc \
--spot
```

Expand Down
4 changes: 4 additions & 0 deletions pkg/provider/azure/action/windows/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ const (
outputAdminUserPassword = "awdAdminUserPassword"

prioritySpot = "Spot"

ProfileCRC = "crc"
)

var profiles = []string{ProfileCRC}
19 changes: 14 additions & 5 deletions pkg/provider/azure/action/windows/rhqp-ci-setup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ param(
[Parameter(Mandatory,HelpMessage='hostname for the current machine')]
$hostname,
[Parameter(Mandatory,HelpMessage='authorizedkey for ssh private key for the user')]
$authorizedKey
$authorizedKey,
[switch]$crcProfile=$false
)
# Create local user
$Password = ConvertTo-SecureString $userPass -AsPlainText -Force
Expand Down Expand Up @@ -68,8 +69,8 @@ New-Item -Path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp" -N

# Install sshd
# Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
curl.exe -LO https://github.com/PowerShell/Win32-OpenSSH/releases/download/v9.2.0.0p1-Beta/OpenSSH-Win64-v9.2.0.0.msi
Start-Process C:\Windows\System32\msiexec.exe -ArgumentList '/qb /i OpenSSH-Win64-v9.2.0.0.msi' -wait
curl.exe -LO https://github.com/PowerShell/Win32-OpenSSH/releases/download/v9.5.0.0p1-Beta/OpenSSH-Win64-v9.5.0.0.msi
Start-Process C:\Windows\System32\msiexec.exe -ArgumentList '/qb /i OpenSSH-Win64-v9.5.0.0.msi' -wait
Set-Service -Name sshd -StartupType 'Manual'
# This generate ssh certs + config file for us
Start-Service sshd
Expand Down Expand Up @@ -103,8 +104,8 @@ If (!(Test-Path $onedrive)) {
Start-Process $onedrive "/uninstall" -NoNewWindow -Wait

# Install powershellcore
curl.exe -LO https://github.com/PowerShell/PowerShell/releases/download/v7.3.0/PowerShell-7.3.0-win-x64.msi
Start-Process C:\Windows\System32\msiexec.exe -ArgumentList '/qb /i PowerShell-7.3.0-win-x64.msi ADD_EXPLORER_CONTEXT_MENU_OPENPOWERSHELL=1 ENABLE_PSREMOTING=1 REGISTER_MANIFEST=1 USE_MU=1 ENABLE_MU=1 ADD_PATH=1' -wait
curl.exe -LO https://github.com/PowerShell/PowerShell/releases/download/v7.4.2/PowerShell-7.4.2-win-x64.msi
Start-Process C:\Windows\System32\msiexec.exe -ArgumentList '/qb /i PowerShell-7.4.2-win-x64.msi ADD_EXPLORER_CONTEXT_MENU_OPENPOWERSHELL=1 ENABLE_PSREMOTING=1 REGISTER_MANIFEST=1 USE_MU=1 ENABLE_MU=1 ADD_PATH=1' -wait
# Set powershell as default shell on openssh
New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Program Files\PowerShell\7\pwsh.exe" -PropertyType String -Force

Expand All @@ -115,6 +116,14 @@ if (!(Test-Path -Path $profilePath)) {
}
Add-Content -Path $profilePath -Value "Remove-Item alias:curl"

# Profiles it can have several profiles at once

# crc profile; create crc-users and add the user
# this is to avoid reboot requirement when installing crc
if ($crcProfile) {
New-LocalGroup -Name "crc-users"
Add-LocalGroupMember -Group "crc-users" -Member $user
}
# Restart computer to have the ssh connection available with setup from this script
Start-Process powershell -verb runas -ArgumentList "Restart-Computer -Force"

Expand Down
33 changes: 31 additions & 2 deletions pkg/provider/azure/action/windows/windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package windows
import (
_ "embed"
"fmt"
"strings"

"github.com/adrianriobo/qenvs/pkg/manager"
qenvsContext "github.com/adrianriobo/qenvs/pkg/manager/context"
Expand All @@ -11,6 +12,7 @@ import (
"github.com/adrianriobo/qenvs/pkg/provider/util/command"
"github.com/adrianriobo/qenvs/pkg/provider/util/output"
"github.com/adrianriobo/qenvs/pkg/provider/util/security"
"github.com/adrianriobo/qenvs/pkg/util"
"github.com/adrianriobo/qenvs/pkg/util/logging"
resourcesUtil "github.com/adrianriobo/qenvs/pkg/util/resources"
"github.com/pulumi/pulumi-azure-native-sdk/compute/v2"
Expand All @@ -21,6 +23,7 @@ import (
"github.com/pulumi/pulumi-tls/sdk/v5/go/tls"
"github.com/pulumi/pulumi/sdk/v3/go/auto"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
"golang.org/x/exp/slices"
)

//go:embed rhqp-ci-setup.ps1
Expand All @@ -35,6 +38,7 @@ type WindowsRequest struct {
Username string
AdminUsername string
Spot bool
Profiles []string
}

func Create(r *WindowsRequest) (err error) {
Expand Down Expand Up @@ -144,6 +148,9 @@ func (r *WindowsRequest) manageResults(stackResult auto.UpResult) error {
func (r *WindowsRequest) createVirtualMachine(ctx *pulumi.Context,
rg *resources.ResourceGroup, ni *network.NetworkInterface,
location string, spotPrice *float64) (*compute.VirtualMachine, error) {
if err := r.validateProfiles(); err != nil {
return nil, err
}
adminPasswd, err := security.CreatePassword(
ctx,
resourcesUtil.GetResourceName(r.Prefix, azureWindowsDesktopID, "pswd-adminuser"))
Expand Down Expand Up @@ -312,12 +319,14 @@ func (r *WindowsRequest) postInitSetup(ctx *pulumi.Context, rg *resources.Resour
authorizedKey := args[1].(string)
hostname := args[2].(*string)
return fmt.Sprintf(
"powershell -ExecutionPolicy Unrestricted -File %s -userPass \"%s\" -user %s -hostname %s -authorizedKey \"%s\"",
"powershell -ExecutionPolicy Unrestricted -File %s %s -userPass \"%s\" -user %s -hostname %s -authorizedKey \"%s\"",
scriptName,
r.profilesAsParams(),
password,
r.Username,
*hostname,
authorizedKey)
authorizedKey,
)
}).(pulumi.StringOutput)
// the post script will be executed as a extension
vme, err := compute.NewVirtualMachineExtension(
Expand Down Expand Up @@ -381,3 +390,23 @@ func (r *WindowsRequest) uploadScript(ctx *pulumi.Context,
BlobName: pulumi.String(scriptName),
})
}

// Check if profiles for the target hosts are supported
func (r *WindowsRequest) validateProfiles() error {
for _, p := range r.Profiles {
if !slices.Contains(profiles, p) {
return fmt.Errorf("the profile %s is not supported", p)
}
}
return nil
}

// Check if a request contains a profile
func (r *WindowsRequest) profilesAsParams() string {
pp := util.ArrayConvert(
r.Profiles,
func(p string) string {
return fmt.Sprintf("-%sProfile", p)
})
return strings.Join(pp, " ")
}
3 changes: 2 additions & 1 deletion tools/bin/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
tkn
tkn
golangci-lint
8 changes: 8 additions & 0 deletions tools/dummy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This file is not meant to be built, it's just a placeholder to ensure
// the source for the various tools that we use is properly referenced in go.mod
// and vendored in vendor/
package buildtools

import (
_ "github.com/golangci/golangci-lint/cmd/golangci-lint"
)
Loading