-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding new implementation for parsing volumen input when running on
darwin. This is important because docker 26 did a refactoring and safepath.Join is not available for darwin. This is a workaround for now Signed-off-by: Juan Bustamante <jbustamante@vmware.com>
- Loading branch information
1 parent
4163bbf
commit 3c6dc12
Showing
6 changed files
with
112 additions
and
27 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
//go:build linux || windows | ||
|
||
package client | ||
|
||
import ( | ||
"fmt" | ||
"runtime" | ||
"strings" | ||
|
||
"github.com/docker/docker/volume/mounts" | ||
"github.com/pkg/errors" | ||
|
||
"github.com/buildpacks/pack/internal/style" | ||
) | ||
|
||
func processVolumes(imgOS string, volumes []string) (processed []string, warnings []string, err error) { | ||
var parser mounts.Parser | ||
switch "windows" { | ||
case imgOS: | ||
parser = mounts.NewWindowsParser() | ||
case runtime.GOOS: | ||
parser = mounts.NewLCOWParser() | ||
default: | ||
parser = mounts.NewLinuxParser() | ||
} | ||
for _, v := range volumes { | ||
volume, err := parser.ParseMountRaw(v, "") | ||
if err != nil { | ||
return nil, nil, errors.Wrapf(err, "platform volume %q has invalid format", v) | ||
} | ||
|
||
sensitiveDirs := []string{"/cnb", "/layers"} | ||
if imgOS == "windows" { | ||
sensitiveDirs = []string{`c:/cnb`, `c:\cnb`, `c:/layers`, `c:\layers`} | ||
} | ||
for _, p := range sensitiveDirs { | ||
if strings.HasPrefix(strings.ToLower(volume.Spec.Target), p) { | ||
warnings = append(warnings, fmt.Sprintf("Mounting to a sensitive directory %s", style.Symbol(volume.Spec.Target))) | ||
} | ||
} | ||
|
||
processed = append(processed, fmt.Sprintf("%s:%s:%s", volume.Spec.Source, volume.Spec.Target, processMode(volume.Mode))) | ||
} | ||
return processed, warnings, nil | ||
} | ||
|
||
func processMode(mode string) string { | ||
if mode == "" { | ||
return "ro" | ||
} | ||
|
||
return mode | ||
} |
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,51 @@ | ||
package client | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/docker/cli/cli/compose/loader" | ||
"github.com/docker/cli/cli/compose/types" | ||
"github.com/pkg/errors" | ||
|
||
"github.com/buildpacks/pack/internal/style" | ||
) | ||
|
||
func processVolumes(imgOS string, volumes []string) (processed []string, warnings []string, err error) { | ||
for _, v := range volumes { | ||
volume, err := parseVolume(v) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
sensitiveDirs := []string{"/cnb", "/layers"} | ||
if imgOS == "windows" { | ||
sensitiveDirs = []string{`c:/cnb`, `c:\cnb`, `c:/layers`, `c:\layers`} | ||
} | ||
for _, p := range sensitiveDirs { | ||
if strings.HasPrefix(strings.ToLower(volume.Target), p) { | ||
warnings = append(warnings, fmt.Sprintf("Mounting to a sensitive directory %s", style.Symbol(volume.Target))) | ||
} | ||
} | ||
mode := "ro" | ||
if strings.HasSuffix(v, ":rw") && !volume.ReadOnly { | ||
mode = "rw" | ||
} | ||
processed = append(processed, fmt.Sprintf("%s:%s:%s", volume.Source, volume.Target, mode)) | ||
} | ||
return processed, warnings, nil | ||
} | ||
|
||
func parseVolume(volume string) (types.ServiceVolumeConfig, error) { | ||
// volume format: '<host path>:<target path>[:<options>]' | ||
split := strings.Split(volume, ":") | ||
if len(split) == 3 { | ||
if split[2] != "ro" && split[2] != "rw" && !strings.Contains(split[2], "volume-opt") { | ||
return types.ServiceVolumeConfig{}, errors.New(fmt.Sprintf("platform volume %q has invalid format: invalid mode: %s", volume, split[2])) | ||
} | ||
} | ||
config, err := loader.ParseVolume(volume) | ||
if err != nil { | ||
return config, errors.Wrapf(err, "platform volume %q has invalid format", volume) | ||
} | ||
return config, nil | ||
} |