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

WIP: Add Cirrus support #382

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/build-img-ghrunner-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
pull_request:
branches: [ main ]
paths:
- 'pkg/util/ghactions/*.go'
- 'pkg/integrations/github/*.go'
- '.github/workflows/build-img-ghrunner-test.yaml'

jobs:
Expand Down
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ VERSION ?= 0.8.0-dev
CONTAINER_MANAGER ?= podman
# Image URL to use all building/pushing image targets
IMG ?= quay.io/redhat-developer/mapt:v${VERSION}
# IMG ?= quay.io/rhqp/mapt:serverless-10-amd64

TKN_IMG ?= quay.io/redhat-developer/mapt:v${VERSION}-tkn

# Go and compilation related variables
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ About the target environments offered it is not limited to a single machine or s
| Service | Provider | Information | Tekton
| -------------- | ------------- | ------------- | ---------------------------- |
| AKS | Azure | [info](docs/azure/aks.md) | [task](tkn/infra-azure-aks.yaml)
| Mac-pool | AWS | [info](docs/aws/mac-pool.md) | -

## CI/CD integrations

Expand Down
4 changes: 3 additions & 1 deletion cmd/mapt/cmd/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package aws

import (
"github.com/redhat-developer/mapt/cmd/mapt/cmd/aws/hosts"
"github.com/redhat-developer/mapt/cmd/mapt/cmd/aws/services"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand All @@ -27,6 +28,7 @@ func GetCmd() *cobra.Command {
hosts.GetMacCmd(),
hosts.GetWindowsCmd(),
hosts.GetRHELCmd(),
hosts.GetFedoraCmd())
hosts.GetFedoraCmd(),
services.GetMacPoolCmd())
return c
}
21 changes: 21 additions & 0 deletions cmd/mapt/cmd/aws/constants/contants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package constants

import "github.com/redhat-developer/mapt/pkg/provider/aws/action/mac"

const (
MACRequestCmd = "request"
MACRRequestCmdDesc = "request mac machine"
MACReleaseCmd = "release"
MACReleaseCmdDesc = "release mac machine"

MACArch string = "arch"
MACArchDesc string = "MAC architecture allowed values x86, m1, m2"
MACArchDefault string = mac.DefaultArch
MACOSVersion string = "version"
MACOSVersionDesc string = "MACos operating system vestion 11, 12 on x86 and m1/m2; 13, 14 on all archs"
MACOSVersionDefault string = mac.DefaultOSVersion
MACFixedLocation string = "fixed-location"
MACFixedLocationDesc string = "if this flag is set the host will be created only on the region set by the AWS Env (AWS_DEFAULT_REGION)"
MACDHID string = "dedicated-host-id"
MACDHIDDesc string = "id for the dedicated host"
)
12 changes: 4 additions & 8 deletions cmd/mapt/cmd/aws/hosts/constans.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package hosts

const (
spot string = "spot"
spotDesc string = "if this flag is set the host will be created only on the region set by the AWS Env (AWS_DEFAULT_REGION)"
airgap string = "airgap"
airgapDesc string = "if this flag is set the host will be created as airgap machine. Access will done through a bastion"
serverless string = "serverless"
serverlessDesc string = "if serverless is set the command will be executed as a serverless action."
timeout string = "timeout"
timeoutDesc string = "if timeout is set a serverless destroy actions will be set on the time according to the timeout. The Timeout value is a duration conforming to Go ParseDuration format."
spot string = "spot"
spotDesc string = "if this flag is set the host will be created only on the region set by the AWS Env (AWS_DEFAULT_REGION)"
airgap string = "airgap"
airgapDesc string = "if this flag is set the host will be created as airgap machine. Access will done through a bastion"

vmTypes string = "vm-types"
vmTypesDescription string = "set an specific set of vm-types and ignore any CPUs, Memory, Arch parameters set. Note vm-type should match requested arch. Also if --spot flag is used set at least 3 types."
Expand Down
81 changes: 41 additions & 40 deletions cmd/mapt/cmd/aws/hosts/fedora.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package hosts

import (
params "github.com/redhat-developer/mapt/cmd/mapt/cmd/constants"
"github.com/redhat-developer/mapt/pkg/integrations/github"
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/provider/util/instancetypes"
"github.com/redhat-developer/mapt/pkg/util"
"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 All @@ -33,6 +33,11 @@ func GetFedoraCmd() *cobra.Command {
return nil
},
}

flagSet := pflag.NewFlagSet(cmdFedora, pflag.ExitOnError)
params.AddCommonFlags(flagSet)
c.PersistentFlags().AddFlagSet(flagSet)

