-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
show: Commands to output app manifest and compose
Add a new command `show` with two subcommands to print App manifest and compose file/project. Signed-off-by: Mike Sul <[email protected]>
- Loading branch information
Showing
5 changed files
with
138 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package composectl | ||
|
||
import ( | ||
"fmt" | ||
"github.com/containerd/containerd/platforms" | ||
"github.com/foundriesio/composeapp/pkg/compose" | ||
v1 "github.com/foundriesio/composeapp/pkg/compose/v1" | ||
"github.com/spf13/cobra" | ||
"path" | ||
) | ||
|
||
var ( | ||
composeCmd = &cobra.Command{ | ||
Use: "compose", | ||
Short: "compose <ref>", | ||
Long: ``, | ||
Args: cobra.ExactArgs(1), | ||
} | ||
) | ||
|
||
type ( | ||
composeOptions struct { | ||
SrcStorePath *string | ||
Locally *bool | ||
} | ||
) | ||
|
||
func init() { | ||
opts := composeOptions{} | ||
|
||
opts.SrcStorePath = composeCmd.Flags().StringP("source-store-path", "l", "", | ||
"A path to the source store root directory") | ||
opts.Locally = composeCmd.Flags().BoolP("local", "", false, | ||
"Print compose config/file of app stored locally") | ||
composeCmd.Run = func(cmd *cobra.Command, args []string) { | ||
doOutputComposeFile(cmd, args, &opts) | ||
} | ||
|
||
showCmd.AddCommand(composeCmd) | ||
} | ||
|
||
func doOutputComposeFile(cmd *cobra.Command, args []string, opts *composeOptions) { | ||
if *opts.Locally && len(*opts.SrcStorePath) == 0 { | ||
opts.SrcStorePath = &config.StoreRoot | ||
} | ||
var blobProvider compose.BlobProvider | ||
if len(*opts.SrcStorePath) > 0 { | ||
blobProvider = compose.NewStoreBlobProvider(path.Join(*opts.SrcStorePath, "blobs", "sha256")) | ||
} else { | ||
authorizer := compose.NewRegistryAuthorizer(config.DockerCfg) | ||
resolver := compose.NewResolver(authorizer, config.ConnectTime) | ||
blobProvider = compose.NewRemoteBlobProvider(resolver) | ||
} | ||
app, _, err := v1.NewAppLoader().LoadAppTree(cmd.Context(), blobProvider, platforms.OnlyStrict(config.Platform), args[0]) | ||
DieNotNil(err) | ||
composeProject, err := app.GetCompose(cmd.Context(), blobProvider) | ||
DieNotNil(err) | ||
b, err := composeProject.MarshalYAML() | ||
DieNotNil(err) | ||
fmt.Printf("%s", string(b)) | ||
} |
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,56 @@ | ||
package composectl | ||
|
||
import ( | ||
"fmt" | ||
"github.com/foundriesio/composeapp/pkg/compose" | ||
"github.com/foundriesio/composeapp/pkg/compose/v1" | ||
"github.com/spf13/cobra" | ||
"path" | ||
) | ||
|
||
var ( | ||
manifestCmd = &cobra.Command{ | ||
Use: "manifest", | ||
Short: "manifest <ref>", | ||
Long: ``, | ||
Args: cobra.ExactArgs(1), | ||
} | ||
) | ||
|
||
type ( | ||
manifestOptions struct { | ||
SrcStorePath *string | ||
Locally *bool | ||
} | ||
) | ||
|
||
func init() { | ||
opts := manifestOptions{} | ||
|
||
opts.SrcStorePath = manifestCmd.Flags().StringP("source-store-path", "l", "", | ||
"A path to the source store root directory") | ||
opts.Locally = manifestCmd.Flags().BoolP("local", "", false, | ||
"Print manifest of app stored locally") | ||
manifestCmd.Run = func(cmd *cobra.Command, args []string) { | ||
doOutputManifest(cmd, args, &opts) | ||
} | ||
|
||
showCmd.AddCommand(manifestCmd) | ||
} | ||
|
||
func doOutputManifest(cmd *cobra.Command, args []string, opts *manifestOptions) { | ||
if *opts.Locally && len(*opts.SrcStorePath) == 0 { | ||
opts.SrcStorePath = &config.StoreRoot | ||
} | ||
var blobProvider compose.BlobProvider | ||
if len(*opts.SrcStorePath) > 0 { | ||
blobProvider = compose.NewStoreBlobProvider(path.Join(*opts.SrcStorePath, "blobs", "sha256")) | ||
} else { | ||
authorizer := compose.NewRegistryAuthorizer(config.DockerCfg) | ||
resolver := compose.NewResolver(authorizer, config.ConnectTime) | ||
blobProvider = compose.NewRemoteBlobProvider(resolver) | ||
} | ||
b, err := compose.ReadBlobWithReadLimit(cmd.Context(), blobProvider, args[0], v1.AppManifestMaxSize) | ||
DieNotNil(err) | ||
fmt.Printf("%s\n", string(b)) | ||
} |
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,14 @@ | ||
package composectl | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var showCmd = &cobra.Command{ | ||
Use: "show", | ||
Short: "output app manifest or compose file", | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(showCmd) | ||
} |
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