Skip to content

Commit

Permalink
Merge branch 'main' into 2372-lib-configure-pterm-output-during-deplo…
Browse files Browse the repository at this point in the history
…y-lifecycle
  • Loading branch information
Noxsios committed Mar 18, 2024
2 parents c7edb53 + 30ffc14 commit 53f9bde
Show file tree
Hide file tree
Showing 46 changed files with 695 additions and 652 deletions.
2 changes: 1 addition & 1 deletion docs/3-create-a-zarf-package/4-zarf-schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -1848,7 +1848,7 @@ Must be one of:
| ------------------------- | -------------------------------------------------------------------------------------------------------- |
| **Type** | `object` |
| **Additional properties** | [![Not allowed](https://img.shields.io/badge/Not%20allowed-red)](# "Additional Properties not allowed.") |
| **Defined in** | #/definitions/ZarfComponentActionShell |
| **Defined in** | #/definitions/Shell |

<details>
<summary>
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ require (
google.golang.org/genproto/googleapis/api v0.0.0-20240221002015-b0ce06bbee7c // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240221002015-b0ce06bbee7c // indirect
google.golang.org/grpc v1.61.1 // indirect
google.golang.org/protobuf v1.32.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/evanphx/json-patch.v5 v5.6.0 // indirect
gopkg.in/go-jose/go-jose.v2 v2.6.3 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2361,8 +2361,8 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
3 changes: 1 addition & 2 deletions src/cmd/common/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/defenseunicorns/zarf/src/config"
"github.com/defenseunicorns/zarf/src/config/lang"
"github.com/defenseunicorns/zarf/src/pkg/message"
"github.com/defenseunicorns/zarf/src/pkg/utils/exec"
"github.com/pterm/pterm"
)

Expand All @@ -20,7 +19,7 @@ var LogLevelCLI string

// SetupCLI sets up the CLI logging, interrupt functions, and more
func SetupCLI() {
exec.ExitOnInterrupt()
ExitOnInterrupt()

match := map[string]message.LogLevel{
"warn": message.WarnLevel,
Expand Down
24 changes: 24 additions & 0 deletions src/cmd/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,34 @@
// Package common handles command configuration across all commands
package common

import (
"os"
"os/signal"
"syscall"

"github.com/defenseunicorns/zarf/src/config/lang"
"github.com/defenseunicorns/zarf/src/pkg/message"
)

// SuppressGlobalInterrupt suppresses the global error on an interrupt
var SuppressGlobalInterrupt = false

// SetBaseDirectory sets the base directory. This is a directory with a zarf.yaml.
func SetBaseDirectory(args []string) string {
if len(args) > 0 {
return args[0]
}
return "."
}

// ExitOnInterrupt catches an interrupt and exits with fatal error
func ExitOnInterrupt() {
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
<-c
if !SuppressGlobalInterrupt {
message.Fatal(lang.ErrInterrupt, lang.ErrInterrupt.Error())
}
}()
}
3 changes: 2 additions & 1 deletion src/cmd/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os/signal"
"syscall"

"github.com/defenseunicorns/zarf/src/cmd/common"
"github.com/defenseunicorns/zarf/src/config/lang"
"github.com/defenseunicorns/zarf/src/pkg/cluster"
"github.com/defenseunicorns/zarf/src/pkg/k8s"
Expand Down Expand Up @@ -72,7 +73,7 @@ var (
// Keep this open until an interrupt signal is received.
interruptChan := make(chan os.Signal, 1)
signal.Notify(interruptChan, os.Interrupt, syscall.SIGTERM)
exec.SuppressGlobalInterrupt = true
common.SuppressGlobalInterrupt = true

// Wait for the interrupt signal or an error.
select {
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"github.com/defenseunicorns/zarf/src/internal/packager/helm"
"github.com/defenseunicorns/zarf/src/pkg/cluster"
"github.com/defenseunicorns/zarf/src/pkg/message"
"github.com/defenseunicorns/zarf/src/pkg/utils"
"github.com/defenseunicorns/zarf/src/pkg/utils/exec"
"github.com/defenseunicorns/zarf/src/pkg/utils/helpers"

"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -52,7 +52,7 @@ var destroyCmd = &cobra.Command{

// Run all the scripts!
pattern := regexp.MustCompile(`(?mi)zarf-clean-.+\.sh$`)
scripts, _ := utils.RecursiveFileList(config.ZarfCleanupScriptsPath, pattern, true)
scripts, _ := helpers.RecursiveFileList(config.ZarfCleanupScriptsPath, pattern, true)
// Iterate over all matching zarf-clean scripts and exec them
for _, script := range scripts {
// Run the matched script
Expand Down
10 changes: 5 additions & 5 deletions src/cmd/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ var initCmd = &cobra.Command{

func findInitPackage(initPackageName string) (string, error) {
// First, look for the init package in the current working directory
if !utils.InvalidPath(initPackageName) {
if !helpers.InvalidPath(initPackageName) {
return initPackageName, nil
}

Expand All @@ -87,19 +87,19 @@ func findInitPackage(initPackageName string) (string, error) {
return "", err
}
executableDir := path.Dir(binaryPath)
if !utils.InvalidPath(filepath.Join(executableDir, initPackageName)) {
if !helpers.InvalidPath(filepath.Join(executableDir, initPackageName)) {
return filepath.Join(executableDir, initPackageName), nil
}

// Create the cache directory if it doesn't exist
if utils.InvalidPath(config.GetAbsCachePath()) {
if err := utils.CreateDirectory(config.GetAbsCachePath(), helpers.ReadExecuteAllWriteUser); err != nil {
if helpers.InvalidPath(config.GetAbsCachePath()) {
if err := helpers.CreateDirectory(config.GetAbsCachePath(), helpers.ReadExecuteAllWriteUser); err != nil {
message.Fatalf(err, lang.CmdInitErrUnableCreateCache, config.GetAbsCachePath())
}
}

// Next, look in the cache directory
if !utils.InvalidPath(filepath.Join(config.GetAbsCachePath(), initPackageName)) {
if !helpers.InvalidPath(filepath.Join(config.GetAbsCachePath(), initPackageName)) {
return filepath.Join(config.GetAbsCachePath(), initPackageName), nil
}

Expand Down
3 changes: 1 addition & 2 deletions src/cmd/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/defenseunicorns/zarf/src/config/lang"
"github.com/defenseunicorns/zarf/src/pkg/message"
"github.com/defenseunicorns/zarf/src/pkg/packager/sources"
"github.com/defenseunicorns/zarf/src/pkg/utils"
"github.com/defenseunicorns/zarf/src/types"

"oras.land/oras-go/v2/registry"
Expand Down Expand Up @@ -214,7 +213,7 @@ var packagePublishCmd = &cobra.Command{
message.Fatalf(nil, "%s", err.Error())
}

if utils.IsDir(pkgConfig.PkgOpts.PackageSource) {
if helpers.IsDir(pkgConfig.PkgOpts.PackageSource) {
pkgConfig.CreateOpts.BaseDir = pkgConfig.PkgOpts.PackageSource
pkgConfig.CreateOpts.IsSkeleton = true
}
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/tools/crane.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import (
"strings"

"github.com/AlecAivazis/survey/v2"
"github.com/defenseunicorns/zarf/src/cmd/common"
"github.com/defenseunicorns/zarf/src/config"
"github.com/defenseunicorns/zarf/src/config/lang"
"github.com/defenseunicorns/zarf/src/pkg/cluster"
"github.com/defenseunicorns/zarf/src/pkg/message"
"github.com/defenseunicorns/zarf/src/pkg/transform"
"github.com/defenseunicorns/zarf/src/pkg/utils/exec"
"github.com/defenseunicorns/zarf/src/types"
craneCmd "github.com/google/go-containerregistry/cmd/crane/cmd"
"github.com/google/go-containerregistry/pkg/crane"
Expand All @@ -39,7 +39,7 @@ func init() {
Short: lang.CmdToolsRegistryShort,
PersistentPreRun: func(cmd *cobra.Command, _ []string) {

exec.ExitOnInterrupt()
common.ExitOnInterrupt()

// The crane options loading here comes from the rootCmd of crane
craneOptions = append(craneOptions, crane.WithContext(cmd.Context()))
Expand Down
4 changes: 2 additions & 2 deletions src/extensions/bigbang/bigbang.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func Skeletonize(tmpPaths *layout.ComponentPaths, c types.ZarfComponent) (types.
rel := filepath.Join(layout.TempDir, skelName)
dst := filepath.Join(tmpPaths.Base, rel)

if err := utils.CreatePathAndCopy(valuesFile, dst); err != nil {
if err := helpers.CreatePathAndCopy(valuesFile, dst); err != nil {
return c, err
}

Expand All @@ -282,7 +282,7 @@ func Skeletonize(tmpPaths *layout.ComponentPaths, c types.ZarfComponent) (types.
rel := filepath.Join(layout.TempDir, skelName)
dst := filepath.Join(tmpPaths.Base, rel)

if err := utils.CreatePathAndCopy(fluxPatchFile, dst); err != nil {
if err := helpers.CreatePathAndCopy(fluxPatchFile, dst); err != nil {
return c, err
}

Expand Down
6 changes: 3 additions & 3 deletions src/internal/packager/helm/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (h *Helm) PackageChartFromLocalFiles(cosignKeyPath string) error {
saved, err = client.Run(h.chart.LocalPath, nil)
} else {
saved = filepath.Join(temp, filepath.Base(h.chart.LocalPath))
err = utils.CreatePathAndCopy(h.chart.LocalPath, saved)
err = helpers.CreatePathAndCopy(h.chart.LocalPath, saved)
}
defer os.RemoveAll(temp)

Expand Down Expand Up @@ -204,7 +204,7 @@ func (h *Helm) DownloadPublishedChart(cosignKeyPath string) error {

// Download the file into a temp directory since we don't control what name helm creates here
temp := filepath.Join(h.chartPath, "temp")
if err = utils.CreateDirectory(temp, helpers.ReadWriteExecuteUser); err != nil {
if err = helpers.CreateDirectory(temp, helpers.ReadWriteExecuteUser); err != nil {
return fmt.Errorf("unable to create helm chart temp directory: %w", err)
}
defer os.RemoveAll(temp)
Expand Down Expand Up @@ -269,7 +269,7 @@ func (h *Helm) packageValues(cosignKeyPath string) error {
return fmt.Errorf(lang.ErrDownloading, path, err.Error())
}
} else {
if err := utils.CreatePathAndCopy(path, dst); err != nil {
if err := helpers.CreatePathAndCopy(path, dst); err != nil {
return fmt.Errorf("unable to copy chart values file %s: %w", path, err)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/internal/packager/images/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (i *ImageConfig) PullAll() ([]ImgInfo, error) {
}

// Create the ImagePath directory
if err := utils.CreateDirectory(i.ImagesPath, helpers.ReadExecuteAllWriteUser); err != nil {
if err := helpers.CreateDirectory(i.ImagesPath, helpers.ReadExecuteAllWriteUser); err != nil {
return nil, fmt.Errorf("failed to create image path %s: %w", i.ImagesPath, err)
}

Expand Down Expand Up @@ -233,7 +233,7 @@ func (i *ImageConfig) PullAll() ([]ImgInfo, error) {

// Create the directory for the blob if it doesn't exist
dir := filepath.Join(string(cranePath), "blobs", digest.Algorithm)
if err := utils.CreateDirectory(dir, os.ModePerm); err != nil {
if err := helpers.CreateDirectory(dir, os.ModePerm); err != nil {
layerWritingConcurrency.ErrorChan <- err
return
}
Expand Down
4 changes: 2 additions & 2 deletions src/internal/packager/sbom/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func Catalog(componentSBOMs map[string]*layout.ComponentSBOM, imageList []transf
defer builder.spinner.Stop()

// Ensure the sbom directory exists
_ = utils.CreateDirectory(builder.outputDir, helpers.ReadWriteExecuteUser)
_ = helpers.CreateDirectory(builder.outputDir, helpers.ReadWriteExecuteUser)

// Generate a list of images and files for the sbom viewer
json, err := builder.generateJSONList(componentSBOMs, imageList)
Expand Down Expand Up @@ -152,7 +152,7 @@ func (b *Builder) createImageSBOM(img v1.Image, src string) ([]byte, error) {
imageCachePath := filepath.Join(b.cachePath, layout.ImagesDir)

// Ensure the image cache directory exists.
if err := utils.CreateDirectory(imageCachePath, helpers.ReadWriteExecuteUser); err != nil {
if err := helpers.CreateDirectory(imageCachePath, helpers.ReadWriteExecuteUser); err != nil {
return nil, err
}

Expand Down

0 comments on commit 53f9bde

Please sign in to comment.