1
0
mirror of synced 2026-02-06 19:05:55 +00:00

Add --ignore-paths arg to flux build|push artifact

Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
This commit is contained in:
Stefan Prodan
2022-08-16 15:31:39 +03:00
parent 02b38ac8e0
commit 899a1fffca
4 changed files with 25 additions and 11 deletions

View File

@@ -19,10 +19,12 @@ package main
import (
"fmt"
"os"
"strings"
"github.com/spf13/cobra"
oci "github.com/fluxcd/pkg/oci/client"
"github.com/fluxcd/pkg/sourceignore"
)
var buildArtifactCmd = &cobra.Command{
@@ -39,8 +41,9 @@ var buildArtifactCmd = &cobra.Command{
}
type buildArtifactFlags struct {
output string
path string
output string
path string
ignorePaths []string
}
var buildArtifactArgs buildArtifactFlags
@@ -48,6 +51,8 @@ var buildArtifactArgs buildArtifactFlags
func init() {
buildArtifactCmd.Flags().StringVar(&buildArtifactArgs.path, "path", "", "Path to the directory where the Kubernetes manifests are located.")
buildArtifactCmd.Flags().StringVarP(&buildArtifactArgs.output, "output", "o", "artifact.tgz", "Path to where the artifact tgz file should be written.")
buildArtifactCmd.Flags().StringSliceVar(&buildArtifactArgs.ignorePaths, "ignore-paths", strings.Split(sourceignore.ExcludeVCS, ","), "set paths to ignore (can specify multiple paths with commas: path1,path2)")
buildCmd.AddCommand(buildArtifactCmd)
}
@@ -63,7 +68,8 @@ func buildArtifactCmdRun(cmd *cobra.Command, args []string) error {
logger.Actionf("building artifact from %s", buildArtifactArgs.path)
ociClient := oci.NewLocalClient()
if err := ociClient.Build(buildArtifactArgs.output, buildArtifactArgs.path); err != nil {
logger.Successf("%v", buildArtifactArgs.ignorePaths)
if err := ociClient.Build(buildArtifactArgs.output, buildArtifactArgs.path, buildArtifactArgs.ignorePaths); err != nil {
return fmt.Errorf("bulding artifact failed, error: %w", err)
}

View File

@@ -20,10 +20,12 @@ import (
"context"
"fmt"
"os"
"strings"
"github.com/spf13/cobra"
oci "github.com/fluxcd/pkg/oci/client"
"github.com/fluxcd/pkg/sourceignore"
)
var pushArtifactCmd = &cobra.Command{
@@ -49,9 +51,10 @@ The command uses the credentials from '~/.docker/config.json'.`,
}
type pushArtifactFlags struct {
path string
source string
revision string
path string
source string
revision string
ignorePaths []string
}
var pushArtifactArgs pushArtifactFlags
@@ -60,6 +63,8 @@ func init() {
pushArtifactCmd.Flags().StringVar(&pushArtifactArgs.path, "path", "", "path to the directory where the Kubernetes manifests are located")
pushArtifactCmd.Flags().StringVar(&pushArtifactArgs.source, "source", "", "the source address, e.g. the Git URL")
pushArtifactCmd.Flags().StringVar(&pushArtifactArgs.revision, "revision", "", "the source revision in the format '<branch|tag>/<commit-sha>'")
pushArtifactCmd.Flags().StringSliceVar(&pushArtifactArgs.ignorePaths, "ignore-paths", strings.Split(sourceignore.ExcludeVCS, ","), "set paths to ignore (can specify multiple paths with commas: path1,path2)")
pushCmd.AddCommand(pushArtifactCmd)
}
@@ -101,7 +106,7 @@ func pushArtifactCmdRun(cmd *cobra.Command, args []string) error {
logger.Actionf("pushing artifact to %s", url)
digest, err := ociClient.Push(ctx, url, pushArtifactArgs.path, meta)
digest, err := ociClient.Push(ctx, url, pushArtifactArgs.path, meta, pushArtifactArgs.ignorePaths)
if err != nil {
return fmt.Errorf("pushing artifact failed: %w", err)
}
@@ -109,5 +114,4 @@ func pushArtifactCmdRun(cmd *cobra.Command, args []string) error {
logger.Successf("artifact successfully pushed to %s", digest)
return nil
}