From 662eb172414e8b86b57ddace02076dc39e31b55c Mon Sep 17 00:00:00 2001 From: Matthew Penner Date: Thu, 21 May 2020 14:53:00 -0600 Subject: [PATCH] Pass server mounts into docker --- server/environment_docker.go | 28 ++++++++++++++++++++-------- server/mount.go | 8 ++++++++ server/server.go | 32 +++++++++++++++++--------------- 3 files changed, 45 insertions(+), 23 deletions(-) create mode 100644 server/mount.go diff --git a/server/environment_docker.go b/server/environment_docker.go index aa0fa02..72a8b72 100644 --- a/server/environment_docker.go +++ b/server/environment_docker.go @@ -621,19 +621,31 @@ func (d *DockerEnvironment) Create() error { }, } + mounts := []mount.Mount{ + { + Target: "/home/container", + Source: d.Server.Filesystem.Path(), + Type: mount.TypeBind, + ReadOnly: false, + }, + } + + for _, m := range d.Server.Mounts { + mounts = append(mounts, mount.Mount{ + Type: mount.TypeBind, + + Source: m.Source, + Target: m.Target, + ReadOnly: m.ReadOnly, + }) + } + hostConf := &container.HostConfig{ PortBindings: d.portBindings(), // Configure the mounts for this container. First mount the server data directory // into the container as a r/w bind. - Mounts: []mount.Mount{ - { - Target: "/home/container", - Source: d.Server.Filesystem.Path(), - Type: mount.TypeBind, - ReadOnly: false, - }, - }, + Mounts: mounts, // Configure the /tmp folder mapping in containers. This is necessary for some // games that need to make use of it for downloads and other installation processes. diff --git a/server/mount.go b/server/mount.go new file mode 100644 index 0000000..9e1f8d2 --- /dev/null +++ b/server/mount.go @@ -0,0 +1,8 @@ +package server + +// Mount represents a Server Mount. +type Mount struct { + Target string `json:"target"` + Source string `json:"source"` + ReadOnly bool `json:"read_only"` +} diff --git a/server/server.go b/server/server.go index 82deffe..092f29a 100644 --- a/server/server.go +++ b/server/server.go @@ -41,27 +41,29 @@ type Server struct { // An array of environment variables that should be passed along to the running // server process. - EnvVars map[string]string `json:"environment" yaml:"environment"` + EnvVars map[string]string `json:"environment"` - Archiver Archiver `json:"-" yaml:"-"` - CrashDetection CrashDetection `json:"crash_detection" yaml:"crash_detection"` - Build BuildSettings `json:"build"` Allocations Allocations `json:"allocations"` - Environment Environment `json:"-" yaml:"-"` - Filesystem Filesystem `json:"-" yaml:"-"` - Resources ResourceUsage `json:"resources" yaml:"-"` + Build BuildSettings `json:"build"` + CrashDetection CrashDetection `json:"crash_detection"` + Mounts []Mount `json:"mounts"` + Resources ResourceUsage `json:"resources"` + + Archiver Archiver `json:"-"` + Environment Environment `json:"-"` + Filesystem Filesystem `json:"-"` Container struct { // Defines the Docker image that will be used for this server Image string `json:"image,omitempty"` // If set to true, OOM killer will be disabled on the server's Docker container. // If not present (nil) we will default to disabling it. - OomDisabled bool `default:"true" json:"oom_disabled" yaml:"oom_disabled"` + OomDisabled bool `default:"true" json:"oom_disabled"` } `json:"container,omitempty"` // Server cache used to store frequently requested information in memory and make // certain long operations return faster. For example, FS disk space usage. - Cache *cache.Cache `json:"-" yaml:"-"` + Cache *cache.Cache `json:"-"` // Events emitted by the server instance. emitter *EventBus @@ -81,25 +83,25 @@ type Server struct { type BuildSettings struct { // The total amount of memory in megabytes that this server is allowed to // use on the host system. - MemoryLimit int64 `json:"memory_limit" yaml:"memory"` + MemoryLimit int64 `json:"memory_limit"` // The amount of additional swap space to be provided to a container instance. Swap int64 `json:"swap"` // The relative weight for IO operations in a container. This is relative to other // containers on the system and should be a value between 10 and 1000. - IoWeight uint16 `json:"io_weight" yaml:"io"` + IoWeight uint16 `json:"io_weight"` // The percentage of CPU that this instance is allowed to consume relative to // the host. A value of 200% represents complete utilization of two cores. This // should be a value between 1 and THREAD_COUNT * 100. - CpuLimit int64 `json:"cpu_limit" yaml:"cpu"` + CpuLimit int64 `json:"cpu_limit"` // The amount of disk space in megabytes that a server is allowed to use. - DiskSpace int64 `json:"disk_space" yaml:"disk"` + DiskSpace int64 `json:"disk_space"` // Sets which CPU threads can be used by the docker instance. - Threads string `json:"threads" yaml:"threads"` + Threads string `json:"threads"` } // Converts the CPU limit for a server build into a number that can be better understood @@ -150,7 +152,7 @@ type Allocations struct { DefaultMapping struct { Ip string `json:"ip"` Port int `json:"port"` - } `json:"default" yaml:"default"` + } `json:"default"` // Mappings contains all of the ports that should be assigned to a given server // attached to the IP they correspond to.