Skip to content
Snippets Groups Projects
Commit c3d77887 authored by Kamil Trzcinski's avatar Kamil Trzcinski
Browse files

Optimize memory usage and add .gitlab-ci.yml

parent e29ca3bd
No related branches found
No related tags found
No related merge requests found
Pipeline #
image: golang:1.4
test:
script:
- go-wrapper download
- go-wrapper download gopkg.in/check.v1
- go -cover test
Loading
Loading
@@ -54,6 +54,7 @@ var opts = struct {
}
 
type DockerClient interface {
Ping() error
ListImages(opts docker.ListImagesOptions) ([]docker.APIImages, error)
ListContainers(opts docker.ListContainersOptions) ([]docker.APIContainers, error)
RemoveImage(name string) error
Loading
Loading
@@ -463,20 +464,26 @@ func runCleanupTool(c *cli.Context) {
logrus.Fatalln(err)
}
 
var dockerClient DockerClient
logrus.Infoln("Watching disk space...")
for {
client, err := docker_helpers.Connect(dockerCredentials, dockerAPIVersion)
if err != nil {
logrus.Warningln("Failed to connect to daemon:", err)
time.Sleep(opts.RetryInterval)
continue
}
if dockerClient == nil || dockerClient.Ping() != nil {
dockerClient = nil
 
customClient := CustomDockerClient{
Client: client,
client, err := docker_helpers.Connect(dockerCredentials, dockerAPIVersion)
if err != nil {
logrus.Warningln("Failed to connect to daemon:", err)
time.Sleep(opts.RetryInterval)
continue
}
dockerClient = &CustomDockerClient{
Client: client,
}
}
 
err = doCycle(&customClient, lowFreeSpace, expectedFreeSpace)
err = doCycle(dockerClient, lowFreeSpace, expectedFreeSpace)
if err == nil {
time.Sleep(opts.CheckInterval)
} else {
Loading
Loading
Loading
Loading
@@ -22,6 +22,10 @@ type MockDockerClient struct {
totalSpace uint64
}
 
func (c *MockDockerClient) Ping() error {
return c.error
}
func (c *MockDockerClient) RemoveImage(name string) error {
if c.error != nil {
return c.error
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment