mirror of
https://github.com/tuna/tunasync.git
synced 2025-04-20 20:04:58 +00:00
docker: support memory limit
This commit is contained in:
parent
3ce5c2ede3
commit
f0ccdc47dc
@ -13,6 +13,7 @@ type dockerHook struct {
|
|||||||
image string
|
image string
|
||||||
volumes []string
|
volumes []string
|
||||||
options []string
|
options []string
|
||||||
|
memoryLimit MemBytes
|
||||||
}
|
}
|
||||||
|
|
||||||
func newDockerHook(p mirrorProvider, gCfg dockerConfig, mCfg mirrorConfig) *dockerHook {
|
func newDockerHook(p mirrorProvider, gCfg dockerConfig, mCfg mirrorConfig) *dockerHook {
|
||||||
@ -35,6 +36,7 @@ func newDockerHook(p mirrorProvider, gCfg dockerConfig, mCfg mirrorConfig) *dock
|
|||||||
image: mCfg.DockerImage,
|
image: mCfg.DockerImage,
|
||||||
volumes: volumes,
|
volumes: volumes,
|
||||||
options: options,
|
options: options,
|
||||||
|
memoryLimit: mCfg.MemoryLimit,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
units "github.com/docker/go-units"
|
||||||
|
|
||||||
"github.com/codeskyblue/go-sh"
|
"github.com/codeskyblue/go-sh"
|
||||||
. "github.com/smartystreets/goconvey/convey"
|
. "github.com/smartystreets/goconvey/convey"
|
||||||
@ -77,6 +78,7 @@ sleep 20
|
|||||||
volumes: []string{
|
volumes: []string{
|
||||||
fmt.Sprintf("%s:%s", cmdScript, "/bin/cmd.sh"),
|
fmt.Sprintf("%s:%s", cmdScript, "/bin/cmd.sh"),
|
||||||
},
|
},
|
||||||
|
memoryLimit: 512 * units.MiB,
|
||||||
}
|
}
|
||||||
provider.AddHook(d)
|
provider.AddHook(d)
|
||||||
So(provider.Docker(), ShouldNotBeNil)
|
So(provider.Docker(), ShouldNotBeNil)
|
||||||
|
@ -56,6 +56,10 @@ func newCmdJob(provider mirrorProvider, cmdAndArgs []string, workingDir string,
|
|||||||
kv := fmt.Sprintf("%s=%s", k, v)
|
kv := fmt.Sprintf("%s=%s", k, v)
|
||||||
args = append(args, "-e", kv)
|
args = append(args, "-e", kv)
|
||||||
}
|
}
|
||||||
|
// set memlimit
|
||||||
|
if d.memoryLimit != 0 {
|
||||||
|
args = append(args, "-m", fmt.Sprint(d.memoryLimit.Value()))
|
||||||
|
}
|
||||||
// apply options
|
// apply options
|
||||||
args = append(args, d.options...)
|
args = append(args, d.options...)
|
||||||
// apply image and command
|
// apply image and command
|
||||||
|
Loading…
x
Reference in New Issue
Block a user