c.AddCommand(getFedoraCreate(), getFedoraDestroy())
return c
}
Expand All @@ -46,42 +51,40 @@ func getFedoraCreate() *cobra.Command {
return err
}

// Initialize context
maptContext.Init(
viper.GetString(params.ProjectName),
viper.GetString(params.BackedURL),
viper.GetString(params.ConnectionDetailsOutput),
viper.GetStringMapString(params.Tags),
viper.IsSet(params.Debug),
viper.GetUint(params.DebugLevel))
ctx := &maptContext.ContextArgs{
ProjectName: viper.GetString(params.ProjectName),
BackedURL: viper.GetString(params.BackedURL),
ResultsOutput: viper.GetString(params.ConnectionDetailsOutput),
Debug: viper.IsSet(params.Debug),
DebugLevel: viper.GetUint(params.DebugLevel),
Tags: 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),
viper.GetStringSlice(params.GHActionsRunnerLabels))
if err != nil {
logging.Fatal(err)
}
}
instanceRequest := &instancetypes.AwsInstanceRequest{
CPUs: viper.GetInt32(params.CPUs),
MemoryGib: viper.GetInt32(params.Memory),
Arch: util.If(viper.GetString(params.LinuxArch) == "arm64", instancetypes.Arm64, instancetypes.Amd64),
NestedVirt: viper.GetBool(params.ProfileSNC) || viper.GetBool(params.NestedVirt),
ctx.GHRunnerArgs = &github.GithubRunnerArgs{
Token: viper.GetString(params.GHActionsRunnerToken),
RepoURL: viper.GetString(params.GHActionsRunnerName),
Name: viper.GetString(params.GHActionsRunnerRepo),
Labels: viper.GetStringSlice(params.GHActionsRunnerLabels)}
}

// Run create
if err := fedora.Create(
ctx,
&fedora.Request{
Prefix: "main",
Version: viper.GetString(fedoraVersion),
Arch: viper.GetString(params.LinuxArch),
VMType: viper.GetStringSlice(vmTypes),
InstanceRequest: instanceRequest,
Prefix: "main",
Version: viper.GetString(fedoraVersion),
Arch: viper.GetString(params.LinuxArch),
VMType: viper.GetStringSlice(vmTypes),
InstanceRequest: &instancetypes.AwsInstanceRequest{
CPUs: viper.GetInt32(params.CPUs),
MemoryGib: viper.GetInt32(params.Memory),
Arch: util.If(viper.GetString(params.LinuxArch) == "arm64",
instancetypes.Arm64, instancetypes.Amd64),
NestedVirt: viper.GetBool(params.ProfileSNC) || viper.GetBool(params.NestedVirt),
},
Spot: viper.IsSet(spot),
Timeout: viper.GetString(timeout),
Timeout: viper.GetString(params.Timeout),
SetupGHActionsRunner: viper.IsSet(params.InstallGHActionsRunner),
Airgap: viper.IsSet(airgap)}); err != nil {
logging.Error(err)
Expand All @@ -97,7 +100,7 @@ func getFedoraCreate() *cobra.Command {
flagSet.StringSliceP(vmTypes, "", []string{}, vmTypesDescription)
flagSet.Bool(airgap, false, airgapDesc)
flagSet.Bool(spot, false, spotDesc)
flagSet.StringP(timeout, "", "", timeout)
flagSet.StringP(params.Timeout, "", "", params.TimeoutDesc)
flagSet.AddFlagSet(params.GetGHActionsFlagset())
flagSet.AddFlagSet(params.GetCpusAndMemoryFlagset())
c.PersistentFlags().AddFlagSet(flagSet)
Expand All @@ -113,22 +116,20 @@ func getFedoraDestroy() *cobra.Command {
return err
}

maptContext.InitBase(
viper.GetString(params.ProjectName),
viper.GetString(params.BackedURL),
viper.IsSet(params.Debug),
viper.GetUint(params.DebugLevel))

logging.Debug("Run fedora destroy")

if err := fedora.Destroy(viper.IsSet(serverless)); err != nil {
if err := fedora.Destroy(&maptContext.ContextArgs{
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),
}); err != nil {
logging.Error(err)
}
return nil
},
}
flagSet := pflag.NewFlagSet(params.DestroyCmdName, pflag.ExitOnError)
flagSet.Bool(serverless, false, serverlessDesc)
flagSet.Bool(params.Serverless, false, params.ServerlessDesc)
c.PersistentFlags().AddFlagSet(flagSet)
return c
}
Loading
Loading