mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-28 03:53:33 +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
|
machines []string
|
||||||
memory dockeropts.MemBytes
|
memory dockeropts.MemBytes
|
||||||
mode string
|
mode string
|
||||||
|
shmSize dockeropts.MemBytes
|
||||||
name string
|
name string
|
||||||
privileged bool
|
privileged bool
|
||||||
publish []string
|
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 "+
|
"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)")
|
"multiple times or as a comma-separated list of machine names. (default is any suitable machine)")
|
||||||
cmd.Flags().VarP(&opts.memory, "memory", "",
|
cmd.Flags().VarP(&opts.memory, "memory", "",
|
||||||
"Maximum amount of memory a service container can use. Value is a positive integer with optional unit suffix "+
|
"Maximum amount of memory a service container can use. Value is a positive integer with optional unit suffix (b, k, m, g).\n"+
|
||||||
"(b, k, m, g). Default unit is bytes if no suffix specified.\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)")
|
"Examples: 1073741824, 1024m, 1g (all equal 1 gibibyte)")
|
||||||
cmd.Flags().StringVarP(&opts.name, "name", "n", "",
|
cmd.Flags().StringVarP(&opts.name, "name", "n", "",
|
||||||
"Assign a name to the service. A random name is generated if not specified.")
|
"Assign a name to the service. A random name is generated if not specified.")
|
||||||
@@ -226,6 +231,7 @@ func prepareServiceSpec(opts runOptions) (api.ServiceSpec, error) {
|
|||||||
Resources: api.ContainerResources{
|
Resources: api.ContainerResources{
|
||||||
CPU: opts.cpu.Value(),
|
CPU: opts.cpu.Value(),
|
||||||
Memory: opts.memory.Value(),
|
Memory: opts.memory.Value(),
|
||||||
|
SharedMemory: opts.shmSize.Value(),
|
||||||
Ulimits: ulimits,
|
Ulimits: ulimits,
|
||||||
},
|
},
|
||||||
User: opts.user,
|
User: opts.user,
|
||||||
|
|||||||
@@ -642,6 +642,7 @@ func (s *Server) CreateServiceContainer(
|
|||||||
RestartPolicy: container.RestartPolicy{
|
RestartPolicy: container.RestartPolicy{
|
||||||
Name: container.RestartPolicyUnlessStopped,
|
Name: container.RestartPolicyUnlessStopped,
|
||||||
},
|
},
|
||||||
|
ShmSize: spec.Container.Resources.SharedMemory,
|
||||||
Sysctls: spec.Container.Sysctls,
|
Sysctls: spec.Container.Sysctls,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ type ContainerResources struct {
|
|||||||
Devices []DeviceMapping
|
Devices []DeviceMapping
|
||||||
// DeviceReservations requests for access to things like GPUs.
|
// DeviceReservations requests for access to things like GPUs.
|
||||||
DeviceReservations []container.DeviceRequest
|
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 defines the resource limits for the container.
|
||||||
Ulimits map[string]Ulimit
|
Ulimits map[string]Ulimit
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -177,6 +177,7 @@ func resourcesFromCompose(service types.ServiceConfig) api.ContainerResources {
|
|||||||
CPU: int64(service.CPUS * 1e9),
|
CPU: int64(service.CPUS * 1e9),
|
||||||
Memory: int64(service.MemLimit),
|
Memory: int64(service.MemLimit),
|
||||||
MemoryReservation: int64(service.MemReservation),
|
MemoryReservation: int64(service.MemReservation),
|
||||||
|
SharedMemory: int64(service.ShmSize),
|
||||||
Ulimits: ulimitsFromCompose(service.Ulimits),
|
Ulimits: ulimitsFromCompose(service.Ulimits),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -133,6 +133,7 @@ func TestServiceSpecFromCompose(t *testing.T) {
|
|||||||
CPU: 0.5 * api.Core,
|
CPU: 0.5 * api.Core,
|
||||||
Memory: 100 * units.MiB,
|
Memory: 100 * units.MiB,
|
||||||
MemoryReservation: 50 * units.MiB,
|
MemoryReservation: 50 * units.MiB,
|
||||||
|
SharedMemory: 256 * units.MiB,
|
||||||
Ulimits: map[string]api.Ulimit{
|
Ulimits: map[string]api.Ulimit{
|
||||||
"nofile": {Soft: 20000, Hard: 40000},
|
"nofile": {Soft: 20000, Hard: 40000},
|
||||||
"nproc": {Soft: 65535, Hard: 65535},
|
"nproc": {Soft: 65535, Hard: 65535},
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ services:
|
|||||||
max-file: 3
|
max-file: 3
|
||||||
mem_limit: 100M
|
mem_limit: 100M
|
||||||
mem_reservation: 50M
|
mem_reservation: 50M
|
||||||
|
shm_size: 268435456
|
||||||
privileged: true
|
privileged: true
|
||||||
pull_policy: always
|
pull_policy: always
|
||||||
scale: 3
|
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` |
|
| `pull_policy` | ✅ Supported | `always`, `missing`, `never` |
|
||||||
| `secrets` | ❌ Not supported | Use configs or environment variables |
|
| `secrets` | ❌ Not supported | Use configs or environment variables |
|
||||||
| `security_opt` | ❌ Not supported | |
|
| `security_opt` | ❌ Not supported | |
|
||||||
|
| `shm_size` | ✅ Supported | Shared memory size |
|
||||||
| `stop_grace_period` | ✅ Supported | Time to wait after SIGTERM before SIGKILL |
|
| `stop_grace_period` | ✅ Supported | Time to wait after SIGTERM before SIGKILL |
|
||||||
| `storage_opt` | ❌ Not supported | |
|
| `storage_opt` | ❌ Not supported | |
|
||||||
| `sysctls` | ✅ Supported | Namespaced kernel parameters |
|
| `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.
|
Format: VAR=value or just VAR to use the value from the local environment.
|
||||||
-h, --help help for run
|
-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)
|
-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)
|
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")
|
--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.
|
-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
|
-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")
|
--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)
|
--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.
|
--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.
|
Format: type=soft_limit[:hard_limit]. If hard limit is not specified, soft limit is used for both.
|
||||||
Examples:
|
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.
|
Format: VAR=value or just VAR to use the value from the local environment.
|
||||||
-h, --help help for run
|
-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)
|
-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)
|
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")
|
--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.
|
-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
|
-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")
|
--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)
|
--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.
|
--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.
|
Format: type=soft_limit[:hard_limit]. If hard limit is not specified, soft limit is used for both.
|
||||||
Examples:
|
Examples:
|
||||||
|
|||||||
Reference in New Issue
Block a user