Merge pull request #2995 from fluxcd/oci-ignore

Add `--ignore-paths` arg to `flux build|push artifact`
pull/2997/head
Stefan Prodan 2 years ago committed by GitHub
commit 787b6953c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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{
@ -41,13 +43,18 @@ var buildArtifactCmd = &cobra.Command{
type buildArtifactFlags struct {
output string
path string
ignorePaths []string
}
var excludeOCI = append(strings.Split(sourceignore.ExcludeVCS, ","), strings.Split(sourceignore.ExcludeExt, ",")...)
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", excludeOCI, "set paths to ignore in .gitignore format")
buildCmd.AddCommand(buildArtifactCmd)
}
@ -63,7 +70,7 @@ 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 {
if err := ociClient.Build(buildArtifactArgs.output, buildArtifactArgs.path, buildArtifactArgs.ignorePaths); err != nil {
return fmt.Errorf("bulding artifact failed, error: %w", err)
}

@ -19,9 +19,8 @@ package main
import (
"context"
"fmt"
"os"
"github.com/spf13/cobra"
"os"
oci "github.com/fluxcd/pkg/oci/client"
)
@ -52,6 +51,7 @@ type pushArtifactFlags struct {
path string
source string
revision string
ignorePaths []string
}
var pushArtifactArgs pushArtifactFlags
@ -60,6 +60,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", excludeOCI, "set paths to ignore in .gitignore format")
pushCmd.AddCommand(pushArtifactCmd)
}
@ -101,7 +103,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 +111,4 @@ func pushArtifactCmdRun(cmd *cobra.Command, args []string) error {
logger.Successf("artifact successfully pushed to %s", digest)
return nil
}

@ -14,8 +14,9 @@ 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.1
github.com/fluxcd/pkg/runtime v0.16.2
github.com/fluxcd/pkg/sourceignore v0.1.0
github.com/fluxcd/pkg/ssa v0.17.0
github.com/fluxcd/pkg/ssh v0.5.0
github.com/fluxcd/pkg/untar v0.1.0

@ -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.1 h1:gx63SW9BymuJydDbu/8xzlMP85Tpc9FBnHZXsckgC7U=
github.com/fluxcd/pkg/oci v0.4.1/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=

Loading…
Cancel
Save