mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-03-01 11:21:23 -05:00
cdbg: implement workspace / "-C" flag and "--bindir" (#2170)
This commit is contained in:
parent
9dcad0ed16
commit
bd26e6bae7
@ -11,6 +11,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@ -44,11 +45,12 @@ func newDeployCmd() *cobra.Command {
|
|||||||
If required, you can override the IP addresses that are used for a deployment by specifying "--ips" and a list of IP addresses.
|
If required, you can override the IP addresses that are used for a deployment by specifying "--ips" and a list of IP addresses.
|
||||||
Specifying --bootstrapper will upload the bootstrapper from the specified path.`,
|
Specifying --bootstrapper will upload the bootstrapper from the specified path.`,
|
||||||
RunE: runDeploy,
|
RunE: runDeploy,
|
||||||
Example: "cdbg deploy\ncdbg deploy --config /path/to/config\ncdbg deploy --bootstrapper /path/to/bootstrapper --ips 192.0.2.1,192.0.2.2,192.0.2.3 --config /path/to/config",
|
Example: "cdbg deploy\ncdbg deploy -C /path/to/workspace --bindir $(pwd)\ncdbg deploy -C /path/to/workspace --bootstrapper /path/to/bootstrapper --ips 192.0.2.1,192.0.2.2,192.0.2.3",
|
||||||
}
|
}
|
||||||
deployCmd.Flags().StringSlice("ips", nil, "override the ips that the bootstrapper will be uploaded to (defaults to ips from constellation config)")
|
deployCmd.Flags().StringSlice("ips", nil, "override the ips that the bootstrapper will be uploaded to (defaults to ips from constellation config)")
|
||||||
deployCmd.Flags().String("bootstrapper", "./bootstrapper", "override the path to the bootstrapper binary uploaded to instances")
|
deployCmd.Flags().String("bindir", "", "override the base path that binaries are read from")
|
||||||
deployCmd.Flags().String("upgrade-agent", "./upgrade-agent", "override the path to the upgrade-agent binary uploaded to instances")
|
deployCmd.Flags().String("bootstrapper", "bootstrapper", "override the path to the bootstrapper binary uploaded to instances")
|
||||||
|
deployCmd.Flags().String("upgrade-agent", "upgrade-agent", "override the path to the upgrade-agent binary uploaded to instances")
|
||||||
deployCmd.Flags().StringToString("info", nil, "additional info to be passed to the debugd, in the form --info key1=value1,key2=value2")
|
deployCmd.Flags().StringToString("info", nil, "additional info to be passed to the debugd, in the form --info key1=value1,key2=value2")
|
||||||
deployCmd.Flags().Int("verbosity", 0, logger.CmdLineVerbosityDescription)
|
deployCmd.Flags().Int("verbosity", 0, logger.CmdLineVerbosityDescription)
|
||||||
return deployCmd
|
return deployCmd
|
||||||
@ -60,10 +62,6 @@ func runDeploy(cmd *cobra.Command, _ []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
log := logger.New(logger.PlainLog, logger.VerbosityFromInt(verbosity))
|
log := logger.New(logger.PlainLog, logger.VerbosityFromInt(verbosity))
|
||||||
configName, err := cmd.Flags().GetString("config")
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("parsing config path argument: %w", err)
|
|
||||||
}
|
|
||||||
force, err := cmd.Flags().GetBool("force")
|
force, err := cmd.Flags().GetBool("force")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("getting force flag: %w", err)
|
return fmt.Errorf("getting force flag: %w", err)
|
||||||
@ -73,7 +71,7 @@ func runDeploy(cmd *cobra.Command, _ []string) error {
|
|||||||
fileHandler := file.NewHandler(fs)
|
fileHandler := file.NewHandler(fs)
|
||||||
streamer := streamer.New(fs)
|
streamer := streamer.New(fs)
|
||||||
transfer := filetransfer.New(log, streamer, filetransfer.ShowProgress)
|
transfer := filetransfer.New(log, streamer, filetransfer.ShowProgress)
|
||||||
constellationConfig, err := config.New(fileHandler, configName, attestationconfigapi.NewFetcher(), force)
|
constellationConfig, err := config.New(fileHandler, constants.ConfigFilename, attestationconfigapi.NewFetcher(), force)
|
||||||
var configValidationErr *config.ValidationError
|
var configValidationErr *config.ValidationError
|
||||||
if errors.As(err, &configValidationErr) {
|
if errors.As(err, &configValidationErr) {
|
||||||
cmd.PrintErrln(configValidationErr.LongMessage())
|
cmd.PrintErrln(configValidationErr.LongMessage())
|
||||||
@ -88,6 +86,10 @@ func deploy(cmd *cobra.Command, fileHandler file.Handler, constellationConfig *c
|
|||||||
transfer fileTransferer,
|
transfer fileTransferer,
|
||||||
log *logger.Logger,
|
log *logger.Logger,
|
||||||
) error {
|
) error {
|
||||||
|
binDir, err := cmd.Flags().GetString("bindir")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
bootstrapperPath, err := cmd.Flags().GetString("bootstrapper")
|
bootstrapperPath, err := cmd.Flags().GetString("bootstrapper")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -129,13 +131,13 @@ func deploy(cmd *cobra.Command, fileHandler file.Handler, constellationConfig *c
|
|||||||
|
|
||||||
files := []filetransfer.FileStat{
|
files := []filetransfer.FileStat{
|
||||||
{
|
{
|
||||||
SourcePath: bootstrapperPath,
|
SourcePath: prependBinDir(binDir, bootstrapperPath),
|
||||||
TargetPath: debugd.BootstrapperDeployFilename,
|
TargetPath: debugd.BootstrapperDeployFilename,
|
||||||
Mode: debugd.BinaryAccessMode,
|
Mode: debugd.BinaryAccessMode,
|
||||||
OverrideServiceUnit: "constellation-bootstrapper",
|
OverrideServiceUnit: "constellation-bootstrapper",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
SourcePath: upgradeAgentPath,
|
SourcePath: prependBinDir(binDir, upgradeAgentPath),
|
||||||
TargetPath: debugd.UpgradeAgentDeployFilename,
|
TargetPath: debugd.UpgradeAgentDeployFilename,
|
||||||
Mode: debugd.BinaryAccessMode,
|
Mode: debugd.BinaryAccessMode,
|
||||||
OverrideServiceUnit: "constellation-upgrade-agent",
|
OverrideServiceUnit: "constellation-upgrade-agent",
|
||||||
@ -158,6 +160,13 @@ func deploy(cmd *cobra.Command, fileHandler file.Handler, constellationConfig *c
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func prependBinDir(bindDir, binary string) string {
|
||||||
|
if len(bindDir) == 0 || filepath.IsAbs(binary) {
|
||||||
|
return binary
|
||||||
|
}
|
||||||
|
return filepath.Join(bindDir, binary)
|
||||||
|
}
|
||||||
|
|
||||||
type deployOnEndpointInput struct {
|
type deployOnEndpointInput struct {
|
||||||
debugdEndpoint string
|
debugdEndpoint string
|
||||||
files []filetransfer.FileStat
|
files []filetransfer.FileStat
|
||||||
|
@ -8,9 +8,9 @@ SPDX-License-Identifier: AGPL-3.0-only
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/edgelesssys/constellation/v2/internal/constants"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -20,10 +20,13 @@ func newRootCmd() *cobra.Command {
|
|||||||
Short: "Constellation debugging client",
|
Short: "Constellation debugging client",
|
||||||
Long: `cdbg is the constellation debugging client.
|
Long: `cdbg is the constellation debugging client.
|
||||||
It connects to Constellation instances running debugd and deploys a self-compiled version of the bootstrapper.`,
|
It connects to Constellation instances running debugd and deploys a self-compiled version of the bootstrapper.`,
|
||||||
|
PersistentPreRunE: preRunRoot,
|
||||||
}
|
}
|
||||||
cmd.PersistentFlags().String("config", constants.ConfigFilename, "Constellation config file")
|
cmd.PersistentFlags().StringP("workspace", "C", "", "path to the Constellation workspace")
|
||||||
cmd.PersistentFlags().Bool("force", false, "disables version validation errors - might result in corrupted clusters")
|
cmd.PersistentFlags().Bool("force", false, "disables version validation errors - might result in corrupted clusters")
|
||||||
|
|
||||||
|
must(cmd.MarkPersistentFlagDirname("workspace"))
|
||||||
|
|
||||||
cmd.AddCommand(newDeployCmd())
|
cmd.AddCommand(newDeployCmd())
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
@ -35,3 +38,28 @@ func Execute() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func preRunRoot(cmd *cobra.Command, _ []string) error {
|
||||||
|
cmd.SilenceUsage = true
|
||||||
|
|
||||||
|
workspace, err := cmd.Flags().GetString("workspace")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("getting workspace flag: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Change to workspace directory if set.
|
||||||
|
if workspace != "" {
|
||||||
|
if err := os.Chdir(workspace); err != nil {
|
||||||
|
return fmt.Errorf("changing from current directory to workspace %q: %w", workspace, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func must(err error) {
|
||||||
|
if err == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user