Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add github actions runner setup for all platforms #241

Merged
merged 10 commits into from
Jul 16, 2024
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
out/
.run*
manifest.json
ami-id
ami-id
Pulumi*.yaml
13 changes: 7 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ TKN_IMG ?= quay.io/redhat-developer/mapt:v${VERSION}-tkn
# Go and compilation related variables
GOPATH ?= $(shell go env GOPATH)
BUILD_DIR ?= out
SOURCE_DIRS = cmd pkg test
SOURCE_DIRS = cmd pkg
SOURCES := $(shell find . -name "*.go" -not -path "./vendor/*")
# https://golang.org/cmd/link/
# LDFLAGS := $(VERSION_VARIABLES) -extldflags='-static' ${GO_EXTRA_LDFLAGS}
LDFLAGS := $(VERSION_VARIABLES) ${GO_EXTRA_LDFLAGS}
GCFLAGS := all=-N -l
GCFLAGS := all=-N -l

TOOLS_DIR := tools
include tools/tools.mk
Expand All @@ -33,12 +34,12 @@ check: build test lint

.PHONY: install
install: $(SOURCES)
go install -ldflags="$(LDFLAGS)" $(GO_EXTRA_BUILDFLAGS) ./cmd
go install -ldflags="$(LDFLAGS)" $(GO_EXTRA_BUILDFLAGS) ./cmd/mapt

$(BUILD_DIR)/mapt: $(SOURCES)
GOOS=linux GOARCH=amd64 go build -gcflags="$(GCFLAGS)" -ldflags="$(LDFLAGS)" -o $(BUILD_DIR)/mapt $(GO_EXTRA_BUILDFLAGS) ./cmd
GOOS=linux GOARCH=amd64 go build -gcflags="$(GCFLAGS)" -ldflags="$(LDFLAGS)" -o $(BUILD_DIR)/mapt $(GO_EXTRA_BUILDFLAGS) ./cmd/mapt

.PHONY: build
.PHONY: build
build: $(BUILD_DIR)/mapt

.PHONY: test
Expand Down Expand Up @@ -77,4 +78,4 @@ tkn-push: install-out-of-tree-tools
-f tkn/infra-aws-mac.yaml \
-f tkn/infra-aws-rhel.yaml \
-f tkn/infra-aws-windows-server.yaml \
-f tkn/infra-azure-windows-desktop.yaml
-f tkn/infra-azure-windows-desktop.yaml
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,19 @@ Features:
* a airgap
* s spot
* p proxy
* v vpn
* v vpn

## Github Self hosted runner

`mapt` can setup a deployed machine as a Self Hosted runner on most of the Platform and Provider combinations
it supports.

Use the following flags with `mapt <provider> <platform> create` command:

```
--install-ghactions-runner <bool> Install and setup Github Actions runner in the instance
--ghactions-runner-name <string> Name for the Github Actions Runner
--ghactions-runner-repo <string> Full URL of the repository where the Github Actions Runner should be registered
--ghactions-runner-token <string> Token needed for registering the Github Actions Runner token
```

7 changes: 0 additions & 7 deletions cmd/main.go

This file was deleted.

2 changes: 1 addition & 1 deletion cmd/cmd/aws/aws.go → cmd/mapt/cmd/aws/aws.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package aws

