Skip to content

Commit

Permalink
Support ulimits in docker stack deploy
Browse files Browse the repository at this point in the history
This is related to moby/moby#40639.

Signed-off-by: Albin Kerouanton <albin@akerouanton.name>
  • Loading branch information
akerouanton authored and thaJeztah committed Sep 10, 2020
1 parent a9158bd commit 8d4ec82
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
24 changes: 24 additions & 0 deletions cli/compose/convert/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/api/types/versions"
"github.com/docker/docker/client"
"github.com/docker/go-units"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -151,6 +152,7 @@ func Service(
Sysctls: service.Sysctls,
CapabilityAdd: capAdd,
CapabilityDrop: capDrop,
Ulimits: convertUlimits(service.Ulimits),
},
LogDriver: logDriver,
Resources: resources,
Expand Down Expand Up @@ -680,3 +682,25 @@ func convertCredentialSpec(namespace Namespace, spec composetypes.CredentialSpec
}
return &swarmCredSpec, nil
}

func convertUlimits(origUlimits map[string]*composetypes.UlimitsConfig) []*units.Ulimit {
ulimits := make([]*units.Ulimit, 0, len(origUlimits))

for name, u := range origUlimits {
ulimit := &units.Ulimit{
Name: name,
}

if u.Single != 0 {
ulimit.Soft = int64(u.Single)
ulimit.Hard = int64(u.Single)
} else {
ulimit.Soft = int64(u.Soft)
ulimit.Hard = int64(u.Hard)
}

ulimits = append(ulimits, ulimit)
}

return ulimits
}
1 change: 0 additions & 1 deletion cli/compose/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ var UnsupportedProperties = []string{
"restart",
"security_opt",
"shm_size",
"ulimits",
"userns_mode",
}

Expand Down

0 comments on commit 8d4ec82

Please # to comment.