Skip to content

Commit

Permalink
WIP: package override path
Browse files Browse the repository at this point in the history
Signed-off-by: Ming Xiao <[email protected]>
  • Loading branch information
selzoc authored and mingxiao committed Aug 12, 2024
1 parent 18a084e commit 93c8182
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
8 changes: 4 additions & 4 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,31 +72,31 @@ func (c Cmd) Execute() (cmdErr error) {

case *CreateEnvOpts:
envProvider := func(manifestPath string, statePath string, vars boshtpl.Variables, op patch.Op) DeploymentPreparer {
return NewEnvFactory(deps, manifestPath, statePath, vars, op, opts.RecreatePersistentDisks).Preparer()
return NewEnvFactory(deps, manifestPath, statePath, vars, op, opts.RecreatePersistentDisks, opts.PackageDir).Preparer()
}

stage := boshui.NewStage(deps.UI, deps.Time, deps.Logger)
return NewCreateEnvCmd(deps.UI, envProvider).Run(stage, *opts)

case *DeleteEnvOpts:
envProvider := func(manifestPath string, statePath string, vars boshtpl.Variables, op patch.Op) DeploymentDeleter {
return NewEnvFactory(deps, manifestPath, statePath, vars, op, false).Deleter()
return NewEnvFactory(deps, manifestPath, statePath, vars, op, false, opts.PackageDir).Deleter()
}

stage := boshui.NewStage(deps.UI, deps.Time, deps.Logger)
return NewDeleteEnvCmd(deps.UI, envProvider).Run(stage, *opts)

case *StopEnvOpts:
envProvider := func(manifestPath string, statePath string, vars boshtpl.Variables, op patch.Op) DeploymentStateManager {
return NewEnvFactory(deps, manifestPath, statePath, vars, op, false).StateManager()
return NewEnvFactory(deps, manifestPath, statePath, vars, op, false, "").StateManager()
}

stage := boshui.NewStage(deps.UI, deps.Time, deps.Logger)
return NewStopEnvCmd(deps.UI, envProvider).Run(stage, *opts)

case *StartEnvOpts:
envProvider := func(manifestPath string, statePath string, vars boshtpl.Variables, op patch.Op) DeploymentStateManager {
return NewEnvFactory(deps, manifestPath, statePath, vars, op, false).StateManager()
return NewEnvFactory(deps, manifestPath, statePath, vars, op, false, "").StateManager()
}

stage := boshui.NewStage(deps.UI, deps.Time, deps.Logger)
Expand Down
3 changes: 2 additions & 1 deletion cmd/env_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func NewEnvFactory(
manifestVars boshtpl.Variables,
manifestOp patch.Op,
recreatePersistentDisks bool,
packageDir string,
) *envFactory {
f := envFactory{
deps: deps,
Expand Down Expand Up @@ -126,7 +127,7 @@ func NewEnvFactory(
}

f.targetProvider = boshinst.NewTargetProvider(
f.deploymentStateService, deps.UUIDGen, filepath.Join(workspaceRootPath, "installations"))
f.deploymentStateService, deps.UUIDGen, filepath.Join(workspaceRootPath, "installations"), packageDir)

{
diskRepo := biconfig.NewDiskRepo(f.deploymentStateService, deps.UUIDGen)
Expand Down
6 changes: 4 additions & 2 deletions cmd/opts/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ type CreateEnvOpts struct {
StatePath string `long:"state" value-name:"PATH" description:"State file path"`
Recreate bool `long:"recreate" description:"Recreate VM in deployment"`
RecreatePersistentDisks bool `long:"recreate-persistent-disks" description:"Recreate persistent disks in the deployment"`
PackageDir string `long:"package-dir" value-name:"DIR" description:"Overrides default package cache location"`
cmd
}

Expand All @@ -208,8 +209,9 @@ type DeleteEnvOpts struct {
Args DeleteEnvArgs `positional-args:"true" required:"true"`
VarFlags
OpsFlags
SkipDrain bool `long:"skip-drain" description:"Skip running drain and pre-stop scripts"`
StatePath string `long:"state" value-name:"PATH" description:"State file path"`
SkipDrain bool `long:"skip-drain" description:"Skip running drain and pre-stop scripts"`
StatePath string `long:"state" value-name:"PATH" description:"State file path"`
PackageDir string `long:"package-dir" value-name:"DIR" description:"Overrides default package cache location"`
cmd
}

Expand Down
12 changes: 9 additions & 3 deletions installation/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import (
)

type Target struct {
path string
path string
packageDir string
}

func NewTarget(path string) Target {
func NewTarget(path string, packageDir string) Target {
return Target{
path,
packageDir,
}
}

Expand All @@ -31,7 +33,11 @@ func (t Target) TemplatesIndexPath() string {
}

func (t Target) PackagesPath() string {
return filepath.Join(t.path, "packages")
if t.packageDir != "" {
return t.packageDir
} else {
return filepath.Join(t.path, "packages")
}
}

func (t Target) JobsPath() string {
Expand Down
5 changes: 4 additions & 1 deletion installation/target_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,20 @@ type targetProvider struct {
deploymentStateService biconfig.DeploymentStateService
uuidGenerator boshuuid.Generator
installationsRootPath string
packageDir string
}

func NewTargetProvider(
deploymentStateService biconfig.DeploymentStateService,
uuidGenerator boshuuid.Generator,
installationsRootPath string,
packageDir string,
) TargetProvider {
return &targetProvider{
deploymentStateService: deploymentStateService,
uuidGenerator: uuidGenerator,
installationsRootPath: installationsRootPath,
packageDir: packageDir,
}
}

Expand All @@ -51,5 +54,5 @@ func (p *targetProvider) NewTarget() (Target, error) {
}
}

return NewTarget(filepath.Join(p.installationsRootPath, installationID)), nil
return NewTarget(filepath.Join(p.installationsRootPath, installationID), p.packageDir), nil
}

0 comments on commit 93c8182

Please sign in to comment.