import (
"github.com/redhat-developer/mapt/cmd/cmd/aws/hosts"
"github.com/redhat-developer/mapt/cmd/mapt/cmd/aws/hosts"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package hosts

import (
params "github.com/redhat-developer/mapt/cmd/cmd/constants"
params "github.com/redhat-developer/mapt/cmd/mapt/cmd/constants"
maptContext "github.com/redhat-developer/mapt/pkg/manager/context"
"github.com/redhat-developer/mapt/pkg/provider/aws/action/fedora"
"github.com/redhat-developer/mapt/pkg/util/logging"
Expand Down
2 changes: 1 addition & 1 deletion cmd/cmd/aws/hosts/mac.go → cmd/mapt/cmd/aws/hosts/mac.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package hosts

import (
params "github.com/redhat-developer/mapt/cmd/cmd/constants"
params "github.com/redhat-developer/mapt/cmd/mapt/cmd/constants"
maptContext "github.com/redhat-developer/mapt/pkg/manager/context"
"github.com/redhat-developer/mapt/pkg/provider/aws/action/mac"
"github.com/redhat-developer/mapt/pkg/util/logging"
Expand Down
34 changes: 24 additions & 10 deletions cmd/cmd/aws/hosts/rhel.go → cmd/mapt/cmd/aws/hosts/rhel.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package hosts

import (
params "github.com/redhat-developer/mapt/cmd/cmd/constants"
params "github.com/redhat-developer/mapt/cmd/mapt/cmd/constants"
maptContext "github.com/redhat-developer/mapt/pkg/manager/context"
"github.com/redhat-developer/mapt/pkg/provider/aws/action/rhel"
"github.com/redhat-developer/mapt/pkg/util/ghactions"
"github.com/redhat-developer/mapt/pkg/util/logging"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
Expand Down Expand Up @@ -61,18 +62,30 @@ func getRHELCreate() *cobra.Command {
viper.GetString(params.ConnectionDetailsOutput),
viper.GetStringMapString(params.Tags))

// Initialize gh actions runner if needed
if viper.IsSet(params.InstallGHActionsRunner) {
err := ghactions.InitGHRunnerArgs(viper.GetString(params.GHActionsRunnerToken),
viper.GetString(params.GHActionsRunnerName),
viper.GetString(params.GHActionsRunnerRepo))
if err != nil {
logging.Error(err)
}
}

// Run create
if err := rhel.Create(
&rhel.Request{
Prefix: "main",
Version: viper.GetString(rhelVersion),
Arch: viper.GetString(rhelArch),
VMType: viper.GetStringSlice(vmTypes),
SubsUsername: viper.GetString(subsUsername),
SubsUserpass: viper.GetString(subsUserpass),
ProfileSNC: viper.IsSet(profileSNC),
Spot: viper.IsSet(spot),
Airgap: viper.IsSet(airgap)}); err != nil {
Prefix: "main",
Version: viper.GetString(rhelVersion),
Arch: viper.GetString(rhelArch),
VMType: viper.GetStringSlice(vmTypes),
SubsUsername: viper.GetString(subsUsername),
SubsUserpass: viper.GetString(subsUserpass),
ProfileSNC: viper.IsSet(profileSNC),
Spot: viper.IsSet(spot),
Airgap: viper.IsSet(airgap),
SetupGHActionsRunner: viper.GetBool(params.InstallGHActionsRunner),
}); err != nil {
logging.Error(err)
}
return nil
Expand All @@ -89,6 +102,7 @@ func getRHELCreate() *cobra.Command {
flagSet.Bool(airgap, false, airgapDesc)
flagSet.Bool(spot, false, spotDesc)
flagSet.Bool(profileSNC, false, profileSNCDesc)
flagSet.AddFlagSet(params.GetGHActionsFlagset())
c.PersistentFlags().AddFlagSet(flagSet)
// if err := c.MarkFlagRequired(subsUsername); err != nil {
// logging.Error(err)
Expand Down
32 changes: 23 additions & 9 deletions cmd/cmd/aws/hosts/windows.go → cmd/mapt/cmd/aws/hosts/windows.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package hosts

import (
params "github.com/redhat-developer/mapt/cmd/cmd/constants"
params "github.com/redhat-developer/mapt/cmd/mapt/cmd/constants"
maptContext "github.com/redhat-developer/mapt/pkg/manager/context"
"github.com/redhat-developer/mapt/pkg/provider/aws/action/windows"
"github.com/redhat-developer/mapt/pkg/util/ghactions"
"github.com/redhat-developer/mapt/pkg/util/logging"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
Expand Down Expand Up @@ -61,17 +62,29 @@ func getWindowsCreate() *cobra.Command {
viper.GetString(params.ConnectionDetailsOutput),
viper.GetStringMapString(params.Tags))

// Initialize gh actions runner if needed
if viper.IsSet(params.InstallGHActionsRunner) {
err := ghactions.InitGHRunnerArgs(viper.GetString(params.GHActionsRunnerToken),
viper.GetString(params.GHActionsRunnerName),
viper.GetString(params.GHActionsRunnerRepo))
if err != nil {
logging.Error(err)
}
}

// Run create
if err := windows.Create(
&windows.Request{
Prefix: "main",
AMIName: viper.GetString(amiName),
AMIUser: viper.GetString(amiUsername),
AMIOwner: viper.GetString(amiOwner),
AMILang: viper.GetString(amiLang),
AMIKeepCopy: viper.IsSet(amiKeepCopy),
Spot: viper.IsSet(spot),
Airgap: viper.IsSet(airgap)}); err != nil {
Prefix: "main",
AMIName: viper.GetString(amiName),
AMIUser: viper.GetString(amiUsername),
AMIOwner: viper.GetString(amiOwner),
AMILang: viper.GetString(amiLang),
AMIKeepCopy: viper.IsSet(amiKeepCopy),
Spot: viper.IsSet(spot),
Airgap: viper.IsSet(airgap),
SetupGHActionsRunner: viper.IsSet(params.InstallGHActionsRunner),
}); err != nil {
logging.Error(err)
}
return nil
Expand All @@ -87,6 +100,7 @@ func getWindowsCreate() *cobra.Command {
flagSet.Bool(airgap, false, airgapDesc)
flagSet.Bool(spot, false, spotDesc)
flagSet.Bool(amiKeepCopy, false, amiKeepCopyDesc)
flagSet.AddFlagSet(params.GetGHActionsFlagset())
c.PersistentFlags().AddFlagSet(flagSet)
return c
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package replica

import (
params "github.com/redhat-developer/mapt/cmd/cmd/constants"
params "github.com/redhat-developer/mapt/cmd/mapt/cmd/constants"
amireplication "github.com/redhat-developer/mapt/pkg/provider/aws/modules/ami"
"github.com/redhat-developer/mapt/pkg/util/logging"
"github.com/spf13/cobra"
Expand Down
2 changes: 1 addition & 1 deletion cmd/cmd/azure/azure.go → cmd/mapt/cmd/azure/azure.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package azure

import (
"github.com/redhat-developer/mapt/cmd/cmd/azure/hosts"
"github.com/redhat-developer/mapt/cmd/mapt/cmd/azure/hosts"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package hosts
import (
"fmt"

params "github.com/redhat-developer/mapt/cmd/cmd/constants"
params "github.com/redhat-developer/mapt/cmd/mapt/cmd/constants"
maptContext "github.com/redhat-developer/mapt/pkg/manager/context"
azureWindows "github.com/redhat-developer/mapt/pkg/provider/azure/action/windows"
spotprice "github.com/redhat-developer/mapt/pkg/provider/azure/module/spot-price"
"github.com/redhat-developer/mapt/pkg/util/ghactions"
"github.com/redhat-developer/mapt/pkg/util/logging"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
Expand Down Expand Up @@ -74,6 +75,7 @@ func getCreate() *cobra.Command {
viper.GetString(params.ConnectionDetailsOutput),
viper.GetStringMapString(params.Tags))

// ParseEvictionRate
var spotToleranceValue = spotprice.DefaultEvictionRate
if viper.IsSet(paramSpotTolerance) {
var ok bool
Expand All @@ -83,19 +85,30 @@ func getCreate() *cobra.Command {
return fmt.Errorf("%s is not a valid spot tolerance value", viper.GetString(paramSpotTolerance))
}
}
// ParseEvictionRate

// Initialize gh actions runner if needed
if viper.IsSet(params.InstallGHActionsRunner) {
err := ghactions.InitGHRunnerArgs(viper.GetString(params.GHActionsRunnerToken),
viper.GetString(params.GHActionsRunnerName),
viper.GetString(params.GHActionsRunnerRepo))
if err != nil {
logging.Error(err)
}
}

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: viper.GetString(params.ProjectName),
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),
Spot: viper.IsSet(paramSpot),
SpotTolerance: spotToleranceValue}); err != nil {
logging.Error(err)
}
return nil
Expand All @@ -113,6 +126,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
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package constants

import "github.com/spf13/pflag"

const (
ProjectName string = "project-name"
ProjectNameDesc string = "project name to identify the instance of the stack"
Expand Down Expand Up @@ -29,7 +31,25 @@ const (
AMISourceRegionDesc string = "region for the ami to be copied worldwide"
Tags string = "tags"
TagsDesc string = "tags to add on each resource (--tags name1=value1,name2=value2)"
InstallGHActionsRunnerDesc string = "Install and setup Github Actions runner in the instance"
GHActionsRunnerTokenDesc string = "Token needed for registering the Github Actions Runner token"
GHActionsRunnerNameDesc string = "Name for the Github Actions Runner"
GHActionsRunnerRepoDesc string = "Full URL of the repository where the Github Actions Runner should be registered"

CreateCmdName string = "create"
DestroyCmdName string = "destroy"

InstallGHActionsRunner string = "install-ghactions-runner"
GHActionsRunnerToken string = "ghactions-runner-token"
GHActionsRunnerName string = "ghactions-runner-name"
GHActionsRunnerRepo string = "ghactions-runner-repo"
)

func GetGHActionsFlagset() *pflag.FlagSet {
flagSet := pflag.NewFlagSet(CreateCmdName, pflag.ExitOnError)
flagSet.Bool(InstallGHActionsRunner, false, InstallGHActionsRunnerDesc)
flagSet.StringP(GHActionsRunnerToken, "", "", GHActionsRunnerTokenDesc)
flagSet.StringP(GHActionsRunnerName, "", "", GHActionsRunnerNameDesc)
flagSet.StringP(GHActionsRunnerRepo, "", "", GHActionsRunnerRepoDesc)
return flagSet
}
10 changes: 5 additions & 5 deletions cmd/cmd/root.go → cmd/mapt/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ import (
"path/filepath"
"strings"

"github.com/redhat-developer/mapt/cmd/cmd/aws"
"github.com/redhat-developer/mapt/cmd/cmd/azure"
params "github.com/redhat-developer/mapt/cmd/cmd/constants"
"github.com/redhat-developer/mapt/cmd/mapt/cmd/aws"
"github.com/redhat-developer/mapt/cmd/mapt/cmd/azure"
params "github.com/redhat-developer/mapt/cmd/mapt/cmd/constants"
"github.com/redhat-developer/mapt/pkg/util/logging"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)

const (
commandName = "mapt"
descriptionShort = "PoC for pulumi"
descriptionLong = "PoC for pulumi"
descriptionShort = "Multi Architecture Provisioning Tool"
descriptionLong = "MAPT is a tool for creating pre-configured machines (baremetal or VMs) on cloud providers"

defaultErrorExitCode = 1
)
Expand Down
7 changes: 7 additions & 0 deletions cmd/mapt/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "github.com/redhat-developer/mapt/cmd/mapt/cmd"

func main() {
cmd.Execute()
}
Loading