Skip to content

Commit 73b4202

Browse files
authored
Merge pull request #658 from cloudfoundry/override-package-dir
Allow package cache dir to be overriden for create/delete env commands
2 parents 18a084e + 026e8a7 commit 73b4202

File tree

14 files changed

+81
-23
lines changed

14 files changed

+81
-23
lines changed

cmd/cmd.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,31 +72,31 @@ func (c Cmd) Execute() (cmdErr error) {
7272

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

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

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

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

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

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

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

102102
stage := boshui.NewStage(deps.UI, deps.Time, deps.Logger)

cmd/create_env_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ var _ = Describe("CreateEnvCmd", func() {
347347
deploymentStateService,
348348
fakeInstallationUUIDGenerator,
349349
filepath.Join("fake-install-dir"),
350+
"",
350351
)
351352
tempRootConfigurator := cmd.NewTempRootConfigurator(fs)
352353

@@ -418,7 +419,7 @@ var _ = Describe("CreateEnvCmd", func() {
418419
fakeInstallationParser.ParseManifest = installationManifest
419420

420421
installationPath := filepath.Join("fake-install-dir", "fake-installation-id")
421-
target := biinstall.NewTarget(installationPath)
422+
target := biinstall.NewTarget(installationPath, "")
422423

423424
installedJob := biinstall.NewInstalledJob(
424425
biinstall.RenderedJobRef{

cmd/deployment_deleter_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ cloud_provider:
193193
},
194194
}
195195

196-
target := biinstall.NewTarget(filepath.Join("fake-install-dir", "fake-installation-id"))
196+
target := biinstall.NewTarget(filepath.Join("fake-install-dir", "fake-installation-id"), "")
197197
mockInstallerFactory.EXPECT().NewInstaller(target).Return(mockCpiInstaller).AnyTimes()
198198

199199
expectCPIInstall = mockCpiInstaller.EXPECT().Install(installationManifest, gomock.Any()).Do(func(_ biinstallmanifest.Manifest, stage boshui.Stage) {
@@ -229,6 +229,7 @@ cloud_provider:
229229
deploymentStateService,
230230
fakeInstallationUUIDGenerator,
231231
filepath.Join("fake-install-dir"),
232+
"",
232233
)
233234

234235
tempRootConfigurator := cmd.NewTempRootConfigurator(fs)
@@ -536,7 +537,7 @@ cloud_provider:
536537
},
537538
}
538539

539-
target := biinstall.NewTarget(filepath.Join("fake-install-dir", "fake-installation-id"))
540+
target := biinstall.NewTarget(filepath.Join("fake-install-dir", "fake-installation-id"), "")
540541
mockInstallerFactory.EXPECT().NewInstaller(target).Return(mockCpiInstaller).AnyTimes()
541542

542543
fakeInstallation := &fakecmd.FakeInstallation{}

cmd/env_factory.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ func NewEnvFactory(
7171
manifestVars boshtpl.Variables,
7272
manifestOp patch.Op,
7373
recreatePersistentDisks bool,
74+
packageDir string,
7475
) *envFactory {
7576
f := envFactory{
7677
deps: deps,
@@ -126,7 +127,7 @@ func NewEnvFactory(
126127
}
127128

128129
f.targetProvider = boshinst.NewTargetProvider(
129-
f.deploymentStateService, deps.UUIDGen, filepath.Join(workspaceRootPath, "installations"))
130+
f.deploymentStateService, deps.UUIDGen, filepath.Join(workspaceRootPath, "installations"), packageDir)
130131

131132
{
132133
diskRepo := biconfig.NewDiskRepo(f.deploymentStateService, deps.UUIDGen)

cmd/opts/opts.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ type CreateEnvOpts struct {
197197
StatePath string `long:"state" value-name:"PATH" description:"State file path"`
198198
Recreate bool `long:"recreate" description:"Recreate VM in deployment"`
199199
RecreatePersistentDisks bool `long:"recreate-persistent-disks" description:"Recreate persistent disks in the deployment"`
200+
PackageDir string `long:"package-dir" value-name:"DIR" description:"Package cache location override"`
200201
cmd
201202
}
202203

@@ -208,8 +209,9 @@ type DeleteEnvOpts struct {
208209
Args DeleteEnvArgs `positional-args:"true" required:"true"`
209210
VarFlags
210211
OpsFlags
211-
SkipDrain bool `long:"skip-drain" description:"Skip running drain and pre-stop scripts"`
212-
StatePath string `long:"state" value-name:"PATH" description:"State file path"`
212+
SkipDrain bool `long:"skip-drain" description:"Skip running drain and pre-stop scripts"`
213+
StatePath string `long:"state" value-name:"PATH" description:"State file path"`
214+
PackageDir string `long:"package-dir" value-name:"DIR" description:"Package cache location override"`
213215
cmd
214216
}
215217

cmd/opts/opts_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,12 @@ var _ = Describe("Opts", func() {
845845
))
846846
})
847847

848+
It("has --package-dir", func() {
849+
Expect(getStructTagForName("PackageDir", opts)).To(Equal(
850+
`long:"package-dir" value-name:"DIR" description:"Package cache location override"`,
851+
))
852+
})
853+
848854
It("has --recreate", func() {
849855
Expect(getStructTagForName("Recreate", opts)).To(Equal(
850856
`long:"recreate" description:"Recreate VM in deployment"`,
@@ -899,6 +905,12 @@ var _ = Describe("Opts", func() {
899905
))
900906
})
901907

908+
It("has --package-dir", func() {
909+
Expect(getStructTagForName("PackageDir", opts)).To(Equal(
910+
`long:"package-dir" value-name:"DIR" description:"Package cache location override"`,
911+
))
912+
})
913+
902914
It("has --skip-drain", func() {
903915
Expect(getStructTagForName("SkipDrain", opts)).To(Equal(
904916
`long:"skip-drain" description:"Skip running drain and pre-stop scripts"`,

cpi/release/installer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ var _ = Describe("Installer", func() {
4646
installStage = fakeui.NewFakeStage()
4747
installation = mocks.NewMockInstallation(mockCtrl)
4848

49-
target = biinstallation.NewTarget("fake-installation-path")
49+
target = biinstallation.NewTarget("fake-installation-path", "")
5050
mockInstallerFactory.EXPECT().NewInstaller(target).Return(mockInstaller).AnyTimes()
5151
expectInstall = mockInstaller.EXPECT().Install(installationManifest, gomock.Any())
5252
expectCleanup = mockInstaller.EXPECT().Cleanup(installation).Return(nil)

installation/installer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ var _ = Describe("Installer", func() {
5050
mockPackageCompiler = mock_install.NewMockPackageCompiler(mockCtrl)
5151
fakeExtractor = &blobextractfakes.FakeExtractor{}
5252

53-
target = NewTarget("fake-installation-path")
53+
target = NewTarget("fake-installation-path", "")
5454
installationManifest = biinstallmanifest.Manifest{
5555
Name: "fake-installation-name",
5656
Properties: biproperty.Map{},

installation/target.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ import (
55
)
66

77
type Target struct {
8-
path string
8+
path string
9+
packageDir string
910
}
1011

11-
func NewTarget(path string) Target {
12+
func NewTarget(path string, packageDir string) Target {
1213
return Target{
1314
path,
15+
packageDir,
1416
}
1517
}
1618

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

3335
func (t Target) PackagesPath() string {
34-
return filepath.Join(t.path, "packages")
36+
if t.packageDir != "" {
37+
return t.packageDir
38+
} else {
39+
return filepath.Join(t.path, "packages")
40+
}
3541
}
3642

3743
func (t Target) JobsPath() string {

installation/target_provider.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,20 @@ type targetProvider struct {
1717
deploymentStateService biconfig.DeploymentStateService
1818
uuidGenerator boshuuid.Generator
1919
installationsRootPath string
20+
packageDir string
2021
}
2122

2223
func NewTargetProvider(
2324
deploymentStateService biconfig.DeploymentStateService,
2425
uuidGenerator boshuuid.Generator,
2526
installationsRootPath string,
27+
packageDir string,
2628
) TargetProvider {
2729
return &targetProvider{
2830
deploymentStateService: deploymentStateService,
2931
uuidGenerator: uuidGenerator,
3032
installationsRootPath: installationsRootPath,
33+
packageDir: packageDir,
3134
}
3235
}
3336

@@ -51,5 +54,5 @@ func (p *targetProvider) NewTarget() (Target, error) {
5154
}
5255
}
5356

54-
return NewTarget(filepath.Join(p.installationsRootPath, installationID)), nil
57+
return NewTarget(filepath.Join(p.installationsRootPath, installationID), p.packageDir), nil
5558
}

0 commit comments

Comments
 (0)