-
Notifications
You must be signed in to change notification settings - Fork 221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(cmd/bundle): add new bundle build sub-commands #2334
Merged
Merged
Changes from 18 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
f1eb8b2
refactor(oci): decouple store from config.OCI
GeorgeMac 5519fd9
refactor(oci): move directory ensuring into store
GeorgeMac df16b85
feat(cmd/bundle): add new bundle build sub-commands
GeorgeMac cd79929
fix(cmd/bundle): correct typo in help message
GeorgeMac b6248a2
fix(oci): walk entire stream of documents
GeorgeMac 706d9ca
chore(oci): remove debug println
GeorgeMac 9bbe22a
test(oci): add more testdata to build case
GeorgeMac 1956955
feat(cmd/flipt): implement bundle list
GeorgeMac 1abc221
feat(cmd): add JSON support to import/export
GeorgeMac 388b885
fix(storage/fs/oci): update source for new oci.Store interface
GeorgeMac 1c8fffd
fix(sql/test): use new import encoding signature
GeorgeMac 59f0d54
chore(oci): make constants for possible schemes
GeorgeMac 9d3165a
chore(ext): remove unnecessary conversions
GeorgeMac 60b57ee
chore(oci): remove uncessary context argument
GeorgeMac 7c8ecdc
test(storage/fs): unknown extension returns an error
GeorgeMac 86bb900
test(storage/fs): ensure count rules returns as expected
GeorgeMac 720ad36
test(storage/fs): ensure walk documents returns expected count
GeorgeMac 5ca0e60
test(storage/fs): add more cases around invalid formats
GeorgeMac 31800d8
chore(bundle): add build use string
GeorgeMac fc59ef6
fix(storage/fs): dont index beyond slice bounds
GeorgeMac File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"text/tabwriter" | ||
|
||
"github.com/spf13/cobra" | ||
"go.flipt.io/flipt/internal/containers" | ||
"go.flipt.io/flipt/internal/oci" | ||
) | ||
|
||
type bundleCommand struct{} | ||
|
||
func newBundleCommand() *cobra.Command { | ||
bundle := &bundleCommand{} | ||
|
||
cmd := &cobra.Command{ | ||
Use: "bundle", | ||
Short: "Manage Flipt bundles", | ||
} | ||
|
||
cmd.AddCommand(&cobra.Command{ | ||
Use: "build", | ||
Short: "Build a bundle", | ||
RunE: bundle.build, | ||
Args: cobra.ExactArgs(1), | ||
}) | ||
|
||
cmd.AddCommand(&cobra.Command{ | ||
Use: "list", | ||
Short: "List all bundles", | ||
RunE: bundle.list, | ||
}) | ||
|
||
return cmd | ||
} | ||
|
||
func (c *bundleCommand) build(cmd *cobra.Command, args []string) error { | ||
store, err := c.getStore() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
ref, err := oci.ParseReference(args[0]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
bundle, err := store.Build(cmd.Context(), os.DirFS("."), ref) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Println(bundle.Digest) | ||
|
||
return nil | ||
} | ||
|
||
func (c *bundleCommand) list(cmd *cobra.Command, args []string) error { | ||
store, err := c.getStore() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
bundles, err := store.List(cmd.Context()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
wr := writer() | ||
|
||
fmt.Fprintf(wr, "DIGEST\tREPO\tTAG\tCREATED\t\n") | ||
for _, bundle := range bundles { | ||
fmt.Fprintf(wr, "%s\t%s\t%s\t%s\t\n", bundle.Digest.Hex()[:7], bundle.Repository, bundle.Tag, bundle.CreatedAt) | ||
} | ||
|
||
return wr.Flush() | ||
} | ||
|
||
func (c *bundleCommand) getStore() (*oci.Store, error) { | ||
logger, cfg, err := buildConfig() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var opts []containers.Option[oci.StoreOptions] | ||
if cfg := cfg.Storage.OCI; cfg != nil { | ||
if cfg.BundleDirectory != "" { | ||
opts = append(opts, oci.WithBundleDir(cfg.BundleDirectory)) | ||
} | ||
|
||
if cfg.Authentication != nil { | ||
opts = append(opts, oci.WithCredentials( | ||
cfg.Authentication.Username, | ||
cfg.Authentication.Password, | ||
)) | ||
} | ||
} | ||
|
||
return oci.NewStore(logger, opts...) | ||
} | ||
|
||
func writer() *tabwriter.Writer { | ||
return tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0) | ||
} |
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
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
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we give the user the ability to set this format via a CLI flag now that we support JSON? could default to yaml still
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh yeah I wondered about this. So it will support JSON if you specify a file with
.json
as the target.However, for STDOUT, yeah we could have an actual flag. Same for import and STDIN.