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

Added build deploy option environment #109

Merged
merged 4 commits into from
Nov 12, 2024
Merged
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
16 changes: 12 additions & 4 deletions cmd/createApplyConfigPipelineJob.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,27 @@ import (
"github.com/equinor/radix-cli/pkg/client"
"github.com/equinor/radix-cli/pkg/config"
"github.com/equinor/radix-cli/pkg/flagnames"
"github.com/equinor/radix-cli/pkg/model"
"github.com/equinor/radix-cli/pkg/utils/completion"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

var deployExternalDNSAlias model.BoolPtr

var createApplyConfigPipelineJobCmd = &cobra.Command{
Use: "apply-config",
Short: "Will trigger apply-config of a Radix application",
Long: "Triggers applyConfig of a Radix application according to the radix config in its repository's master branch.",
Example: ` # Create a Radix pipeline apply-config job to apply the radixconfig properties without re-building or re-deploying components.
Currently applied changes in properties DNS alias, build secrets, create new or soft-delete existing environments.
By default it applies changes to properties DNS alias, build secrets, and create new or soft-delete existing environments.
rx create job apply-config --application radix-test

# Create a Radix pipeline applyConfig-only job, short option versions
rx create job apply-config -a radix-test`,
rx create job apply-config -a radix-test

# Create a Radix pipeline apply-config job with external DNS aliases
rx create job apply-config -a radix-test --deploy-external-dns-alias true`,
RunE: func(cmd *cobra.Command, args []string) error {
var errs []error
appName, err := config.GetAppNameFromConfigOrFromParameter(cmd, flagnames.Application)
Expand Down Expand Up @@ -68,7 +74,8 @@ Currently applied changes in properties DNS alias, build secrets, create new or
triggerPipelineParams := application.NewTriggerPipelineApplyConfigParams()
triggerPipelineParams.SetAppName(appName)
parametersApplyConfig := models.PipelineParametersApplyConfig{
TriggeredBy: triggeredByUser,
TriggeredBy: triggeredByUser,
DeployExternalDNS: deployExternalDNSAlias.Get(),
}
triggerPipelineParams.SetPipelineParametersApplyConfig(&parametersApplyConfig)

Expand All @@ -89,6 +96,7 @@ Currently applied changes in properties DNS alias, build secrets, create new or
func init() {
createJobCmd.AddCommand(createApplyConfigPipelineJobCmd)
createApplyConfigPipelineJobCmd.Flags().StringP(flagnames.Application, "a", "", "Name of the application to apply-config")
createApplyConfigPipelineJobCmd.Flags().Var(&deployExternalDNSAlias, flagnames.DeployExternalDNSAlias, "Optional. Deploy changes in External DNS aliases. Default is false.")
createApplyConfigPipelineJobCmd.Flags().StringP(flagnames.User, "u", "", "The user who triggered the apply-config")
createApplyConfigPipelineJobCmd.Flags().BoolP(flagnames.Follow, "f", false, "Follow applyConfig")
_ = createApplyConfigPipelineJobCmd.RegisterFlagCompletionFunc(flagnames.Application, completion.ApplicationCompletion)
Expand Down
36 changes: 28 additions & 8 deletions cmd/createBuildDeployPipelineJob.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,44 @@ import (
"github.com/spf13/cobra"
)

var overrideUseBuildCache model.BoolPtr
var overrideUseBuildCacheForBuildDeploy model.BoolPtr

// createBuildDeployApplicationCmd represents the buildApplication command
var createBuildDeployApplicationCmd = &cobra.Command{
Use: "build-deploy",
Short: "Will trigger build-deploy of a Radix application",
Long: `Triggers build-deploy of Radix application, if branch to environment map exists for the branch in the Radix config`,
RunE: func(cmd *cobra.Command, args []string) error {
var errs []error
appName, err := config.GetAppNameFromConfigOrFromParameter(cmd, flagnames.Application)
if err != nil {
return err
errs = append(errs, err)
}

branch, _ := cmd.Flags().GetString(flagnames.Branch)
commitID, _ := cmd.Flags().GetString(flagnames.CommitID)
follow, _ := cmd.Flags().GetBool(flagnames.Follow)
branch, err := cmd.Flags().GetString(flagnames.Branch)
if err != nil {
errs = append(errs, err)
}
commitID, err := cmd.Flags().GetString(flagnames.CommitID)
if err != nil {
errs = append(errs, err)
}
targetEnvironment, err := cmd.Flags().GetString(flagnames.Environment)
if err != nil {
errs = append(errs, err)
}
follow, err := cmd.Flags().GetBool(flagnames.Follow)
if err != nil {
errs = append(errs, err)
}

if appName == "" || branch == "" {
return errors.New("application name and branch are required")
errs = append(errs, errors.New("application name and branch are required"))
}
if len(errs) > 0 {
return errors.Join(errs...)
}

cmd.SilenceUsage = true

apiClient, err := client.GetForCommand(cmd)
Expand All @@ -60,8 +78,9 @@ var createBuildDeployApplicationCmd = &cobra.Command{
triggerPipelineParams.SetAppName(appName)
triggerPipelineParams.SetPipelineParametersBuild(&models.PipelineParametersBuild{
Branch: branch,
ToEnvironment: targetEnvironment,
CommitID: commitID,
OverrideUseBuildCache: overrideUseBuildCache.Get(),
OverrideUseBuildCache: overrideUseBuildCacheForBuildDeploy.Get(),
})

newJob, err := apiClient.Application.TriggerPipelineBuildDeploy(triggerPipelineParams, nil)
Expand All @@ -82,9 +101,10 @@ func init() {
createJobCmd.AddCommand(createBuildDeployApplicationCmd)
createBuildDeployApplicationCmd.Flags().StringP(flagnames.Application, "a", "", "Name of the application to build-deploy")
createBuildDeployApplicationCmd.Flags().StringP(flagnames.Branch, "b", "master", "Branch to build-deploy from")
createBuildDeployApplicationCmd.Flags().StringP(flagnames.Environment, "e", "", "Optional. Target environment to deploy in ('prod', 'dev', 'playground'), when multiple environments are built from the selected branch.")
createBuildDeployApplicationCmd.Flags().StringP(flagnames.CommitID, "i", "", "Commit id")
createBuildDeployApplicationCmd.Flags().BoolP(flagnames.Follow, "f", false, "Follow build-deploy")
createBuildDeployApplicationCmd.Flags().Var(&overrideUseBuildCache, flagnames.UseBuildCache, "Optional. Overrides configured or default useBuildCache option. It is applicable when the useBuildKit option is set as true.")
createBuildDeployApplicationCmd.Flags().Var(&overrideUseBuildCacheForBuildDeploy, flagnames.UseBuildCache, "Optional. Overrides configured or default useBuildCache option. It is applicable when the useBuildKit option is set as true.")

_ = createBuildDeployApplicationCmd.RegisterFlagCompletionFunc(flagnames.Application, completion.ApplicationCompletion)
setContextSpecificPersistentFlags(createBuildDeployApplicationCmd)
Expand Down
32 changes: 26 additions & 6 deletions cmd/createBuildPipelineJob.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,42 @@ import (
"github.com/equinor/radix-cli/pkg/client"
"github.com/equinor/radix-cli/pkg/config"
"github.com/equinor/radix-cli/pkg/flagnames"
"github.com/equinor/radix-cli/pkg/model"
"github.com/equinor/radix-cli/pkg/utils/completion"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

// createBuildPipelineJobCmd represents the createBuildPipelineJob command
var overrideUseBuildCacheForBuild model.BoolPtr

var createBuildPipelineJobCmd = &cobra.Command{
Use: "build",
Short: "Will trigger build of a Radix application",
Long: `Triggers build of Radix application, for branches that are mapped to a environment in the Radix config`,
RunE: func(cmd *cobra.Command, args []string) error {
var errs []error
appName, err := config.GetAppNameFromConfigOrFromParameter(cmd, flagnames.Application)
if err != nil {
return err
errs = append(errs, err)
}
if appName == "" {
return errors.New("application name is required")
errs = append(errs, errors.New("application name is required"))
}
branch, err := cmd.Flags().GetString(flagnames.Branch)
if err != nil {
errs = append(errs, err)
}
targetEnvironment, err := cmd.Flags().GetString(flagnames.Environment)
if err != nil {
errs = append(errs, err)
}
follow, err := cmd.Flags().GetBool(flagnames.Follow)
if err != nil {
errs = append(errs, err)
}
if len(errs) > 0 {
return errors.Join(errs...)
}
branch, _ := cmd.Flags().GetString(flagnames.Branch)
follow, _ := cmd.Flags().GetBool(flagnames.Follow)

cmd.SilenceUsage = true

Expand All @@ -52,7 +68,9 @@ var createBuildPipelineJobCmd = &cobra.Command{
triggerDeployParams := application.NewTriggerPipelineBuildParams()
triggerDeployParams.SetAppName(appName)
triggerDeployParams.SetPipelineParametersBuild(&models.PipelineParametersBuild{
Branch: branch,
Branch: branch,
ToEnvironment: targetEnvironment,
OverrideUseBuildCache: overrideUseBuildCacheForBuild.Get(),
})
newJob, err := apiClient.Application.TriggerPipelineBuild(triggerDeployParams, nil)
if err != nil {
Expand All @@ -73,7 +91,9 @@ func init() {
createJobCmd.AddCommand(createBuildPipelineJobCmd)
createBuildPipelineJobCmd.Flags().StringP(flagnames.Branch, "b", "master", "Branch to build from")
createBuildPipelineJobCmd.Flags().StringP(flagnames.Application, "a", "", "Name of the application to build")
createBuildPipelineJobCmd.Flags().StringP(flagnames.Environment, "e", "", "Optional. Target environment to deploy in ('prod', 'dev', 'playground'), when multiple environments are built from the selected branch.")
createBuildPipelineJobCmd.Flags().BoolP(flagnames.Follow, "f", false, "Follow build")
createBuildPipelineJobCmd.Flags().Var(&overrideUseBuildCacheForBuild, flagnames.UseBuildCache, "Optional. Overrides configured or default useBuildCache option. It is applicable when the useBuildKit option is set as true.")
if err := createBuildPipelineJobCmd.MarkFlagRequired(flagnames.Branch); err != nil {
log.Fatalf("Error during command initialization: %v", err)
}
Expand Down
82 changes: 82 additions & 0 deletions generated-client/client/environment/environment_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading