-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Gerd Oberlechner <[email protected]>
- Loading branch information
Showing
14 changed files
with
434 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,24 @@ | ||
SHELL = /bin/bash | ||
SHELLFLAGS = -eu -o pipefail -c | ||
SHELLFLAGS = -eu -o pipefail | ||
|
||
ifndef EV2 | ||
ifndef RUNS_IN_TEMPLATIZE | ||
PROJECT_ROOT_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) | ||
|
||
DEPLOY_ENV ?= personal-dev | ||
PIPELINE ?= pipeline.yaml | ||
PIPELINE_STEP ?= deploy | ||
HASH = $(shell echo -n "$(DEPLOY_ENV)$(PIPELINE)$(PIPELINE_STEP)" | md5) | ||
ENV_VARS_FILE ?= /tmp/deploy.${HASH}.cfg | ||
ENV_VARS_FILE ?= ${TMPDIR}/deploy.${HASH}.cfg | ||
|
||
# Target to generate the environment variables file | ||
$(ENV_VARS_FILE): ${PROJECT_ROOT_DIR}/config/config.yaml ${PIPELINE} ${PROJECT_ROOT_DIR}/templatize.sh ${MAKEFILE_LIST} | ||
@echo "generate env vars" | ||
@echo "generate env vars file ${ENV_VARS_FILE}" | ||
@${PROJECT_ROOT_DIR}/templatize.sh ${DEPLOY_ENV} \ | ||
-p ${PIPELINE} \ | ||
-s ${PIPELINE_STEP} > $@ | ||
-s ${PIPELINE_STEP} > $(ENV_VARS_FILE) | ||
|
||
# Include the environment variables file if it exists | ||
ifndef EV2 | ||
-include ${ENV_VARS_FILE} | ||
endif | ||
endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
SHELL = /bin/bash | ||
|
||
# Define the binary name | ||
BINARY = templatize | ||
|
||
# Define the source files | ||
SOURCES = $(shell find . -name '*.go') | ||
|
||
# Build the binary | ||
$(BINARY): $(SOURCES) $(MAKEFILE_LIST) | ||
@echo "rebuild templatize" | ||
go build -o $(BINARY) . | ||
|
||
# Clean the build artifacts | ||
clean: | ||
rm -f $(BINARY) | ||
|
||
.PHONY: clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package pipeline | ||
|
||
import ( | ||
"github.com/Azure/ARO-HCP/tooling/templatize/cmd/pipeline/inspect" | ||
"github.com/Azure/ARO-HCP/tooling/templatize/cmd/pipeline/run" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "pipeline", | ||
Short: "pipeline", | ||
Long: "pipeline", | ||
SilenceUsage: true, | ||
TraverseChildren: true, | ||
CompletionOptions: cobra.CompletionOptions{ | ||
HiddenDefaultCmd: true, | ||
}, | ||
} | ||
cmd.AddCommand(run.NewCommand()) | ||
cmd.AddCommand(inspect.NewCommand()) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package inspect | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewCommand() *cobra.Command { | ||
opts := DefaultOptions() | ||
cmd := &cobra.Command{ | ||
Use: "inspect", | ||
Short: "inspect aspects of a pipeline.yaml file", | ||
Long: "inspect aspects of a pipeline.yaml file", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
ctx, stop := signal.NotifyContext(cmd.Context(), os.Interrupt, syscall.SIGTERM) | ||
defer stop() | ||
|
||
return runInspect(ctx, opts) | ||
}, | ||
} | ||
if err := BindOptions(opts, cmd); err != nil { | ||
log.Fatal(err) | ||
} | ||
return cmd | ||
} | ||
|
||
func runInspect(ctx context.Context, opts *RawInspectOptions) error { | ||
validated, err := opts.Validate() | ||
if err != nil { | ||
return err | ||
} | ||
completed, err := validated.Complete() | ||
if err != nil { | ||
return err | ||
} | ||
return completed.RunInspect(ctx) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package inspect | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/Azure/ARO-HCP/tooling/templatize/cmd/pipeline/options" | ||
"github.com/Azure/ARO-HCP/tooling/templatize/pkg/config" | ||
"github.com/Azure/ARO-HCP/tooling/templatize/pkg/pipeline" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func DefaultOptions() *RawInspectOptions { | ||
return &RawInspectOptions{ | ||
PipelineOptions: options.DefaultOptions(), | ||
} | ||
} | ||
|
||
func BindOptions(opts *RawInspectOptions, cmd *cobra.Command) error { | ||
err := options.BindOptions(opts.PipelineOptions, cmd) | ||
if err != nil { | ||
return fmt.Errorf("failed to bind options: %w", err) | ||
} | ||
cmd.Flags().StringVar(&opts.Aspect, "aspect", opts.Aspect, "aspect of the pipeline to inspect") | ||
cmd.Flags().StringVar(&opts.Format, "format", opts.Format, "output format") | ||
return nil | ||
} | ||
|
||
type RawInspectOptions struct { | ||
PipelineOptions *options.RawPipelineOptions | ||
Aspect string | ||
Format string | ||
} | ||
|
||
// validatedInspectOptions is a private wrapper that enforces a call of Validate() before Complete() can be invoked. | ||
type validatedInspectOptions struct { | ||
*RawInspectOptions | ||
*options.ValidatedPipelineOptions | ||
} | ||
|
||
type ValidatedInspectOptions struct { | ||
// Embed a private pointer that cannot be instantiated outside of this package. | ||
*validatedInspectOptions | ||
} | ||
|
||
// completedRunOptions is a private wrapper that enforces a call of Complete() before config generation can be invoked. | ||
type completedInspectOptions struct { | ||
PipelineOptions *options.PipelineOptions | ||
Aspect string | ||
Format string | ||
} | ||
|
||
type InspectOptions struct { | ||
// Embed a private pointer that cannot be instantiated outside of this package. | ||
*completedInspectOptions | ||
} | ||
|
||
func (o *RawInspectOptions) Validate() (*ValidatedInspectOptions, error) { | ||
validatedPipelineOptions, err := o.PipelineOptions.Validate() | ||
if err != nil { | ||
return nil, err | ||
} | ||
// todo validate aspect | ||
return &ValidatedInspectOptions{ | ||
validatedInspectOptions: &validatedInspectOptions{ | ||
RawInspectOptions: o, | ||
ValidatedPipelineOptions: validatedPipelineOptions, | ||
}, | ||
}, nil | ||
} | ||
|
||
func (o *ValidatedInspectOptions) Complete() (*InspectOptions, error) { | ||
completed, err := o.ValidatedPipelineOptions.Complete() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &InspectOptions{ | ||
completedInspectOptions: &completedInspectOptions{ | ||
PipelineOptions: completed, | ||
Aspect: o.Aspect, | ||
Format: o.Format, | ||
}, | ||
}, nil | ||
} | ||
|
||
func (o *InspectOptions) RunInspect(ctx context.Context) error { | ||
rolloutOptions := o.PipelineOptions.RolloutOptions | ||
variables, err := rolloutOptions.Options.ConfigProvider.GetVariables( | ||
rolloutOptions.Cloud, | ||
rolloutOptions.DeployEnv, | ||
rolloutOptions.Region, | ||
config.NewConfigReplacements( | ||
rolloutOptions.Region, | ||
rolloutOptions.RegionShort, | ||
rolloutOptions.Stamp, | ||
), | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
return o.PipelineOptions.Pipeline.Inspect(ctx, &pipeline.PipelineInspectOptions{ | ||
Vars: variables, | ||
Region: rolloutOptions.Region, | ||
Step: o.PipelineOptions.Step, | ||
Aspect: o.Aspect, | ||
Format: o.Format, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.