mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 11:03:34 +00:00
feat: add shm_size support in Compose and --shm-size flag for 'uc run' (closes #267)
This commit is contained in:
@@ -28,6 +28,7 @@ type runOptions struct {
|
||||
machines []string
|
||||
memory dockeropts.MemBytes
|
||||
mode string
|
||||
shmSize dockeropts.MemBytes
|
||||
name string
|
||||
privileged bool
|
||||
publish []string
|
||||
@@ -78,8 +79,12 @@ func NewRunCommand(groupID string) *cobra.Command {
|
||||
"Placement constraint by machine names, limiting which machines the service can run on. Can be specified "+
|
||||
"multiple times or as a comma-separated list of machine names. (default is any suitable machine)")
|
||||
cmd.Flags().VarP(&opts.memory, "memory", "",
|
||||
"Maximum amount of memory a service container can use. Value is a positive integer with optional unit suffix "+
|
||||
"(b, k, m, g). Default unit is bytes if no suffix specified.\n"+
|
||||
"Maximum amount of memory a service container can use. Value is a positive integer with optional unit suffix (b, k, m, g).\n"+
|
||||
"Default unit is bytes if no suffix specified.\n"+
|
||||
"Examples: 1073741824, 1024m, 1g (all equal 1 gibibyte)")
|
||||
cmd.Flags().VarP(&opts.shmSize, "shm-size", "",
|
||||
"Maximum amount of shared memory (mounted at /dev/shm) a service container can use. Value is a positive integer\n"+
|
||||
"with optional unit suffix (b, k, m, g). Default unit is bytes if no suffix specified.\n"+
|
||||
"Examples: 1073741824, 1024m, 1g (all equal 1 gibibyte)")
|
||||
cmd.Flags().StringVarP(&opts.name, "name", "n", "",
|
||||
"Assign a name to the service. A random name is generated if not specified.")
|
||||
@@ -224,9 +229,10 @@ func prepareServiceSpec(opts runOptions) (api.ServiceSpec, error) {
|
||||
Privileged: opts.privileged,
|
||||
PullPolicy: opts.pull,
|
||||
Resources: api.ContainerResources{
|
||||
CPU: opts.cpu.Value(),
|
||||
Memory: opts.memory.Value(),
|
||||
Ulimits: ulimits,
|
||||
CPU: opts.cpu.Value(),
|
||||
Memory: opts.memory.Value(),
|
||||
SharedMemory: opts.shmSize.Value(),
|
||||
Ulimits: ulimits,
|
||||
},
|
||||
User: opts.user,
|
||||
VolumeMounts: mounts,
|
||||
|
||||
@@ -642,6 +642,7 @@ func (s *Server) CreateServiceContainer(
|
||||
RestartPolicy: container.RestartPolicy{
|
||||
Name: container.RestartPolicyUnlessStopped,
|
||||
},
|
||||
ShmSize: spec.Container.Resources.SharedMemory,
|
||||
Sysctls: spec.Container.Sysctls,
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,8 @@ type ContainerResources struct {
|
||||
Devices []DeviceMapping
|
||||
// DeviceReservations requests for access to things like GPUs.
|
||||
DeviceReservations []container.DeviceRequest
|
||||
// SharedMemory is the size of the shared memory (in bytes) mounted at /dev/shm in the container.
|
||||
SharedMemory int64
|
||||
// Ulimits defines the resource limits for the container.
|
||||
Ulimits map[string]Ulimit
|
||||
}
|
||||
|
||||
@@ -177,6 +177,7 @@ func resourcesFromCompose(service types.ServiceConfig) api.ContainerResources {
|
||||
CPU: int64(service.CPUS * 1e9),
|
||||
Memory: int64(service.MemLimit),
|
||||
MemoryReservation: int64(service.MemReservation),
|
||||
SharedMemory: int64(service.ShmSize),
|
||||
Ulimits: ulimitsFromCompose(service.Ulimits),
|
||||
}
|
||||
|
||||
|
||||
@@ -133,6 +133,7 @@ func TestServiceSpecFromCompose(t *testing.T) {
|
||||
CPU: 0.5 * api.Core,
|
||||
Memory: 100 * units.MiB,
|
||||
MemoryReservation: 50 * units.MiB,
|
||||
SharedMemory: 256 * units.MiB,
|
||||
Ulimits: map[string]api.Ulimit{
|
||||
"nofile": {Soft: 20000, Hard: 40000},
|
||||
"nproc": {Soft: 65535, Hard: 65535},
|
||||
|
||||
@@ -34,6 +34,7 @@ services:
|
||||
max-file: 3
|
||||
mem_limit: 100M
|
||||
mem_reservation: 50M
|
||||
shm_size: 268435456
|
||||
privileged: true
|
||||
pull_policy: always
|
||||
scale: 3
|
||||
|
||||
@@ -43,6 +43,7 @@ If you rely on a specific Compose feature that is not supported by Uncloud, plea
|
||||
| `pull_policy` | ✅ Supported | `always`, `missing`, `never` |
|
||||
| `secrets` | ❌ Not supported | Use configs or environment variables |
|
||||
| `security_opt` | ❌ Not supported | |
|
||||
| `shm_size` | ✅ Supported | Shared memory size |
|
||||
| `stop_grace_period` | ✅ Supported | Time to wait after SIGTERM before SIGKILL |
|
||||
| `storage_opt` | ❌ Not supported | |
|
||||
| `sysctls` | ✅ Supported | Namespaced kernel parameters |
|
||||
|
||||
@@ -16,7 +16,8 @@ uc run IMAGE [COMMAND...] [flags]
|
||||
Format: VAR=value or just VAR to use the value from the local environment.
|
||||
-h, --help help for run
|
||||
-m, --machine strings Placement constraint by machine names, limiting which machines the service can run on. Can be specified multiple times or as a comma-separated list of machine names. (default is any suitable machine)
|
||||
--memory bytes Maximum amount of memory a service container can use. Value is a positive integer with optional unit suffix (b, k, m, g). Default unit is bytes if no suffix specified.
|
||||
--memory bytes Maximum amount of memory a service container can use. Value is a positive integer with optional unit suffix (b, k, m, g).
|
||||
Default unit is bytes if no suffix specified.
|
||||
Examples: 1073741824, 1024m, 1g (all equal 1 gibibyte)
|
||||
--mode string Replication mode of the service: either 'replicated' (a specified number of containers across the machines) or 'global' (one container on every machine). (default "replicated")
|
||||
-n, --name string Assign a name to the service. A random name is generated if not specified.
|
||||
@@ -31,6 +32,9 @@ uc run IMAGE [COMMAND...] [flags]
|
||||
-p 53:5353/udp@host Bind UDP port 5353 to host port 53
|
||||
--pull string Pull image from the registry before running service containers ('always', 'missing', 'never'). (default "missing")
|
||||
--replicas uint Number of containers to run for the service. Only valid for a replicated service. (default 1)
|
||||
--shm-size bytes Maximum amount of shared memory (mounted at /dev/shm) a service container can use. Value is a positive integer
|
||||
with optional unit suffix (b, k, m, g). Default unit is bytes if no suffix specified.
|
||||
Examples: 1073741824, 1024m, 1g (all equal 1 gibibyte)
|
||||
--ulimit strings Set resource limits for service containers. Can be specified multiple times.
|
||||
Format: type=soft_limit[:hard_limit]. If hard limit is not specified, soft limit is used for both.
|
||||
Examples:
|
||||
|
||||
@@ -16,7 +16,8 @@ uc service run IMAGE [COMMAND...] [flags]
|
||||
Format: VAR=value or just VAR to use the value from the local environment.
|
||||
-h, --help help for run
|
||||
-m, --machine strings Placement constraint by machine names, limiting which machines the service can run on. Can be specified multiple times or as a comma-separated list of machine names. (default is any suitable machine)
|
||||
--memory bytes Maximum amount of memory a service container can use. Value is a positive integer with optional unit suffix (b, k, m, g). Default unit is bytes if no suffix specified.
|
||||
--memory bytes Maximum amount of memory a service container can use. Value is a positive integer with optional unit suffix (b, k, m, g).
|
||||
Default unit is bytes if no suffix specified.
|
||||
Examples: 1073741824, 1024m, 1g (all equal 1 gibibyte)
|
||||
--mode string Replication mode of the service: either 'replicated' (a specified number of containers across the machines) or 'global' (one container on every machine). (default "replicated")
|
||||
-n, --name string Assign a name to the service. A random name is generated if not specified.
|
||||
@@ -31,6 +32,9 @@ uc service run IMAGE [COMMAND...] [flags]
|
||||
-p 53:5353/udp@host Bind UDP port 5353 to host port 53
|
||||
--pull string Pull image from the registry before running service containers ('always', 'missing', 'never'). (default "missing")
|
||||
--replicas uint Number of containers to run for the service. Only valid for a replicated service. (default 1)
|
||||
--shm-size bytes Maximum amount of shared memory (mounted at /dev/shm) a service container can use. Value is a positive integer
|
||||
with optional unit suffix (b, k, m, g). Default unit is bytes if no suffix specified.
|
||||
Examples: 1073741824, 1024m, 1g (all equal 1 gibibyte)
|
||||
--ulimit strings Set resource limits for service containers. Can be specified multiple times.
|
||||
Format: type=soft_limit[:hard_limit]. If hard limit is not specified, soft limit is used for both.
|
||||
Examples:
|
||||
|
||||
Reference in New Issue
Block a user