diff --git a/cmd/mapt/cmd/aws/hosts/fedora.go b/cmd/mapt/cmd/aws/hosts/fedora.go index d8cafbdc0..db9761859 100644 --- a/cmd/mapt/cmd/aws/hosts/fedora.go +++ b/cmd/mapt/cmd/aws/hosts/fedora.go @@ -56,6 +56,7 @@ func getFedoraCreate() *cobra.Command { DebugLevel: viper.GetUint(params.DebugLevel), CirrusPWArgs: params.CirrusPersistentWorkerArgs(), GHRunnerArgs: params.GithubRunnerArgs(), + GLRunnerArgs: params.GitLabRunnerArgs(), Tags: viper.GetStringMapString(params.Tags), }, &fedora.FedoraArgs{ @@ -79,6 +80,7 @@ func getFedoraCreate() *cobra.Command { params.AddSpotFlags(flagSet) params.AddGHActionsFlags(flagSet) params.AddCirrusFlags(flagSet) + params.AddGitLabRunnerFlags(flagSet) c.PersistentFlags().AddFlagSet(flagSet) return c } @@ -92,7 +94,7 @@ func getFedoraDestroy() *cobra.Command { return err } return fedora.Destroy(&maptContext.ContextArgs{ - Context: cmd.Context(), + Context: cmd.Context(), ProjectName: viper.GetString(params.ProjectName), BackedURL: viper.GetString(params.BackedURL), Debug: viper.IsSet(params.Debug), diff --git a/cmd/mapt/cmd/aws/hosts/mac.go b/cmd/mapt/cmd/aws/hosts/mac.go index 5480f9fbc..3159dd95e 100644 --- a/cmd/mapt/cmd/aws/hosts/mac.go +++ b/cmd/mapt/cmd/aws/hosts/mac.go @@ -48,6 +48,7 @@ func getMacRequest() *cobra.Command { Debug: viper.IsSet(params.Debug), DebugLevel: viper.GetUint(params.DebugLevel), GHRunnerArgs: params.GithubRunnerArgs(), + GLRunnerArgs: params.GitLabRunnerArgs(), Tags: viper.GetStringMapString(params.Tags), }, &mac.MacRequestArgs{ @@ -67,6 +68,7 @@ func getMacRequest() *cobra.Command { flagSet.Bool(awsParams.MACFixedLocation, false, awsParams.MACFixedLocationDesc) flagSet.Bool(airgap, false, airgapDesc) params.AddGHActionsFlags(flagSet) + params.AddGitLabRunnerFlags(flagSet) c.PersistentFlags().AddFlagSet(flagSet) return c } @@ -82,7 +84,7 @@ func getMacRelease() *cobra.Command { } return mac.Release( &maptContext.ContextArgs{ - Context: cmd.Context(), + Context: cmd.Context(), Debug: viper.IsSet(params.Debug), DebugLevel: viper.GetUint(params.DebugLevel), }, @@ -109,10 +111,10 @@ func getMacDestroy() *cobra.Command { } return mac.Destroy( &maptContext.ContextArgs{ - Context: cmd.Context(), - Debug: viper.IsSet(params.Debug), - DebugLevel: viper.GetUint(params.DebugLevel), - KeepState: viper.IsSet(params.KeepState), + Context: cmd.Context(), + Debug: viper.IsSet(params.Debug), + DebugLevel: viper.GetUint(params.DebugLevel), + KeepState: viper.IsSet(params.KeepState), }, viper.GetString(awsParams.MACDHID)) }, diff --git a/cmd/mapt/cmd/aws/hosts/rhel.go b/cmd/mapt/cmd/aws/hosts/rhel.go index 6b2fdd0ea..b394918ee 100644 --- a/cmd/mapt/cmd/aws/hosts/rhel.go +++ b/cmd/mapt/cmd/aws/hosts/rhel.go @@ -52,6 +52,7 @@ func getRHELCreate() *cobra.Command { DebugLevel: viper.GetUint(params.DebugLevel), CirrusPWArgs: params.CirrusPersistentWorkerArgs(), GHRunnerArgs: params.GithubRunnerArgs(), + GLRunnerArgs: params.GitLabRunnerArgs(), Tags: viper.GetStringMapString(params.Tags), }, &rhel.RHELArgs{ @@ -82,6 +83,7 @@ func getRHELCreate() *cobra.Command { params.AddSpotFlags(flagSet) params.AddGHActionsFlags(flagSet) params.AddCirrusFlags(flagSet) + params.AddGitLabRunnerFlags(flagSet) c.PersistentFlags().AddFlagSet(flagSet) return c } @@ -95,13 +97,13 @@ func getRHELDestroy() *cobra.Command { return err } return rhel.Destroy(&maptContext.ContextArgs{ - Context: cmd.Context(), - ProjectName: viper.GetString(params.ProjectName), - BackedURL: viper.GetString(params.BackedURL), - Debug: viper.IsSet(params.Debug), - DebugLevel: viper.GetUint(params.DebugLevel), - Serverless: viper.IsSet(params.Serverless), - KeepState: viper.IsSet(params.KeepState), + Context: cmd.Context(), + ProjectName: viper.GetString(params.ProjectName), + BackedURL: viper.GetString(params.BackedURL), + Debug: viper.IsSet(params.Debug), + DebugLevel: viper.GetUint(params.DebugLevel), + Serverless: viper.IsSet(params.Serverless), + KeepState: viper.IsSet(params.KeepState), }) }, } diff --git a/cmd/mapt/cmd/aws/hosts/rhelai.go b/cmd/mapt/cmd/aws/hosts/rhelai.go index d9bbc4316..bf6ffa51c 100644 --- a/cmd/mapt/cmd/aws/hosts/rhelai.go +++ b/cmd/mapt/cmd/aws/hosts/rhelai.go @@ -87,7 +87,7 @@ func getRHELAIDestroy() *cobra.Command { return err } return rhelai.Destroy(&maptContext.ContextArgs{ - Context: cmd.Context(), + Context: cmd.Context(), ProjectName: viper.GetString(params.ProjectName), BackedURL: viper.GetString(params.BackedURL), Debug: viper.IsSet(params.Debug), diff --git a/cmd/mapt/cmd/aws/hosts/windows.go b/cmd/mapt/cmd/aws/hosts/windows.go index 815b2f829..32f736a2d 100644 --- a/cmd/mapt/cmd/aws/hosts/windows.go +++ b/cmd/mapt/cmd/aws/hosts/windows.go @@ -65,6 +65,7 @@ func getWindowsCreate() *cobra.Command { DebugLevel: viper.GetUint(params.DebugLevel), CirrusPWArgs: params.CirrusPersistentWorkerArgs(), GHRunnerArgs: params.GithubRunnerArgs(), + GLRunnerArgs: params.GitLabRunnerArgs(), Tags: viper.GetStringMapString(params.Tags), }, &windows.WindowsServerArgs{ @@ -93,6 +94,7 @@ func getWindowsCreate() *cobra.Command { params.AddSpotFlags(flagSet) params.AddGHActionsFlags(flagSet) params.AddCirrusFlags(flagSet) + params.AddGitLabRunnerFlags(flagSet) c.PersistentFlags().AddFlagSet(flagSet) return c } @@ -106,13 +108,13 @@ func getWindowsDestroy() *cobra.Command { return err } return windows.Destroy(&maptContext.ContextArgs{ - Context: cmd.Context(), - ProjectName: viper.GetString(params.ProjectName), - BackedURL: viper.GetString(params.BackedURL), - Debug: viper.IsSet(params.Debug), - DebugLevel: viper.GetUint(params.DebugLevel), - Serverless: viper.IsSet(params.Serverless), - KeepState: viper.IsSet(params.KeepState), + Context: cmd.Context(), + ProjectName: viper.GetString(params.ProjectName), + BackedURL: viper.GetString(params.BackedURL), + Debug: viper.IsSet(params.Debug), + DebugLevel: viper.GetUint(params.DebugLevel), + Serverless: viper.IsSet(params.Serverless), + KeepState: viper.IsSet(params.KeepState), }) }, } diff --git a/cmd/mapt/cmd/aws/services/eks.go b/cmd/mapt/cmd/aws/services/eks.go index ec7961e04..dbf553901 100644 --- a/cmd/mapt/cmd/aws/services/eks.go +++ b/cmd/mapt/cmd/aws/services/eks.go @@ -108,12 +108,12 @@ func getDestroyEKS() *cobra.Command { } return awsEKS.Destroy( &maptContext.ContextArgs{ - Context: cmd.Context(), - ProjectName: viper.GetString(params.ProjectName), - BackedURL: viper.GetString(params.BackedURL), - Debug: viper.IsSet(params.Debug), - DebugLevel: viper.GetUint(params.DebugLevel), - KeepState: viper.IsSet(params.KeepState), + Context: cmd.Context(), + ProjectName: viper.GetString(params.ProjectName), + BackedURL: viper.GetString(params.BackedURL), + Debug: viper.IsSet(params.Debug), + DebugLevel: viper.GetUint(params.DebugLevel), + KeepState: viper.IsSet(params.KeepState), }) }, } diff --git a/cmd/mapt/cmd/aws/services/kind.go b/cmd/mapt/cmd/aws/services/kind.go index 56c4d60c0..ca215529e 100644 --- a/cmd/mapt/cmd/aws/services/kind.go +++ b/cmd/mapt/cmd/aws/services/kind.go @@ -95,7 +95,7 @@ func destroyKind() *cobra.Command { return err } return kind.Destroy(&maptContext.ContextArgs{ - Context: cmd.Context(), + Context: cmd.Context(), ProjectName: viper.GetString(params.ProjectName), BackedURL: viper.GetString(params.BackedURL), Debug: viper.IsSet(params.Debug), diff --git a/cmd/mapt/cmd/aws/services/mac-pool.go b/cmd/mapt/cmd/aws/services/mac-pool.go index 895c7898c..756b4e7a1 100644 --- a/cmd/mapt/cmd/aws/services/mac-pool.go +++ b/cmd/mapt/cmd/aws/services/mac-pool.go @@ -99,12 +99,12 @@ func destroyMP() *cobra.Command { return err } return macpool.Destroy(&maptContext.ContextArgs{ - Context: cmd.Context(), - ProjectName: viper.GetString(params.ProjectName), - BackedURL: viper.GetString(params.BackedURL), - Debug: viper.IsSet(params.Debug), - DebugLevel: viper.GetUint(params.DebugLevel), - KeepState: viper.IsSet(params.KeepState), + Context: cmd.Context(), + ProjectName: viper.GetString(params.ProjectName), + BackedURL: viper.GetString(params.BackedURL), + Debug: viper.IsSet(params.Debug), + DebugLevel: viper.GetUint(params.DebugLevel), + KeepState: viper.IsSet(params.KeepState), }) }, } @@ -125,7 +125,7 @@ func houseKeep() *cobra.Command { } return macpool.HouseKeeper( &maptContext.ContextArgs{ - Context: cmd.Context(), + Context: cmd.Context(), ProjectName: viper.GetString(params.ProjectName), BackedURL: viper.GetString(params.BackedURL), Serverless: viper.IsSet(params.Serverless), @@ -172,6 +172,7 @@ func request() *cobra.Command { DebugLevel: viper.GetUint(params.DebugLevel), CirrusPWArgs: params.CirrusPersistentWorkerArgs(), GHRunnerArgs: params.GithubRunnerArgs(), + GLRunnerArgs: params.GitLabRunnerArgs(), Tags: viper.GetStringMapString(params.Tags), }, &macpool.RequestMachineArgs{ @@ -191,6 +192,7 @@ func request() *cobra.Command { flagSet.StringP(params.Timeout, "", "", params.TimeoutDesc) params.AddGHActionsFlags(flagSet) params.AddCirrusFlags(flagSet) + params.AddGitLabRunnerFlags(flagSet) c.PersistentFlags().AddFlagSet(flagSet) return c } @@ -205,7 +207,7 @@ func release() *cobra.Command { } return macpool.Release( &maptContext.ContextArgs{ - Context: cmd.Context(), + Context: cmd.Context(), Debug: viper.IsSet(params.Debug), DebugLevel: viper.GetUint(params.DebugLevel), Serverless: viper.IsSet(params.Serverless), diff --git a/cmd/mapt/cmd/aws/services/openshift-snc.go b/cmd/mapt/cmd/aws/services/openshift-snc.go index 266c0a1e5..9c93f0367 100644 --- a/cmd/mapt/cmd/aws/services/openshift-snc.go +++ b/cmd/mapt/cmd/aws/services/openshift-snc.go @@ -90,13 +90,13 @@ func destroySNC() *cobra.Command { return err } return openshiftsnc.Destroy(&maptContext.ContextArgs{ - Context: cmd.Context(), - ProjectName: viper.GetString(params.ProjectName), - BackedURL: viper.GetString(params.BackedURL), - Debug: viper.IsSet(params.Debug), - DebugLevel: viper.GetUint(params.DebugLevel), - Serverless: viper.IsSet(params.Serverless), - KeepState: viper.IsSet(params.KeepState), + Context: cmd.Context(), + ProjectName: viper.GetString(params.ProjectName), + BackedURL: viper.GetString(params.BackedURL), + Debug: viper.IsSet(params.Debug), + DebugLevel: viper.GetUint(params.DebugLevel), + Serverless: viper.IsSet(params.Serverless), + KeepState: viper.IsSet(params.KeepState), }) }, } diff --git a/cmd/mapt/cmd/azure/hosts/linux.go b/cmd/mapt/cmd/azure/hosts/linux.go index 998cfd33a..97e72b658 100644 --- a/cmd/mapt/cmd/azure/hosts/linux.go +++ b/cmd/mapt/cmd/azure/hosts/linux.go @@ -92,7 +92,7 @@ func getDestroyLinux() *cobra.Command { return err } return azureLinux.Destroy(&maptContext.ContextArgs{ - Context: cmd.Context(), + Context: cmd.Context(), ProjectName: viper.GetString(params.ProjectName), BackedURL: viper.GetString(params.BackedURL), Debug: viper.IsSet(params.Debug), diff --git a/cmd/mapt/cmd/azure/hosts/rhel.go b/cmd/mapt/cmd/azure/hosts/rhel.go index a0cc48a2f..6e1f1392d 100644 --- a/cmd/mapt/cmd/azure/hosts/rhel.go +++ b/cmd/mapt/cmd/azure/hosts/rhel.go @@ -49,6 +49,7 @@ func getCreateRHEL() *cobra.Command { DebugLevel: viper.GetUint(params.DebugLevel), CirrusPWArgs: params.CirrusPersistentWorkerArgs(), GHRunnerArgs: params.GithubRunnerArgs(), + GLRunnerArgs: params.GitLabRunnerArgs(), Tags: viper.GetStringMapString(params.Tags), }, &azureRHEL.RhelArgs{ @@ -77,6 +78,7 @@ func getCreateRHEL() *cobra.Command { params.AddSpotFlags(flagSet) params.AddGHActionsFlags(flagSet) params.AddCirrusFlags(flagSet) + params.AddGitLabRunnerFlags(flagSet) c.PersistentFlags().AddFlagSet(flagSet) return c } @@ -90,7 +92,7 @@ func getDestroyRHEL() *cobra.Command { return err } return azureRHEL.Destroy(&maptContext.ContextArgs{ - Context: cmd.Context(), + Context: cmd.Context(), ProjectName: viper.GetString(params.ProjectName), BackedURL: viper.GetString(params.BackedURL), Debug: viper.IsSet(params.Debug), diff --git a/cmd/mapt/cmd/azure/hosts/windows.go b/cmd/mapt/cmd/azure/hosts/windows.go index 833856a89..e9161532f 100644 --- a/cmd/mapt/cmd/azure/hosts/windows.go +++ b/cmd/mapt/cmd/azure/hosts/windows.go @@ -62,6 +62,7 @@ func getCreateWindowsDesktop() *cobra.Command { DebugLevel: viper.GetUint(params.DebugLevel), CirrusPWArgs: params.CirrusPersistentWorkerArgs(), GHRunnerArgs: params.GithubRunnerArgs(), + GLRunnerArgs: params.GitLabRunnerArgs(), Tags: viper.GetStringMapString(params.Tags), }, &azureWindows.WindowsArgs{ @@ -89,6 +90,7 @@ func getCreateWindowsDesktop() *cobra.Command { params.AddSpotFlags(flagSet) params.AddGHActionsFlags(flagSet) params.AddCirrusFlags(flagSet) + params.AddGitLabRunnerFlags(flagSet) c.PersistentFlags().AddFlagSet(flagSet) return c } @@ -102,7 +104,7 @@ func getDestroyWindowsDesktop() *cobra.Command { return err } if err := azureWindows.Destroy(&maptContext.ContextArgs{ - Context: cmd.Context(), + Context: cmd.Context(), ProjectName: viper.GetString(params.ProjectName), BackedURL: viper.GetString(params.BackedURL), Debug: viper.IsSet(params.Debug), diff --git a/cmd/mapt/cmd/azure/services/aks.go b/cmd/mapt/cmd/azure/services/aks.go index 69ab61212..5313e3423 100644 --- a/cmd/mapt/cmd/azure/services/aks.go +++ b/cmd/mapt/cmd/azure/services/aks.go @@ -93,7 +93,7 @@ func getDestroyAKS() *cobra.Command { return err } return azureAKS.Destroy(&maptContext.ContextArgs{ - Context: cmd.Context(), + Context: cmd.Context(), ProjectName: viper.GetString(params.ProjectName), BackedURL: viper.GetString(params.BackedURL), Debug: viper.IsSet(params.Debug), diff --git a/cmd/mapt/cmd/azure/services/kind.go b/cmd/mapt/cmd/azure/services/kind.go index 840b5254c..580e59e41 100644 --- a/cmd/mapt/cmd/azure/services/kind.go +++ b/cmd/mapt/cmd/azure/services/kind.go @@ -96,13 +96,13 @@ func destroyKind() *cobra.Command { return err } return kind.Destroy(&maptContext.ContextArgs{ - Context: cmd.Context(), - ProjectName: viper.GetString(params.ProjectName), - BackedURL: viper.GetString(params.BackedURL), - Debug: viper.IsSet(params.Debug), - DebugLevel: viper.GetUint(params.DebugLevel), - Serverless: viper.IsSet(params.Serverless), - ForceDestroy: viper.IsSet(params.ForceDestroy), + Context: cmd.Context(), + ProjectName: viper.GetString(params.ProjectName), + BackedURL: viper.GetString(params.BackedURL), + Debug: viper.IsSet(params.Debug), + DebugLevel: viper.GetUint(params.DebugLevel), + Serverless: viper.IsSet(params.Serverless), + ForceDestroy: viper.IsSet(params.ForceDestroy), }) }, } diff --git a/cmd/mapt/cmd/params/params.go b/cmd/mapt/cmd/params/params.go index 1dab0a39e..39f66ab81 100644 --- a/cmd/mapt/cmd/params/params.go +++ b/cmd/mapt/cmd/params/params.go @@ -3,6 +3,7 @@ package params import ( "github.com/redhat-developer/mapt/pkg/integrations/cirrus" "github.com/redhat-developer/mapt/pkg/integrations/github" + "github.com/redhat-developer/mapt/pkg/integrations/gitlab" cr "github.com/redhat-developer/mapt/pkg/provider/api/compute-request" spotTypes "github.com/redhat-developer/mapt/pkg/provider/api/spot" "github.com/redhat-developer/mapt/pkg/util" @@ -77,6 +78,16 @@ const ( cirrusPWLabels string = "it-cirrus-pw-labels" cirrusPWLabelsDesc string = "additional labels to use on the persistent worker (--it-cirrus-pw-labels key1=value1,key2=value2)" + glRunnerToken string = "glrunner-token" + glRunnerTokenDesc string = "GitLab Personal Access Token with api scope" + glRunnerProjectID string = "glrunner-project-id" + glRunnerProjectIDDesc string = "GitLab project ID for project runner registration" + glRunnerGroupID string = "glrunner-group-id" + glRunnerGroupIDDesc string = "GitLab group ID for group runner registration (alternative to --glrunner-project-id)" + glRunnerURL string = "glrunner-url" + glRunnerURLDesc string = "GitLab instance URL (e.g., https://gitlab.com, https://gitlab.example.com)" + glRunnerURLDefault string = "https://gitlab.com" + //RHEL SubsUsername string = "rh-subscription-username" SubsUsernameDesc string = "username to register the subscription" @@ -206,6 +217,13 @@ func AddCirrusFlags(fs *pflag.FlagSet) { fs.StringToStringP(cirrusPWLabels, "", nil, cirrusPWLabelsDesc) } +func AddGitLabRunnerFlags(fs *pflag.FlagSet) { + fs.StringP(glRunnerToken, "", "", glRunnerTokenDesc) + fs.StringP(glRunnerProjectID, "", "", glRunnerProjectIDDesc) + fs.StringP(glRunnerGroupID, "", "", glRunnerGroupIDDesc) + fs.StringP(glRunnerURL, "", glRunnerURLDefault, glRunnerURLDesc) +} + func CirrusPersistentWorkerArgs() *cirrus.PersistentWorkerArgs { if viper.IsSet(cirrusPWToken) { return &cirrus.PersistentWorkerArgs{ @@ -219,6 +237,20 @@ func CirrusPersistentWorkerArgs() *cirrus.PersistentWorkerArgs { return nil } +func GitLabRunnerArgs() *gitlab.GitLabRunnerArgs { + if viper.IsSet(glRunnerToken) { + return &gitlab.GitLabRunnerArgs{ + GitLabPAT: viper.GetString(glRunnerToken), + ProjectID: viper.GetString(glRunnerProjectID), + GroupID: viper.GetString(glRunnerGroupID), + URL: viper.GetString(glRunnerURL), + Platform: &gitlab.Linux, + Arch: linuxArchAsGitLabArch(viper.GetString(LinuxArch)), + } + } + return nil +} + func linuxArchAsCirrusArch(arch string) *cirrus.Arch { switch arch { case "x86_64": @@ -242,3 +274,19 @@ func MACArchAsCirrusArch(arch string) *cirrus.Arch { } return &cirrus.Arm64 } + +func linuxArchAsGitLabArch(arch string) *gitlab.Arch { + switch arch { + case "x86_64": + return &gitlab.Amd64 + } + return &gitlab.Arm64 +} + +func MACArchAsGitLabArch(arch string) *gitlab.Arch { + switch arch { + case "x86": + return &gitlab.Amd64 + } + return &gitlab.Arm64 +} diff --git a/cmd/mapt/cmd/root.go b/cmd/mapt/cmd/root.go index df90a8f91..9d9e399b4 100644 --- a/cmd/mapt/cmd/root.go +++ b/cmd/mapt/cmd/root.go @@ -3,17 +3,17 @@ package cmd import ( "context" "fmt" - "os" - "path/filepath" - "strings" - "os/signal" - "syscall" "github.com/redhat-developer/mapt/cmd/mapt/cmd/aws" "github.com/redhat-developer/mapt/cmd/mapt/cmd/azure" "github.com/redhat-developer/mapt/cmd/mapt/cmd/params" "github.com/redhat-developer/mapt/pkg/util/logging" "github.com/spf13/cobra" "github.com/spf13/pflag" + "os" + "os/signal" + "path/filepath" + "strings" + "syscall" ) const ( @@ -65,17 +65,17 @@ func init() { } func Execute() { - attachMiddleware([]string{}, rootCmd) + attachMiddleware([]string{}, rootCmd) - ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM) - defer stop() + ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM) + defer stop() - if err := rootCmd.ExecuteContext(ctx); err != nil { - runPostrun() - _, _ = fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(defaultErrorExitCode) - } - runPostrun() + if err := rootCmd.ExecuteContext(ctx); err != nil { + runPostrun() + _, _ = fmt.Fprintln(os.Stderr, err.Error()) + os.Exit(defaultErrorExitCode) + } + runPostrun() } func attachMiddleware(names []string, cmd *cobra.Command) { diff --git a/go.mod b/go.mod index 7910ec7db..3929ae639 100644 --- a/go.mod +++ b/go.mod @@ -33,6 +33,7 @@ require ( github.com/pulumi/pulumi-azure-native-sdk/network/v3 v3.12.1 github.com/pulumi/pulumi-azure-native-sdk/resources/v3 v3.12.1 github.com/pulumi/pulumi-azure-native-sdk/storage/v3 v3.12.1 + github.com/pulumi/pulumi-gitlab/sdk/v8 v8.11.0 github.com/pulumi/pulumi-tls/sdk/v5 v5.2.3 golang.org/x/exp v0.0.0-20251219203646-944ab1f22d93 ) diff --git a/go.sum b/go.sum index e8a73bc36..ac3479b43 100644 --- a/go.sum +++ b/go.sum @@ -328,6 +328,8 @@ github.com/pulumi/pulumi-docker-build/sdk/go/dockerbuild v0.0.15 h1:K6F/3o44gGj+ github.com/pulumi/pulumi-docker-build/sdk/go/dockerbuild v0.0.15/go.mod h1:cZyHs6q34kbQZJYaBjWUJhPsgwUFoL6xyjo7sRqBcv4= github.com/pulumi/pulumi-docker/sdk/v4 v4.11.0 h1:I8nJlJcQQiMs0njR1/CvXWk2y0dzhwSXIW62xuVaZQc= github.com/pulumi/pulumi-docker/sdk/v4 v4.11.0/go.mod h1:TbjBDNYFkMGmDZdrV6grRy+7AADkGLTcPjLHY9gh8dg= +github.com/pulumi/pulumi-gitlab/sdk/v8 v8.11.0 h1:nR406lhXeltZVfLXH8E4J5JetflNZePBgXz2eyHT7RM= +github.com/pulumi/pulumi-gitlab/sdk/v8 v8.11.0/go.mod h1:TU9R5gbZHqe1iJ054UW3ygPU8PxQcOi4J2n/YsnTviE= github.com/pulumi/pulumi-kubernetes/sdk/v4 v4.24.1 h1:L1J2/PHgAziDXUvOWJ4HH1JBlgxzpQseZiEIu4K2x34= github.com/pulumi/pulumi-kubernetes/sdk/v4 v4.24.1/go.mod h1:vNiMC/N8GNHvDwU3gQRXQ6V+kbgSl5N/lKtfrUjGuXU= github.com/pulumi/pulumi-random/sdk/v4 v4.18.5 h1:vNVS8u0VhNmxZDL7Qmr6gVff7zjVQeU+fFfAysfNgYc= diff --git a/pkg/integrations/gitlab/glrunner.go b/pkg/integrations/gitlab/glrunner.go new file mode 100644 index 000000000..07de3edab --- /dev/null +++ b/pkg/integrations/gitlab/glrunner.go @@ -0,0 +1,82 @@ +package gitlab + +import ( + _ "embed" + "fmt" + + "github.com/redhat-developer/mapt/pkg/integrations" + "github.com/redhat-developer/mapt/pkg/util" +) + +// Download URL +const runnerBaseURL = "https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-%s-%s" + +//go:embed snippet-darwin.sh +var snippetDarwin []byte + +//go:embed snippet-linux.sh +var snippetLinux []byte + +//go:embed snippet-windows.ps1 +var snippetWindows []byte + +var snippets map[Platform][]byte = map[Platform][]byte{ + Darwin: snippetDarwin, + Linux: snippetLinux, + Windows: snippetWindows, +} + +var runnerArgs *GitLabRunnerArgs + +func Init(args *GitLabRunnerArgs) { + runnerArgs = args +} + +func (args *GitLabRunnerArgs) GetUserDataValues() *integrations.UserDataValues { + if args == nil { + return nil + } + return &integrations.UserDataValues{ + Name: args.Name, + Token: args.AuthToken, // Use auth token (set by Pulumi during deployment) + CliURL: downloadURL(), + RepoURL: args.URL, + } +} + +func (args *GitLabRunnerArgs) GetSetupScriptTemplate() string { + templateConfig := string(snippets[*runnerArgs.Platform][:]) + return templateConfig +} + +func GetRunnerArgs() *GitLabRunnerArgs { + return runnerArgs +} + +// platform: darwin, linux, windows +// arch: amd64, arm64, arm +func downloadURL() string { + platform := string(*runnerArgs.Platform) + arch := string(*runnerArgs.Arch) + + url := fmt.Sprintf(runnerBaseURL, platform, arch) + if *runnerArgs.Platform == Windows { + url = fmt.Sprintf("%s.exe", url) + } + return url +} + +func GetToken() string { + var token = func() string { + return runnerArgs.AuthToken + } + return util.IfNillable(runnerArgs != nil, token, "") +} + +// SetAuthToken sets the authentication token in the global runner args. +// This is called during Pulumi deployment after the runner is created. +func SetAuthToken(token string) { + if runnerArgs != nil { + runnerArgs.AuthToken = token + } +} diff --git a/pkg/integrations/gitlab/pulumi.go b/pkg/integrations/gitlab/pulumi.go new file mode 100644 index 000000000..5608b2aff --- /dev/null +++ b/pkg/integrations/gitlab/pulumi.go @@ -0,0 +1,91 @@ +package gitlab + +import ( + "fmt" + "strconv" + + "github.com/pulumi/pulumi-gitlab/sdk/v8/go/gitlab" + "github.com/pulumi/pulumi/sdk/v3/go/pulumi" + "github.com/redhat-developer/mapt/pkg/util/logging" +) + +// CreateRunner creates a GitLab UserRunner via Pulumi and returns auth token. +// This function should be called during Pulumi stack deployment (inside deploy() functions). +// Supports both project runners (with ProjectID) and group runners (with GroupID). +func CreateRunner(ctx *pulumi.Context, args *GitLabRunnerArgs) (pulumi.StringOutput, error) { + // Determine runner type based on which ID is provided + var runnerType string + var runnerArgs *gitlab.UserRunnerArgs + + if args.ProjectID != "" && args.GroupID != "" { + return pulumi.StringOutput{}, fmt.Errorf("cannot specify both ProjectID and GroupID - use only one") + } + + if args.ProjectID != "" { + // Project runner + runnerType = "project_type" + projectID, err := strconv.Atoi(args.ProjectID) + if err != nil { + logging.Error(fmt.Sprintf("Failed to convert ProjectID '%s' to int: %v", args.ProjectID, err)) + return pulumi.StringOutput{}, err + } + logging.Debug(fmt.Sprintf("Creating GitLab project runner: URL=%s, ProjectID=%d, Name=%s", + args.URL, projectID, args.Name)) + + runnerArgs = &gitlab.UserRunnerArgs{ + RunnerType: pulumi.String(runnerType), + ProjectId: pulumi.Int(projectID), + Description: pulumi.String(args.Name), + TagLists: pulumi.StringArray{}, + Untagged: pulumi.Bool(true), + Locked: pulumi.Bool(false), + AccessLevel: pulumi.String("not_protected"), + } + } else if args.GroupID != "" { + // Group runner + runnerType = "group_type" + groupID, err := strconv.Atoi(args.GroupID) + if err != nil { + logging.Error(fmt.Sprintf("Failed to convert GroupID '%s' to int: %v", args.GroupID, err)) + return pulumi.StringOutput{}, err + } + logging.Debug(fmt.Sprintf("Creating GitLab group runner: URL=%s, GroupID=%d, Name=%s", + args.URL, groupID, args.Name)) + + runnerArgs = &gitlab.UserRunnerArgs{ + RunnerType: pulumi.String(runnerType), + GroupId: pulumi.Int(groupID), + Description: pulumi.String(args.Name), + TagLists: pulumi.StringArray{}, + Untagged: pulumi.Bool(true), + Locked: pulumi.Bool(false), + AccessLevel: pulumi.String("not_protected"), + } + } else { + return pulumi.StringOutput{}, fmt.Errorf("must specify either ProjectID or GroupID") + } + + // Configure GitLab provider with PAT + provider, err := gitlab.NewProvider(ctx, "gitlab-provider", &gitlab.ProviderArgs{ + Token: pulumi.String(args.GitLabPAT), + BaseUrl: pulumi.String(args.URL), + }) + if err != nil { + return pulumi.StringOutput{}, err + } + + // Create UserRunner resource + // This creates the runner in GitLab and returns an authentication token + runner, err := gitlab.NewUserRunner(ctx, "gitlab-runner", runnerArgs, pulumi.Provider(provider)) + if err != nil { + return pulumi.StringOutput{}, err + } + + // Export runner ID for reference + ctx.Export("gitlab-runner-id", runner.ID()) + ctx.Export("gitlab-runner-type", pulumi.String(runnerType)) + + // Return the authentication token as a Pulumi output + // This will be used with ApplyT to pass to userdata generation + return runner.Token, nil +} diff --git a/pkg/integrations/gitlab/snippet-darwin.sh b/pkg/integrations/gitlab/snippet-darwin.sh new file mode 100644 index 000000000..ff64d9f05 --- /dev/null +++ b/pkg/integrations/gitlab/snippet-darwin.sh @@ -0,0 +1,15 @@ +#!/bin/bash +# Download GitLab Runner +sudo curl -L -o /usr/local/bin/gitlab-runner "{{ .CliURL }}" +sudo chmod +x /usr/local/bin/gitlab-runner + +# Register runner +sudo gitlab-runner register \ + --non-interactive \ + --url "{{ .RepoURL }}" \ + --token "{{ .Token }}" \ + --executor "shell" + +# Install and start as LaunchDaemon +sudo gitlab-runner install +sudo gitlab-runner start diff --git a/pkg/integrations/gitlab/snippet-linux.sh b/pkg/integrations/gitlab/snippet-linux.sh new file mode 100644 index 000000000..c25b4d711 --- /dev/null +++ b/pkg/integrations/gitlab/snippet-linux.sh @@ -0,0 +1,24 @@ +#!/bin/bash +set -e + +# Download GitLab Runner +curl -L -o /tmp/gitlab-runner "{{ .CliURL }}" +chmod +x /tmp/gitlab-runner + +# Move to trusted path +sudo mv /tmp/gitlab-runner /usr/bin/gitlab-runner + +# Fix SELinux context +sudo restorecon -v /usr/bin/gitlab-runner + +# Register runner +sudo gitlab-runner register \ + --non-interactive \ + --url "{{ .RepoURL }}" \ + --token "{{ .Token }}" \ + --executor "shell" + +# Install and start as service +sudo gitlab-runner install --user={{ .User }} +sudo systemctl daemon-reload +sudo systemctl enable --now gitlab-runner diff --git a/pkg/integrations/gitlab/snippet-windows.ps1 b/pkg/integrations/gitlab/snippet-windows.ps1 new file mode 100644 index 000000000..2013c1bee --- /dev/null +++ b/pkg/integrations/gitlab/snippet-windows.ps1 @@ -0,0 +1,14 @@ +# Download GitLab Runner +New-Item -Path C:\GitLab-Runner -ItemType Directory -Force +Invoke-WebRequest -Uri "{{ .CliURL }}" -OutFile C:\GitLab-Runner\gitlab-runner.exe + +# Register runner +C:\GitLab-Runner\gitlab-runner.exe register ` + --non-interactive ` + --url "{{ .RepoURL }}" ` + --token "{{ .Token }}" ` + --executor "shell" + +# Install and start as Windows service +C:\GitLab-Runner\gitlab-runner.exe install +C:\GitLab-Runner\gitlab-runner.exe start diff --git a/pkg/integrations/gitlab/types.go b/pkg/integrations/gitlab/types.go new file mode 100644 index 000000000..c7b08c042 --- /dev/null +++ b/pkg/integrations/gitlab/types.go @@ -0,0 +1,26 @@ +package gitlab + +type Platform string +type Arch string + +var ( + Windows Platform = "windows" + Linux Platform = "linux" + Darwin Platform = "darwin" + + Arm64 Arch = "arm64" + Amd64 Arch = "amd64" + Arm Arch = "arm" +) + +type GitLabRunnerArgs struct { + GitLabPAT string // Personal Access Token for Pulumi GitLab provider (input) + ProjectID string // GitLab project ID for project runner registration (mutually exclusive with GroupID) + GroupID string // GitLab group ID for group runner registration (mutually exclusive with ProjectID) + URL string // GitLab instance URL (e.g., https://gitlab.com) + Name string // Runner name/description (auto-generated from run ID) + Platform *Platform // Target platform + Arch *Arch // Target architecture + User string // OS user to run as + AuthToken string // Runner authentication token (set by Pulumi during deployment) +} diff --git a/pkg/integrations/integrations.go b/pkg/integrations/integrations.go index 960ce8dec..4252f3318 100644 --- a/pkg/integrations/integrations.go +++ b/pkg/integrations/integrations.go @@ -8,13 +8,14 @@ import ( ) type UserDataValues struct { - CliURL string - User string - Name string - Token string - Labels string - Port string - RepoURL string + CliURL string + User string + Name string + Token string + Labels string + Port string + RepoURL string + Executor string } type IntegrationConfig interface { diff --git a/pkg/manager/context/context.go b/pkg/manager/context/context.go index 86f38dcca..bb74bb301 100644 --- a/pkg/manager/context/context.go +++ b/pkg/manager/context/context.go @@ -9,6 +9,7 @@ import ( "github.com/pulumi/pulumi/sdk/v3/go/pulumi" "github.com/redhat-developer/mapt/pkg/integrations/cirrus" "github.com/redhat-developer/mapt/pkg/integrations/github" + "github.com/redhat-developer/mapt/pkg/integrations/gitlab" "github.com/redhat-developer/mapt/pkg/util" "github.com/redhat-developer/mapt/pkg/util/logging" utilMaps "github.com/redhat-developer/mapt/pkg/util/maps" @@ -50,6 +51,7 @@ type ContextArgs struct { // integrations GHRunnerArgs *github.GithubRunnerArgs CirrusPWArgs *cirrus.PersistentWorkerArgs + GLRunnerArgs *gitlab.GitLabRunnerArgs } type Context struct { @@ -184,5 +186,9 @@ func manageIntegration(c *Context, ca *ContextArgs) error { ca.CirrusPWArgs.Name = c.RunID() cirrus.Init(ca.CirrusPWArgs) } + if ca.GLRunnerArgs != nil { + ca.GLRunnerArgs.Name = c.RunID() + gitlab.Init(ca.GLRunnerArgs) + } return nil } diff --git a/pkg/provider/aws/action/fedora/fedora.go b/pkg/provider/aws/action/fedora/fedora.go index 264d79c02..f34ed72a0 100644 --- a/pkg/provider/aws/action/fedora/fedora.go +++ b/pkg/provider/aws/action/fedora/fedora.go @@ -8,6 +8,7 @@ import ( "github.com/pulumi/pulumi/sdk/v3/go/auto" "github.com/pulumi/pulumi/sdk/v3/go/pulumi" "github.com/redhat-developer/mapt/pkg/integrations/cirrus" + "github.com/redhat-developer/mapt/pkg/integrations/gitlab" "github.com/redhat-developer/mapt/pkg/manager" mc "github.com/redhat-developer/mapt/pkg/manager/context" infra "github.com/redhat-developer/mapt/pkg/provider" @@ -215,10 +216,30 @@ func (r *fedoraRequest) deploy(ctx *pulumi.Context) error { if err != nil { return err } - userDataB64, err := fedoraCloudConfig.Userdata(amiUserDefault) - if err != nil { - return err + + // Generate userdata - if GitLab runner args present, create runner via Pulumi first + var userDataB64 pulumi.StringPtrInput + glRunnerArgs := gitlab.GetRunnerArgs() + if glRunnerArgs != nil { + glRunnerArgs.Name = r.mCtx.RunID() + + authToken, err := gitlab.CreateRunner(ctx, glRunnerArgs) + if err != nil { + return err + } + + // Generate userdata with auth token using ApplyT + userDataB64 = authToken.ApplyT(func(token string) (string, error) { + return fedoraCloudConfig.UserdataWithGitLabToken(amiUserDefault, token) + }).(pulumi.StringOutput) + } else { + // No GitLab runner, use normal userdata + userDataB64, err = fedoraCloudConfig.Userdata(amiUserDefault) + if err != nil { + return err + } } + cr := compute.ComputeRequest{ MCtx: r.mCtx, Prefix: *r.prefix, diff --git a/pkg/provider/aws/action/openshift-snc/constants.go b/pkg/provider/aws/action/openshift-snc/constants.go index 3fc4f697c..efce5abc7 100644 --- a/pkg/provider/aws/action/openshift-snc/constants.go +++ b/pkg/provider/aws/action/openshift-snc/constants.go @@ -25,7 +25,7 @@ var ( outputKubeAdminPass = "aosKubeAdminPasss" outputDeveloperPass = "aosDeveloperPass" - commandCrcReadiness = "while [ ! -f /tmp/.crc-cluster-ready ]; do sleep 5; done" + commandCrcReadiness = "while [ ! -f /tmp/.crc-cluster-ready ]; do sleep 5; done" commandCaServiceRan = "sudo bash -c 'until oc get node --kubeconfig /opt/kubeconfig --context system:admin || oc get node --kubeconfig /opt/crc/kubeconfig --context system:admin; do sleep 5; done'" // portHTTP = 80 diff --git a/pkg/provider/aws/action/openshift-snc/openshift-snc.go b/pkg/provider/aws/action/openshift-snc/openshift-snc.go index b5306d333..e9b7ec58f 100644 --- a/pkg/provider/aws/action/openshift-snc/openshift-snc.go +++ b/pkg/provider/aws/action/openshift-snc/openshift-snc.go @@ -28,11 +28,11 @@ import ( "github.com/redhat-developer/mapt/pkg/provider/aws/services/ec2/keypair" securityGroup "github.com/redhat-developer/mapt/pkg/provider/aws/services/ec2/security-group" "github.com/redhat-developer/mapt/pkg/provider/aws/services/ssm" + "github.com/redhat-developer/mapt/pkg/provider/util/command" "github.com/redhat-developer/mapt/pkg/provider/util/output" "github.com/redhat-developer/mapt/pkg/provider/util/security" "github.com/redhat-developer/mapt/pkg/util" "github.com/redhat-developer/mapt/pkg/util/logging" - "github.com/redhat-developer/mapt/pkg/provider/util/command" resourcesUtil "github.com/redhat-developer/mapt/pkg/util/resources" ) diff --git a/pkg/provider/aws/aws.go b/pkg/provider/aws/aws.go index 3a87c096f..dbe88bbff 100644 --- a/pkg/provider/aws/aws.go +++ b/pkg/provider/aws/aws.go @@ -234,7 +234,7 @@ func CleanupState(mCtx *mc.Context) error { } logging.Infof("Cleaning up Pulumi state from s3://%s/%s", *bucket, *key) - if deleteErr := s3.Delete(mCtx.Context() , bucket, key); deleteErr != nil { + if deleteErr := s3.Delete(mCtx.Context(), bucket, key); deleteErr != nil { logging.Warnf("Failed to cleanup S3 state: %v", deleteErr) // Don't return error - resources are already destroyed } else { diff --git a/pkg/provider/aws/data/azs.go b/pkg/provider/aws/data/azs.go index ceab2230a..8e9a95291 100644 --- a/pkg/provider/aws/data/azs.go +++ b/pkg/provider/aws/data/azs.go @@ -78,7 +78,7 @@ func describeAvailabilityZones(ctx context.Context, regionName string, excludedZ if err != nil { return nil, err } - + // Filter out excluded zone-ids if provided if len(excludedZoneIDs) > 0 { filteredAZs := slices.DeleteFunc(resultAZs.AvailabilityZones, func(az ec2Types.AvailabilityZone) bool { @@ -86,7 +86,7 @@ func describeAvailabilityZones(ctx context.Context, regionName string, excludedZ }) return filteredAZs, nil } - + return resultAZs.AvailabilityZones, nil } diff --git a/pkg/provider/aws/modules/ami/stack.go b/pkg/provider/aws/modules/ami/stack.go index 16a2cb788..917259f80 100644 --- a/pkg/provider/aws/modules/ami/stack.go +++ b/pkg/provider/aws/modules/ami/stack.go @@ -40,7 +40,7 @@ func (r CopyAMIRequest) Create() error { if err := r.validate(); err != nil { return err } - _, err := manager.CheckStack(r.MCtx,manager.Stack{ + _, err := manager.CheckStack(r.MCtx, manager.Stack{ StackName: r.MCtx.StackNameByProject("copyAMI"), ProjectName: r.MCtx.ProjectName(), BackedURL: r.MCtx.BackedURL()}) diff --git a/pkg/provider/azure/action/windows/rhqp-ci-setup.ps1 b/pkg/provider/azure/action/windows/rhqp-ci-setup.ps1 index f78331dfd..a4db4f932 100644 --- a/pkg/provider/azure/action/windows/rhqp-ci-setup.ps1 +++ b/pkg/provider/azure/action/windows/rhqp-ci-setup.ps1 @@ -11,6 +11,8 @@ param( $ghToken, [Parameter(HelpMessage='token for the cirrus persistent worker')] $cirrusToken, + [Parameter(HelpMessage='token for the gitlab runner')] + $gitlabToken, [switch]$crcProfile=$false ) # Create local user @@ -134,6 +136,8 @@ if ($crcProfile) { {{ .CirrusSnippet }} +{{ .GitLabSnippet }} + # Restart computer to have the ssh connection available with setup from this script Start-Process powershell -verb runas -ArgumentList "Restart-Computer -Force" diff --git a/pkg/provider/azure/action/windows/windows.go b/pkg/provider/azure/action/windows/windows.go index 3bfb09949..0ded5fb21 100644 --- a/pkg/provider/azure/action/windows/windows.go +++ b/pkg/provider/azure/action/windows/windows.go @@ -16,6 +16,7 @@ import ( "github.com/redhat-developer/mapt/pkg/integrations" "github.com/redhat-developer/mapt/pkg/integrations/cirrus" "github.com/redhat-developer/mapt/pkg/integrations/github" + "github.com/redhat-developer/mapt/pkg/integrations/gitlab" "github.com/redhat-developer/mapt/pkg/manager" mc "github.com/redhat-developer/mapt/pkg/manager/context" infra "github.com/redhat-developer/mapt/pkg/provider" @@ -74,6 +75,7 @@ func (r *windowsRequest) validate() error { type ghActionsRunnerData struct { ActionsRunnerSnippet string CirrusSnippet string + GitLabSnippet string } func Create(mCtxArgs *mc.ContextArgs, args *WindowsArgs) (err error) { @@ -291,7 +293,7 @@ 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 -ghToken \"%s\" -cirrusToken \"%s\" -authorizedKey \"%s\"", + "powershell -ExecutionPolicy Unrestricted -File %s %s -userPass \"%s\" -user %s -hostname %s -ghToken \"%s\" -cirrusToken \"%s\" -gitlabToken \"%s\" -authorizedKey \"%s\"", scriptName, r.profilesAsParams(), password, @@ -299,6 +301,7 @@ func (r *windowsRequest) postInitSetup(ctx *pulumi.Context, rg *resources.Resour *hostname, github.GetToken(), cirrus.GetToken(), + gitlab.GetToken(), authorizedKey, ) }).(pulumi.StringOutput) @@ -366,11 +369,16 @@ func (r *windowsRequest) uploadScript(ctx *pulumi.Context, if err != nil { return nil, err } + gitlabSnippet, err := integrations.GetIntegrationSnippet(gitlab.GetRunnerArgs(), *r.username) + if err != nil { + return nil, err + } logging.Debug("got the self hosted runner script") ciSetupScript, err := file.Template( ghActionsRunnerData{ *ghActionsRunnerSnippet, *cirrusSnippet, + *gitlabSnippet, }, string(RHQPCISetupScript)) if err != nil { diff --git a/pkg/provider/azure/data/compute-request.go b/pkg/provider/azure/data/compute-request.go index 805b0a5e8..0b50e61a9 100644 --- a/pkg/provider/azure/data/compute-request.go +++ b/pkg/provider/azure/data/compute-request.go @@ -30,7 +30,7 @@ type ComputeSelector struct{} func NewComputeSelector() *ComputeSelector { return &ComputeSelector{} } func (c *ComputeSelector) Select(ctx context.Context, args *cr.ComputeRequestArgs) ([]string, error) { - return getAzureVMSKUs(ctx, args) + return getAzureVMSKUs(ctx, args) } func FilterComputeSizesByLocation(ctx context.Context, location *string, computeSizes []string) ([]string, error) { diff --git a/pkg/provider/util/cloud-config/fedora/cloud-config b/pkg/provider/util/cloud-config/fedora/cloud-config index e1ce10983..68c5f8875 100644 --- a/pkg/provider/util/cloud-config/fedora/cloud-config +++ b/pkg/provider/util/cloud-config/fedora/cloud-config @@ -13,6 +13,7 @@ runcmd: - dnf install -y podman {{ if .ActionsRunnerSnippet }} - sudo -u {{ .Username }} bash -c /opt/install-ghrunner.sh{{ end }} {{ if .CirrusSnippet }} - /opt/setup-cirrus-service.sh{{ end }} +{{ if .GitLabSnippet }} - sudo -u {{ .Username }} bash -c /opt/install-glrunner.sh{{ end }} {{ if .ActionsRunnerSnippet }}write_files: - content: | {{ .ActionsRunnerSnippet }} @@ -25,3 +26,9 @@ runcmd: path: /opt/setup-cirrus-service.sh permissions: '0755' {{ end }} +{{ if .GitLabSnippet }}write_files: + - content: | +{{.GitLabSnippet}} + path: /opt/install-glrunner.sh + permissions: '0755' +{{ end }} diff --git a/pkg/provider/util/cloud-config/fedora/fedora.go b/pkg/provider/util/cloud-config/fedora/fedora.go index b326d4da5..315420160 100644 --- a/pkg/provider/util/cloud-config/fedora/fedora.go +++ b/pkg/provider/util/cloud-config/fedora/fedora.go @@ -8,6 +8,7 @@ import ( "github.com/redhat-developer/mapt/pkg/integrations" "github.com/redhat-developer/mapt/pkg/integrations/cirrus" "github.com/redhat-developer/mapt/pkg/integrations/github" + "github.com/redhat-developer/mapt/pkg/integrations/gitlab" "github.com/redhat-developer/mapt/pkg/util/file" ) @@ -15,6 +16,7 @@ type userDataValues struct { Username string ActionsRunnerSnippet string CirrusSnippet string + GitLabSnippet string } //go:embed cloud-config @@ -29,13 +31,54 @@ func Userdata(amiUser string) (pulumi.StringPtrInput, error) { if err != nil { return nil, err } + gitlabSnippet, err := integrations.GetIntegrationSnippetAsCloudInitWritableFile(gitlab.GetRunnerArgs(), amiUser) + if err != nil { + return nil, err + } templateConfig := string(CloudConfig[:]) userdata, err := file.Template( userDataValues{ amiUser, *ghActionsRunnerSnippet, - *cirrusSnippet}, + *cirrusSnippet, + *gitlabSnippet}, templateConfig) return pulumi.String(base64.StdEncoding.EncodeToString([]byte(userdata))), err } + +// UserdataWithGitLabToken generates userdata with the GitLab auth token set. +// This is used when the token is obtained asynchronously via Pulumi ApplyT. +func UserdataWithGitLabToken(amiUser string, gitlabAuthToken string) (string, error) { + // Set auth token in global state temporarily + gitlab.SetAuthToken(gitlabAuthToken) + defer gitlab.SetAuthToken("") // Clear after use + + // Generate userdata as normal + cirrusSnippet, err := integrations.GetIntegrationSnippetAsCloudInitWritableFile(cirrus.GetRunnerArgs(), amiUser) + if err != nil { + return "", err + } + ghActionsRunnerSnippet, err := integrations.GetIntegrationSnippetAsCloudInitWritableFile(github.GetRunnerArgs(), amiUser) + if err != nil { + return "", err + } + gitlabSnippet, err := integrations.GetIntegrationSnippetAsCloudInitWritableFile(gitlab.GetRunnerArgs(), amiUser) + if err != nil { + return "", err + } + + templateConfig := string(CloudConfig[:]) + userdata, err := file.Template( + userDataValues{ + amiUser, + *ghActionsRunnerSnippet, + *cirrusSnippet, + *gitlabSnippet}, + templateConfig) + if err != nil { + return "", err + } + + return base64.StdEncoding.EncodeToString([]byte(userdata)), nil +} diff --git a/pkg/provider/util/cloud-config/windows-server/bootstrap.ps1 b/pkg/provider/util/cloud-config/windows-server/bootstrap.ps1 index d30c8194e..894431da3 100644 --- a/pkg/provider/util/cloud-config/windows-server/bootstrap.ps1 +++ b/pkg/provider/util/cloud-config/windows-server/bootstrap.ps1 @@ -29,6 +29,11 @@ $cirrusToken = {{ .CirrusToken }} {{ .CirrusSnippet }} {{ end }} +{{ if .GitLabSnippet }} +$gitlabToken = {{ .GitLabToken }} +{{ .GitLabSnippet }} +{{ end }} + netsh advfirewall firewall add rule name="Open SSH Port 22" dir=in action=allow protocol=TCP localport=22 remoteip=any # Restart computer to have the ssh connection available with setup from this script Start-Process powershell -verb runas -ArgumentList "Restart-Computer -Force" diff --git a/pkg/provider/util/cloud-config/windows-server/windows-server.go b/pkg/provider/util/cloud-config/windows-server/windows-server.go index c5550e05a..0b609170f 100644 --- a/pkg/provider/util/cloud-config/windows-server/windows-server.go +++ b/pkg/provider/util/cloud-config/windows-server/windows-server.go @@ -9,6 +9,7 @@ import ( "github.com/redhat-developer/mapt/pkg/integrations" "github.com/redhat-developer/mapt/pkg/integrations/cirrus" "github.com/redhat-developer/mapt/pkg/integrations/github" + "github.com/redhat-developer/mapt/pkg/integrations/gitlab" "github.com/redhat-developer/mapt/pkg/provider/aws/services/ec2/keypair" "github.com/redhat-developer/mapt/pkg/util/file" ) @@ -21,6 +22,8 @@ type userDataValues struct { RunnerToken string CirrusSnippet string CirrusToken string + GitLabSnippet string + GitLabToken string } //go:embed bootstrap.ps1 @@ -41,6 +44,10 @@ func Userdata(ctx *pulumi.Context, amiUser *string, password *random.RandomPassw if err != nil { return "", err } + gitlabSnippet, err := integrations.GetIntegrationSnippet(gitlab.GetRunnerArgs(), *amiUser) + if err != nil { + return "", err + } udv := userDataValues{ *amiUser, password, @@ -49,6 +56,8 @@ func Userdata(ctx *pulumi.Context, amiUser *string, password *random.RandomPassw github.GetToken(), *cirrusSnippet, cirrus.GetToken(), + *gitlabSnippet, + gitlab.GetToken(), } userdata, err := file.Template(udv, string(BootstrapScript[:])) if err != nil { diff --git a/pkg/targets/host/rhel/cloud-config-base b/pkg/targets/host/rhel/cloud-config-base index 23a36d959..2db674814 100644 --- a/pkg/targets/host/rhel/cloud-config-base +++ b/pkg/targets/host/rhel/cloud-config-base @@ -8,6 +8,7 @@ runcmd: - dnf install -y podman {{ if .ActionsRunnerSnippet }} - sudo -u {{ .Username }} bash -c /opt/install-ghrunner.sh{{ end }} {{ if .CirrusSnippet }} - /opt/setup-cirrus-service.sh{{ end }} +{{ if .GitLabSnippet }} - sudo -u {{ .Username }} bash -c /opt/install-glrunner.sh{{ end }} {{ if .ActionsRunnerSnippet }}write_files: # Github actions runner installation - content: | @@ -21,3 +22,9 @@ runcmd: path: /opt/setup-cirrus-service.sh permissions: '0755' {{ end }} +{{ if .GitLabSnippet }}write_files: + - content: | +{{.GitLabSnippet}} + path: /opt/install-glrunner.sh + permissions: '0755' +{{ end }} diff --git a/pkg/targets/host/rhel/cloud-config-snc b/pkg/targets/host/rhel/cloud-config-snc index 7027e4931..fc64b8672 100644 --- a/pkg/targets/host/rhel/cloud-config-snc +++ b/pkg/targets/host/rhel/cloud-config-snc @@ -19,6 +19,7 @@ runcmd: - sysctl -p /etc/sysctl.d/userns.conf {{ if .ActionsRunnerSnippet }} - sudo -u {{ .Username }} bash -c /opt/install-ghrunner.sh {{ end }} {{ if .CirrusSnippet }} - /opt/setup-cirrus-service.sh{{ end }} +{{ if .GitLabSnippet }} - sudo -u {{ .Username }} bash -c /opt/install-glrunner.sh{{ end }} {{ if .ActionsRunnerSnippet }}write_files: # Github actions runner installation - content: | @@ -32,3 +33,9 @@ runcmd: path: /opt/setup-cirrus-service.sh permissions: '0755' {{ end }} +{{ if .GitLabSnippet }}write_files: + - content: | +{{.GitLabSnippet}} + path: /opt/install-glrunner.sh + permissions: '0755' +{{ end }} diff --git a/pkg/targets/host/rhel/cloud-config.go b/pkg/targets/host/rhel/cloud-config.go index f4003dfc7..edbaabadb 100644 --- a/pkg/targets/host/rhel/cloud-config.go +++ b/pkg/targets/host/rhel/cloud-config.go @@ -7,6 +7,7 @@ import ( "github.com/redhat-developer/mapt/pkg/integrations" "github.com/redhat-developer/mapt/pkg/integrations/cirrus" "github.com/redhat-developer/mapt/pkg/integrations/github" + "github.com/redhat-developer/mapt/pkg/integrations/gitlab" "github.com/redhat-developer/mapt/pkg/util/file" ) @@ -22,6 +23,7 @@ type userDataValues struct { Username string ActionsRunnerSnippet string CirrusSnippet string + GitLabSnippet string } //go:embed cloud-config-base @@ -43,13 +45,18 @@ func (r *CloudConfigArgs) CloudConfig() (*string, error) { if err != nil { return nil, err } + gitlabSnippet, err := integrations.GetIntegrationSnippetAsCloudInitWritableFile(gitlab.GetRunnerArgs(), r.Username) + if err != nil { + return nil, err + } userdata, err := file.Template( userDataValues{ r.SubsUsername, r.SubsPassword, r.Username, *ghActionsRunnerSnippet, - *cirrusSnippet}, + *cirrusSnippet, + *gitlabSnippet}, templateConfig) if err != nil { return nil, err