diff --git a/cmd/flux/build_artifact.go b/cmd/flux/build_artifact.go index bf523fa0..ea8c2cd7 100644 --- a/cmd/flux/build_artifact.go +++ b/cmd/flux/build_artifact.go @@ -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) } diff --git a/cmd/flux/push_artifact.go b/cmd/flux/push_artifact.go index 6f318602..52e545a5 100644 --- a/cmd/flux/push_artifact.go +++ b/cmd/flux/push_artifact.go @@ -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 '/'") + 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 - } diff --git a/go.mod b/go.mod index 9a345d1b..653c97ec 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/fluxcd/notification-controller/api v0.25.1 github.com/fluxcd/pkg/apis/meta v0.14.2 github.com/fluxcd/pkg/kustomize v0.5.2 - github.com/fluxcd/pkg/oci v0.3.0 + github.com/fluxcd/pkg/oci v0.4.0 github.com/fluxcd/pkg/runtime v0.16.2 github.com/fluxcd/pkg/ssa v0.17.0 github.com/fluxcd/pkg/ssh v0.5.0 @@ -86,6 +86,7 @@ require ( github.com/fatih/color v1.13.0 // indirect github.com/fluxcd/pkg/apis/acl v0.0.3 // indirect github.com/fluxcd/pkg/apis/kustomize v0.4.2 // indirect + github.com/fluxcd/pkg/sourceignore v0.1.0 // indirect github.com/fsnotify/fsnotify v1.5.1 // indirect github.com/go-errors/errors v1.0.1 // indirect github.com/go-git/gcfg v1.5.0 // indirect diff --git a/go.sum b/go.sum index b2a68166..f1c4f773 100644 --- a/go.sum +++ b/go.sum @@ -289,10 +289,12 @@ github.com/fluxcd/pkg/apis/meta v0.14.2 h1:/Hf7I/Vz01vv3m7Qx7DtQvrzAL1oVt0MJcLb/ github.com/fluxcd/pkg/apis/meta v0.14.2/go.mod h1:ijZ61VG/8T3U17gj0aFL3fdtZL+mulD6V8VrLLUCAgM= github.com/fluxcd/pkg/kustomize v0.5.2 h1:Nhaw/Tqwt588Cp4PYa83nj45t3mGgojMl23zhq/t/fM= github.com/fluxcd/pkg/kustomize v0.5.2/go.mod h1:X3Uls1l13giFPwig1NDoXvrF53yyXUemSyR3nYGw28s= -github.com/fluxcd/pkg/oci v0.3.0 h1:GFn6JZeg5fV2K4vsQ0s5lJFid6qrpA4RybLXL+7qUbQ= -github.com/fluxcd/pkg/oci v0.3.0/go.mod h1:c1pj9E/G5927gSa6ooACAyZe+HwjgmPk9johL7oXDHw= +github.com/fluxcd/pkg/oci v0.4.0 h1:cUNPffT/lvdVmFUe8nhPQhRNIWs1Oa2/ODI+rWikqcI= +github.com/fluxcd/pkg/oci v0.4.0/go.mod h1:eOnW+Ce3Z8AmQ+X9tf1BCv+qxwro+rPM/VKca1E9Ka0= github.com/fluxcd/pkg/runtime v0.16.2 h1:CexfMmJK+r12sHTvKWyAax0pcPomjd6VnaHXcxjUrRY= github.com/fluxcd/pkg/runtime v0.16.2/go.mod h1:OHSKsrO+T+Ym8WZRS2oidrnauWRARuE2nfm8ewevm7M= +github.com/fluxcd/pkg/sourceignore v0.1.0 h1:v36Rqp6FDB7Ntjy7NakdwscOfxFPk14peKa+VMBNugo= +github.com/fluxcd/pkg/sourceignore v0.1.0/go.mod h1:m9/q+YLMNSWjXns1n/5q3ucwzSSddti+D6ExbNaCo6s= github.com/fluxcd/pkg/ssa v0.17.0 h1:iO4EQ+/xIbd79VKrh+8fvsAvq3RlmgAdWtnzOAUxD5s= github.com/fluxcd/pkg/ssa v0.17.0/go.mod h1:UZkF5CwbDuvWPXnISoaXWlc0JPbHh8BKfa4ExeTtWgY= github.com/fluxcd/pkg/ssh v0.5.0 h1:jE9F2XvUXC2mgseeXMATvO014fLqdB30/VzlPLKsk20= @@ -1655,6 +1657,7 @@ gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk= gotest.tools/v3 v3.0.3 h1:4AuOwCGf4lLR9u3YOe2awrHygurzhO/HeQ6laiA6Sx0= gotest.tools/v3 v3.0.3/go.mod h1:Z7Lb0S5l+klDB31fvDQX8ss/FlKDxtlFlw3Oa8Ymbl8=