diff --git a/pkg/container/docker.go b/pkg/container/docker.go index bd70939..b6bca91 100644 --- a/pkg/container/docker.go +++ b/pkg/container/docker.go @@ -22,6 +22,7 @@ import ( "os" "strconv" "strings" + "syscall" "time" "github.com/docker/docker/api/types" @@ -112,6 +113,31 @@ func (r *DockerRunner) Start(c *Container) (*ContainerStatus, error) { Target: m.ContainerPath, } } + if c.Sound { + level.Debug(r.Logger).Log("msg", "enabling sound") + hostConfig.Devices = append(hostConfig.Devices, container.DeviceMapping{ + PathOnHost: "/dev/snd", + PathInContainer: "/dev/snd", + CgroupPermissions: "rwm", + }) + // // /dev/snd gid + fi, err := os.Stat("/dev/snd/seq") + if err != nil { + return nil, fmt.Errorf("couldn't stat /dev/snd: %w", err) + } + hostConfig.GroupAdd = []string{fmt.Sprintf("%d", fi.Sys().(*syscall.Stat_t).Gid)} + hostConfig.Mounts = append(hostConfig.Mounts, mount.Mount{ + Type: mount.TypeBind, + Source: "/etc/group", + Target: "/etc/group", + ReadOnly: true, + }, mount.Mount{ + Type: mount.TypeBind, + Source: "/usr/share/alsa", + Target: "/usr/share/alsa", + ReadOnly: true, + }) + } level.Debug(r.Logger).Log("msg", "creating container", "config", fmt.Sprintf("%#v", config), "hostConfig", fmt.Sprintf("%#v", hostConfig)) dc, err := r.Client.ContainerCreate(ctx, config, hostConfig, nil, nil, "") if err != nil { diff --git a/pkg/container/runner.go b/pkg/container/runner.go index 1b7238c..e66cc10 100644 --- a/pkg/container/runner.go +++ b/pkg/container/runner.go @@ -97,6 +97,7 @@ type Container struct { Hostname string WorkingDir string IPCMode string + Sound bool // If true, the entrypoint of the image will be overridden. Only used for // `diambra agent test`. diff --git a/pkg/diambra/credentials.go b/pkg/diambra/credentials.go index 8357d64..659fd58 100644 --- a/pkg/diambra/credentials.go +++ b/pkg/diambra/credentials.go @@ -67,9 +67,6 @@ func EnsureCredentials(logger log.Logger, credPath string) error { if exists { var err error - if err != nil { - return fmt.Errorf("couldn't create client: %w", err) - } user, err := dc.User() if err == nil { level.Info(logger).Log("msg", "logged in", "user", user.Username) diff --git a/pkg/diambra/diambra.go b/pkg/diambra/diambra.go index 8ceb895..c9c18ec 100644 --- a/pkg/diambra/diambra.go +++ b/pkg/diambra/diambra.go @@ -265,6 +265,7 @@ func newEnvContainer(config *EnvConfig, envID, randomSeed int) (*container.Conta container.NewBindMount(config.CredPath, "/tmp/.diambra/credentials"), container.NewBindMount(config.RomsPath, "/opt/diambraArena/roms"), }, + Sound: args.Sound, } c.BindMounts = append(c.BindMounts, config.Mounts...) @@ -276,6 +277,7 @@ func newEnvContainer(config *EnvConfig, envID, randomSeed int) (*container.Conta if config.SeccompProfile != "" { c.SecurityOpt = []string{"seccomp=" + config.SeccompProfile} } + return c, nil }