Skip to content

Commit

Permalink
feat: add gh actions runner setup snippet to azure setup script
Browse files Browse the repository at this point in the history
this adds new flags to the command `mapt azure windows create`
to setup github actions runner on the provisioned  instance

it also adds the additional flags to get the various values
needed to setup the github actions runner

Signed-off-by: Anjan Nath <[email protected]>
  • Loading branch information
anjannath committed Jul 9, 2024
1 parent 52a26c9 commit 932cb2a
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 22 deletions.
25 changes: 15 additions & 10 deletions cmd/mapt/cmd/azure/hosts/windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,20 @@ func getCreate() *cobra.Command {
// ParseEvictionRate
if err := azureWindows.Create(
&azureWindows.WindowsRequest{
Prefix: "",
Location: viper.GetString(paramLocation),
VMSize: viper.GetString(paramVMSize),
Version: viper.GetString(paramVersion),
Feature: viper.GetString(paramFeature),
Username: viper.GetString(paramUsername),
AdminUsername: viper.GetString(paramAdminUsername),
Profiles: viper.GetStringSlice(paramProfile),
Spot: viper.IsSet(paramSpot),
SpotTolerance: spotToleranceValue}); err != nil {
Prefix: "",
Location: viper.GetString(paramLocation),
VMSize: viper.GetString(paramVMSize),
Version: viper.GetString(paramVersion),
Feature: viper.GetString(paramFeature),
Username: viper.GetString(paramUsername),
AdminUsername: viper.GetString(paramAdminUsername),
Profiles: viper.GetStringSlice(paramProfile),
SetupGHActionsRunner: viper.IsSet(params.InstallGHActionsRunner),
GHActionsRunnerToken: viper.GetString(params.GHActionsRunnerToken),
GHActionsRunnerName: viper.GetString(params.GHActionsRunnerName),
GHActionsRunnerRepo: viper.GetString(params.GHActionsRunnerRepo),
Spot: viper.IsSet(paramSpot),
SpotTolerance: spotToleranceValue}); err != nil {
logging.Error(err)
}
return nil
Expand All @@ -113,6 +117,7 @@ func getCreate() *cobra.Command {
flagSet.StringSliceP(paramProfile, "", []string{}, paramProfileDesc)
flagSet.Bool(paramSpot, false, paramSpotDesc)
flagSet.StringP(paramSpotTolerance, "", defaultSpotTolerance, paramSpotToleranceDesc)
flagSet.AddFlagSet(params.GetGHActionsFlagset())
c.PersistentFlags().AddFlagSet(flagSet)
return c
}
Expand Down
20 changes: 19 additions & 1 deletion pkg/provider/azure/action/windows/rhqp-ci-setup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ param(
$hostname,
[Parameter(Mandatory,HelpMessage='authorizedkey for ssh private key for the user')]
$authorizedKey,
[switch]$crcProfile=$false
[Parameter(HelpMessage='token to register the github actions runner')]
$ghRunnerToken,
[Parameter(HelpMessage='name to be used for the github actions runner')]
$ghRunnerName,
[Parameter(HelpMessage='full url of the repo for the github actions runner')]
$ghRunnerRepo,
[switch]$crcProfile=$false,
[switch]$installGHActionsRunner=$false
)
# Create local user
$Password = ConvertTo-SecureString $userPass -AsPlainText -Force
Expand Down Expand Up @@ -124,6 +131,17 @@ if ($crcProfile) {
New-LocalGroup -Name "crc-users"
Add-LocalGroupMember -Group "crc-users" -Member $user
}

# Install github actions runner if requested
if ($installGHActionsRunner) {
New-Item -Path C:\actions-runner -Type Directory ; cd C:\actions-runner
Invoke-WebRequest -Uri https://github.com/actions/runner/releases/download/v2.317.0/actions-runner-win-x64-2.317.0.zip -OutFile actions-runner-win-x64-2.317.0.zip
Add-Type -AssemblyName System.IO.Compression.FileSystem ;
if((Get-FileHash -Path actions-runner-win-x64-2.317.0.zip -Algorithm SHA256).Hash.ToUpper() -ne 'a74dcd1612476eaf4b11c15b3db5a43a4f459c1d3c1807f8148aeb9530d69826'.ToUpper()){ throw 'Computed checksum did not match' }
[System.IO.Compression.ZipFile]::ExtractToDirectory("$PWD\actions-runner-win-x64-2.317.0.zip", "$PWD")
./config.cmd --token $ghRunnerToken --url $ghRunnerRepo --name $ghRunnerName --unattended --runasservice --replace --ephemeral
}

# Restart computer to have the ssh connection available with setup from this script
Start-Process powershell -verb runas -ArgumentList "Restart-Computer -Force"

Expand Down
38 changes: 27 additions & 11 deletions pkg/provider/azure/action/windows/windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,20 @@ import (
var RHQPCISetupScript []byte

type WindowsRequest struct {
Prefix string
Location string
VMSize string
Version string
Feature string
Username string
AdminUsername string
Spot bool
SpotTolerance spotprice.EvictionRate
Profiles []string
Prefix string
Location string
VMSize string
Version string
Feature string
Username string
AdminUsername string
Spot bool
SpotTolerance spotprice.EvictionRate
Profiles []string
SetupGHActionsRunner bool // setup as github actions runner
GHActionsRunnerToken string
GHActionsRunnerName string
GHActionsRunnerRepo string
}

func Create(r *WindowsRequest) (err error) {
Expand Down Expand Up @@ -321,12 +325,16 @@ 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 %s -userPass \"%s\" -user %s -hostname %s -authorizedKey \"%s\"",
"powershell -ExecutionPolicy Unrestricted -File %s %s -userPass \"%s\" -user %s -hostname %s %s -ghRunnerToken \"%s\" -ghRunnerRepo \"%s\" -ghRunnerName \"%s\" -authorizedKey \"%s\"",
scriptName,
r.profilesAsParams(),
password,
r.Username,
*hostname,
installActionsRunnerAsParam(r.SetupGHActionsRunner),
r.GHActionsRunnerToken,
r.GHActionsRunnerRepo,
r.GHActionsRunnerName,
authorizedKey,
)
}).(pulumi.StringOutput)
Expand Down Expand Up @@ -416,3 +424,11 @@ func (r *WindowsRequest) profilesAsParams() string {
})
return strings.Join(pp, " ")
}

func installActionsRunnerAsParam(installRunner bool) string {
if installRunner {
// the arg name has to match with the one defined in rhqp-ci-setup.ps1
return "-installGHActionsRunner"
}
return ""
}

0 comments on commit 932cb2a

Please sign in to comment.