mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 11:03:34 +00:00
feat(compose): support stdin_open and tty (#419)
* feat: support stdin_open and tty This can be useful to leave a container running without specifying a command like `sleep`, and probably in other situations as well. Signed-off-by: Miek Gieben <miek@miek.nl> * Complete full spec test case Signed-off-by: Miek Gieben <miek@miek.nl> * fix container log streaming for containers with TTY --------- Signed-off-by: Miek Gieben <miek@miek.nl> Co-authored-by: Pasha Sviderski <me@psviderski.name>
This commit is contained in:
co-authored by
Pasha Sviderski
parent
351698c280
commit
b7e224a1ef
@@ -265,6 +265,11 @@ type ContainerSpec struct {
|
||||
LogDriver *LogDriver
|
||||
// PidMode sets the PID namespace mode for the container. Currently only "" or "host" is supported.
|
||||
PidMode string
|
||||
// Tty allocates a pseudo-TTY and connects the container's standard streams to it.
|
||||
// Standard output and standard error share one stream.
|
||||
Tty bool
|
||||
// OpenStdin allocates standard input and keeps it open.
|
||||
OpenStdin bool
|
||||
// Privileged gives extended privileges to the container. This is a security risk and should be used with caution.
|
||||
Privileged bool
|
||||
// PullPolicy determines when to pull the image from the registry or use the image already available in the cluster.
|
||||
|
||||
@@ -54,6 +54,8 @@ func ServiceSpecFromCompose(project *types.Project, serviceName string) (api.Ser
|
||||
Image: service.Image,
|
||||
Init: service.Init,
|
||||
PidMode: service.Pid,
|
||||
Tty: service.Tty,
|
||||
OpenStdin: service.StdinOpen,
|
||||
Privileged: service.Privileged,
|
||||
PullPolicy: pullPolicy,
|
||||
Resources: resourcesFromCompose(service),
|
||||
|
||||
@@ -128,6 +128,8 @@ func TestServiceSpecFromCompose(t *testing.T) {
|
||||
},
|
||||
},
|
||||
PidMode: "host",
|
||||
Tty: true,
|
||||
OpenStdin: true,
|
||||
Privileged: true,
|
||||
PullPolicy: api.PullPolicyAlways,
|
||||
Resources: api.ContainerResources{
|
||||
|
||||
@@ -7,6 +7,8 @@ services:
|
||||
command: ["nginx", "updated", "command"]
|
||||
cpus: 0.5
|
||||
pid: host
|
||||
tty: true
|
||||
stdin_open: true
|
||||
deploy:
|
||||
update_config:
|
||||
order: stop-first
|
||||
|
||||
@@ -66,6 +66,26 @@ func TestEvalContainerSpecChange_ContainerPidMode(t *testing.T) {
|
||||
assert.Equal(t, ContainerNeedsRecreate, EvalContainerSpecChange(newSpec, currentSpec))
|
||||
}
|
||||
|
||||
func TestEvalContainerSpecChange_ContainerTty(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
currentSpec := api.ServiceSpec{
|
||||
Container: api.ContainerSpec{
|
||||
Image: "nginx:latest",
|
||||
},
|
||||
}
|
||||
newSpec := api.ServiceSpec{
|
||||
Container: api.ContainerSpec{
|
||||
Image: "nginx:latest",
|
||||
Tty: true,
|
||||
OpenStdin: true,
|
||||
},
|
||||
}
|
||||
|
||||
assert.Equal(t, ContainerNeedsRecreate, EvalContainerSpecChange(currentSpec, newSpec))
|
||||
assert.Equal(t, ContainerNeedsRecreate, EvalContainerSpecChange(newSpec, currentSpec))
|
||||
}
|
||||
|
||||
func TestEvalContainerSpecChange_ContainerResources(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user