Skip to content

Commit 8876bc6

Browse files
committed
feat: add gh actions runner setup for rhel on aws
this adds new flags to the command `mapt aws rhel create` to to install 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 <kaludios@gmail.com>
1 parent 60a6772 commit 8876bc6

5 files changed

Lines changed: 67 additions & 11 deletions

File tree

cmd/mapt/cmd/aws/hosts/rhel.go

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
params "github.com/redhat-developer/mapt/cmd/mapt/cmd/constants"
55
maptContext "github.com/redhat-developer/mapt/pkg/manager/context"
66
"github.com/redhat-developer/mapt/pkg/provider/aws/action/rhel"
7+
"github.com/redhat-developer/mapt/pkg/util/ghactions"
78
"github.com/redhat-developer/mapt/pkg/util/logging"
89
"github.com/spf13/cobra"
910
"github.com/spf13/pflag"
@@ -61,18 +62,30 @@ func getRHELCreate() *cobra.Command {
6162
viper.GetString(params.ConnectionDetailsOutput),
6263
viper.GetStringMapString(params.Tags))
6364

65+
// Initialize gh actions runner if needed
66+
if viper.IsSet(params.InstallGHActionsRunner) {
67+
err := ghactions.InitGHRunnerArgs(viper.GetString(params.GHActionsRunnerToken),
68+
viper.GetString(params.GHActionsRunnerName),
69+
viper.GetString(params.GHActionsRunnerRepo))
70+
if err != nil {
71+
logging.Error(err)
72+
}
73+
}
74+
6475
// Run create
6576
if err := rhel.Create(
6677
&rhel.Request{
67-
Prefix: "main",
68-
Version: viper.GetString(rhelVersion),
69-
Arch: viper.GetString(rhelArch),
70-
VMType: viper.GetStringSlice(vmTypes),
71-
SubsUsername: viper.GetString(subsUsername),
72-
SubsUserpass: viper.GetString(subsUserpass),
73-
ProfileSNC: viper.IsSet(profileSNC),
74-
Spot: viper.IsSet(spot),
75-
Airgap: viper.IsSet(airgap)}); err != nil {
78+
Prefix: "main",
79+
Version: viper.GetString(rhelVersion),
80+
Arch: viper.GetString(rhelArch),
81+
VMType: viper.GetStringSlice(vmTypes),
82+
SubsUsername: viper.GetString(subsUsername),
83+
SubsUserpass: viper.GetString(subsUserpass),
84+
ProfileSNC: viper.IsSet(profileSNC),
85+
Spot: viper.IsSet(spot),
86+
Airgap: viper.IsSet(airgap),
87+
SetupGHActionsRunner: viper.GetBool(params.InstallGHActionsRunner),
88+
}); err != nil {
7689
logging.Error(err)
7790
}
7891
return nil
@@ -89,6 +102,7 @@ func getRHELCreate() *cobra.Command {
89102
flagSet.Bool(airgap, false, airgapDesc)
90103
flagSet.Bool(spot, false, spotDesc)
91104
flagSet.Bool(profileSNC, false, profileSNCDesc)
105+
flagSet.AddFlagSet(params.GetGHActionsFlagset())
92106
c.PersistentFlags().AddFlagSet(flagSet)
93107
// if err := c.MarkFlagRequired(subsUsername); err != nil {
94108
// logging.Error(err)

pkg/provider/aws/action/rhel/cloud-config-base

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,12 @@ rh_subscription:
55
auto-attach: true
66
runcmd:
77
- while fuser /var/lib/rpm/.rpm.lock > /dev/null 2>&1 ; do sleep 1 ; done
8-
- dnf install -y podman
8+
- dnf install -y podman
9+
{{ if .InstallActionsRunner }} - sudo -u {{ .Username }} bash -c /opt/install-ghrunner.sh{{ end }}
10+
{{ if .InstallActionsRunner }}write_files:
11+
# Github actions runner installation
12+
- content: |
13+
{{ .ActionsRunnerSnippet }}
14+
path: /opt/install-ghrunner.sh
15+
permissions: '0755'
16+
{{ end }}

pkg/provider/aws/action/rhel/cloud-config-snc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,11 @@ runcmd:
2525
- echo "user.max_user_namespaces=28633" | tee -a /etc/sysctl.d/userns.conf
2626
- sysctl -p /etc/sysctl.d/userns.conf
2727
- dnf upgrade -y curl openssl
28+
{{ if .InstallActionsRunner }} - sudo -u {{ .Username }} bash -c /opt/install-ghrunner.sh {{ end }}
29+
{{ if .InstallActionsRunner }}write_files:
30+
# Github actions runner installation
31+
- content: |
32+
{{ .ActionsRunnerSnippet }}
33+
path: /opt/install-ghrunner.sh
34+
permissions: '0755'
35+
{{ end }}

pkg/provider/aws/action/rhel/rhel.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/redhat-developer/mapt/pkg/provider/util/output"
2626
"github.com/redhat-developer/mapt/pkg/util"
2727
"github.com/redhat-developer/mapt/pkg/util/file"
28+
"github.com/redhat-developer/mapt/pkg/util/ghactions"
2829
resourcesUtil "github.com/redhat-developer/mapt/pkg/util/resources"
2930
)
3031

