Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions playground/local_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -648,11 +648,16 @@ func (d *LocalRunner) toDockerComposeService(s *Service) (map[string]interface{}

// create the bind volumes
for localPath, volumeName := range s.VolumesMapped {
volumeDirAbsPath, err := d.createVolume(s.Name, volumeName)
if err != nil {
return nil, err
// If the volume name is an absolute path, use it directly
if filepath.IsAbs(volumeName) {
volumes[volumeName] = localPath
} else {
volumeDirAbsPath, err := d.createVolume(s.Name, volumeName)
if err != nil {
return nil, err
}
volumes[volumeDirAbsPath] = localPath
}
volumes[volumeDirAbsPath] = localPath
}

volumesInLine := []string{}
Expand All @@ -671,6 +676,10 @@ func (d *LocalRunner) toDockerComposeService(s *Service) (map[string]interface{}
"labels": labels,
}

if s.Privileged {
service["privileged"] = true
}

if d.platform != "" {
service["platform"] = d.platform
}
Expand Down
20 changes: 20 additions & 0 deletions playground/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ type Service struct {
Tag string `json:"tag,omitempty"`
Image string `json:"image,omitempty"`
Entrypoint string `json:"entrypoint,omitempty"`
Privileged bool `json:"privileged,omitempty"`
}

type instance struct {
Expand Down Expand Up @@ -409,6 +410,11 @@ func (s *Service) WithArgs(args ...string) *Service {
return s
}

func (s *Service) WithPrivileged() *Service {
s.Privileged = true
return s
}

func (s *Service) WithVolume(name string, localPath string) *Service {
if s.VolumesMapped == nil {
s.VolumesMapped = make(map[string]string)
Expand All @@ -417,6 +423,20 @@ func (s *Service) WithVolume(name string, localPath string) *Service {
return s
}

// WithAbsoluteVolume adds a volume mapping using an absolute path on the host.
// This is useful for binding system paths like /var/run/docker.sock.
// The path must be absolute and will be used as-is without any modification.
func (s *Service) WithAbsoluteVolume(containerPath string, hostPath string) *Service {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is this used?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We used it in our own components in our fork, especially for the case when binding paths which are not in the project path ~/.playground/devnet (like i.e. /var/run/docker.sock).
It is not being used in the standard builder-playground but we thought it might be useful to have it there for projects which fork the builder-playground and add their own components to it, like we did.
But I also understand if it's not desired to keep it upstream. Feel free to either close or approve.

if !filepath.IsAbs(hostPath) {
panic(fmt.Sprintf("host path must be absolute: %s", hostPath))
}
if s.VolumesMapped == nil {
s.VolumesMapped = make(map[string]string)
}
s.VolumesMapped[containerPath] = hostPath
return s
}

func (s *Service) WithArtifact(localPath string, artifactName string) *Service {
if s.FilesMapped == nil {
s.FilesMapped = make(map[string]string)
Expand Down