Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 70abeb3

Browse files
authored
Merge pull request #433 from yudai/volume_panic
Do not panic with null volume configurations
2 parents 1c4bd45 + 103d669 commit 70abeb3

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

docker/volume/volume.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,18 @@ func (v *Volume) create(ctx context.Context) error {
8181

8282
// NewVolume creates a new volume from the specified name and config.
8383
func NewVolume(projectName, name string, config *config.VolumeConfig, client client.VolumeAPIClient) *Volume {
84-
return &Volume{
85-
client: client,
86-
projectName: projectName,
87-
name: name,
88-
driver: config.Driver,
89-
driverOptions: config.DriverOpts,
90-
external: config.External.External,
84+
vol := &Volume{
85+
client: client,
86+
projectName: projectName,
87+
name: name,
9188
}
89+
if config != nil {
90+
vol.driver = config.Driver
91+
vol.driverOptions = config.DriverOpts
92+
vol.external = config.External.External
93+
94+
}
95+
return vol
9296
}
9397

9498
// Volumes holds a list of volume

docker/volume/volume_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,19 @@ func TestVolumesFromServices(t *testing.T) {
3030
},
3131
expectedError: false,
3232
},
33+
{
34+
volumeConfigs: map[string]*config.VolumeConfig{
35+
"vol1": nil,
36+
},
37+
services: map[string]*config.ServiceConfig{},
38+
expectedVolumes: []*Volume{
39+
{
40+
name: "vol1",
41+
projectName: "prj",
42+
},
43+
},
44+
expectedError: false,
45+
},
3346
}
3447

3548
for index, c := range cases {

project/project.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ func (p *Project) handleVolumeConfig() {
312312
}
313313

314314
vol, ok := p.VolumeConfigs[volume.Source]
315-
if !ok {
315+
if !ok || vol == nil {
316316
continue
317317
}
318318

0 commit comments

Comments
 (0)