@@ -41,6 +42,8 @@ type Request struct {
4142
ProfileSNC bool
4243
Spot bool
4344
Airgap bool
45+
// setup as github actions runner
46+
SetupGHActionsRunner bool
4447
// internal management
4548
// For airgap scenario there is an orchestation of
4649
// a phase with connectivity on the machine (allowing bootstraping)
@@ -56,6 +59,8 @@ type userDataValues struct {
5659
SubscriptionUsername string
5760
SubscriptionPassword string
5861
Username string
62+
InstallActionsRunner bool
63+
ActionsRunnerSnippet string
5964
}
6065

6166
//go:embed cloud-config-base
@@ -274,7 +279,9 @@ func (r *Request) getUserdata() (pulumi.StringPtrInput, error) {
274279
userDataValues{
275280
r.SubsUsername,
276281
r.SubsUserpass,
277-
amiUserDefault},
282+
amiUserDefault,
283+
r.SetupGHActionsRunner,
284+
ghactions.GetActionRunnerSnippetLinux()},
278285
resourcesUtil.GetResourceName(
279286
r.Prefix, awsRHELDedicatedID, "userdata"),
280287
templateConfig)

pkg/util/ghactions/runner.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,28 @@ if((Get-FileHash -Path actions-runner-win-x64-2.317.0.zip -Algorithm SHA256).Has
3333
[System.IO.Compression.ZipFile]::ExtractToDirectory("$PWD\actions-runner-win-x64-2.317.0.zip", "$PWD")
3434
./config.cmd --token %s --url %s --name %s --unattended --runasservice --replace`
3535

36+
// whitespace at the start is required since this is expanded in a cloud-init yaml file
37+
// to start as service need to relable the runsvc.sh file on rhel: https://github.com/actions/runner/issues/3222
38+
const LinuxActionsRunnerInstallSnippet string = ` mkdir ~/actions-runner && cd ~/actions-runner` + "\n" +
39+
` curl -o actions-runner-linux-x64-2.317.0.tar.gz -L https://github.com/actions/runner/releases/download/v2.317.0/actions-runner-linux-x64-2.317.0.tar.gz` + "\n" +
40+
` echo "9e883d210df8c6028aff475475a457d380353f9d01877d51cc01a17b2a91161d actions-runner-linux-x64-2.317.0.tar.gz" | sha256sum -c` + "\n" +
41+
` tar xzf ./actions-runner-linux-x64-2.317.0.tar.gz` + "\n" +
42+
` sudo ./bin/installdependencies.sh` + "\n" +
43+
` ./config.sh --token %s --url %s --name %s --unattended --replace` + "\n" +
44+
` sudo ./svc.sh install` + "\n" +
45+
` chcon system_u:object_r:usr_t:s0 $(pwd)/runsvc.sh` + "\n" +
46+
` sudo ./svc.sh start`
47+
3648
func GetActionRunnerSnippetWin() string {
3749
if (args == &RunnerArgs{}) {
3850
return ""
3951
}
4052
return fmt.Sprintf(WindowsActionsRunnerInstallSnippet, args.Token, args.RepoURL, args.Name)
4153
}
54+
55+
func GetActionRunnerSnippetLinux() string {
56+
if (args == &RunnerArgs{}) {
57+
return ""
58+
}
59+
return fmt.Sprintf(LinuxActionsRunnerInstallSnippet, args.Token, args.RepoURL, args.Name)
60+
}

0 commit comments

Comments
 (0)