docker-storage-gc 3.5.3 → 3.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.versionbot/CHANGELOG.yml +25 -1
- package/CHANGELOG.md +6 -0
- package/build/docker-event-stream.js +3 -5
- package/build/docker-image-tree.js +2 -2
- package/build/docker.js +4 -26
- package/lib/docker-event-stream.coffee +2 -6
- package/lib/docker-image-tree.coffee +3 -1
- package/lib/docker.coffee +3 -22
- package/package.json +4 -4
- package/test/index.coffee +11 -5
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
- commits:
|
|
2
|
+
- subject: Run tests using dind to avoid interactions with existing images
|
|
3
|
+
hash: ee161f87df98729d935c47c7c2a9f20d72a39e46
|
|
4
|
+
body: ""
|
|
5
|
+
footer:
|
|
6
|
+
Change-type: patch
|
|
7
|
+
change-type: patch
|
|
8
|
+
author: Pagan Gazzard
|
|
9
|
+
- subject: Only default the mtime to "now" for unrecognized images rather than old
|
|
10
|
+
hash: 134083f6655449470bc92438a94e79b11b6c1461
|
|
11
|
+
body: |
|
|
12
|
+
This avoids issues where images that existed before the garbage
|
|
13
|
+
collector was attached would always have their mtime set to "now" and
|
|
14
|
+
be avoided for removal. Instead we now only do it for images we haven't
|
|
15
|
+
seen which should only be the case for newly added images which haven't
|
|
16
|
+
yet had an mtime added but shortly will do, in which case `now` is a
|
|
17
|
+
good approximation
|
|
18
|
+
footer:
|
|
19
|
+
Change-type: patch
|
|
20
|
+
change-type: patch
|
|
21
|
+
author: Pagan Gazzard
|
|
22
|
+
version: 3.5.4
|
|
23
|
+
title: ""
|
|
24
|
+
date: 2023-08-01T13:38:01.904Z
|
|
1
25
|
- commits:
|
|
2
26
|
- subject: Add typings
|
|
3
27
|
hash: 15a645990da1f763088a843c9a8876b4b5cddff8
|
|
@@ -8,7 +32,7 @@
|
|
|
8
32
|
author: Pagan Gazzard
|
|
9
33
|
version: 3.5.3
|
|
10
34
|
title: ""
|
|
11
|
-
date: 2023-03-27T16:
|
|
35
|
+
date: 2023-03-27T16:36:50.392Z
|
|
12
36
|
- commits:
|
|
13
37
|
- subject: Replace balenaCI with flowzone
|
|
14
38
|
hash: 1f5029fed1b1d7713665274949f2c8badb6d4f0f
|
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file
|
|
|
4
4
|
automatically by Versionist. DO NOT EDIT THIS FILE MANUALLY!
|
|
5
5
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
|
6
6
|
|
|
7
|
+
# v3.5.4
|
|
8
|
+
## (2023-08-01)
|
|
9
|
+
|
|
10
|
+
* Run tests using dind to avoid interactions with existing images [Pagan Gazzard]
|
|
11
|
+
* Only default the mtime to "now" for unrecognized images rather than old [Pagan Gazzard]
|
|
12
|
+
|
|
7
13
|
# v3.5.3
|
|
8
14
|
## (2023-03-27)
|
|
9
15
|
|
|
@@ -19,11 +19,9 @@
|
|
|
19
19
|
}).then(function(images) {
|
|
20
20
|
var i, image, layer_mtimes, len;
|
|
21
21
|
layer_mtimes = {};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
layer_mtimes[image.Id] = 0;
|
|
26
|
-
}
|
|
22
|
+
for (i = 0, len = images.length; i < len; i++) {
|
|
23
|
+
image = images[i];
|
|
24
|
+
layer_mtimes[image.Id] = 0;
|
|
27
25
|
}
|
|
28
26
|
return es.pipeline(JSONStream.parse(), es.mapSync(function(arg) {
|
|
29
27
|
var from, id, status, timeNano;
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
};
|
|
51
51
|
|
|
52
52
|
exports.createTree = createTree = function(images, containers, layer_mtimes) {
|
|
53
|
-
var i, image, len, name, node, now, parent, parentId, root, tree, usedImageIds;
|
|
53
|
+
var i, image, len, name, node, now, parent, parentId, ref, root, tree, usedImageIds;
|
|
54
54
|
now = Date.now() * Math.pow(10, 6);
|
|
55
55
|
usedImageIds = new Set(_(containers).map('ImageID'));
|
|
56
56
|
tree = {};
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
node.repoTags = saneRepoAttrs(image.RepoTags);
|
|
64
64
|
node.repoDigests = saneRepoAttrs(image.RepoDigests);
|
|
65
65
|
node.size = image.Size;
|
|
66
|
-
node.mtime = getMtime(node, layer_mtimes)
|
|
66
|
+
node.mtime = (ref = getMtime(node, layer_mtimes)) != null ? ref : now;
|
|
67
67
|
node.isUsedByAContainer = usedImageIds.has(image.Id);
|
|
68
68
|
parent.children[image.Id] = node;
|
|
69
69
|
}
|
package/build/docker.js
CHANGED
|
@@ -15,35 +15,13 @@
|
|
|
15
15
|
url = require('url');
|
|
16
16
|
|
|
17
17
|
getDockerConnectOpts = function(hostObj) {
|
|
18
|
-
var certs;
|
|
19
18
|
if (!_.isEmpty(hostObj)) {
|
|
20
19
|
return Promise.resolve(hostObj);
|
|
21
20
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return Promise.map(certs, function(c) {
|
|
27
|
-
return fs.readFile(c, 'utf-8');
|
|
28
|
-
}).then(function(arg) {
|
|
29
|
-
var ca, cert, key, parsed;
|
|
30
|
-
ca = arg[0], cert = arg[1], key = arg[2];
|
|
31
|
-
parsed = url.parse(process.env.DOCKER_HOST);
|
|
32
|
-
return {
|
|
33
|
-
host: 'https://' + parsed.hostname,
|
|
34
|
-
port: parsed.port,
|
|
35
|
-
ca: ca,
|
|
36
|
-
cert: cert,
|
|
37
|
-
key: key,
|
|
38
|
-
Promise: Promise
|
|
39
|
-
};
|
|
40
|
-
});
|
|
41
|
-
} else {
|
|
42
|
-
return Promise.resolve({
|
|
43
|
-
socketPath: '/var/run/docker.sock',
|
|
44
|
-
Promise: Promise
|
|
45
|
-
});
|
|
46
|
-
}
|
|
21
|
+
return Promise.resolve({
|
|
22
|
+
socketPath: '/var/run/docker.sock',
|
|
23
|
+
Promise: Promise
|
|
24
|
+
});
|
|
47
25
|
};
|
|
48
26
|
|
|
49
27
|
exports.getDocker = function(hostObj) {
|
|
@@ -17,12 +17,8 @@ exports.parseEventStream = parseEventStream = (docker) ->
|
|
|
17
17
|
# If we've never seen the layer used then it's likely created before we started
|
|
18
18
|
# listening and so set the last used time to 0 as we know it should be older than
|
|
19
19
|
# anything we've seen
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
# existing images and the tests will break
|
|
23
|
-
if ! process.env.LOCAL_TESTS
|
|
24
|
-
for image in images
|
|
25
|
-
layer_mtimes[image.Id] = 0
|
|
20
|
+
for image in images
|
|
21
|
+
layer_mtimes[image.Id] = 0
|
|
26
22
|
|
|
27
23
|
return es.pipeline(
|
|
28
24
|
JSONStream.parse()
|
|
@@ -37,7 +37,9 @@ exports.createTree = createTree = (images, containers, layer_mtimes) ->
|
|
|
37
37
|
node.repoTags = saneRepoAttrs(image.RepoTags)
|
|
38
38
|
node.repoDigests = saneRepoAttrs(image.RepoDigests)
|
|
39
39
|
node.size = image.Size
|
|
40
|
-
|
|
40
|
+
# If we haven't seen the image at all then assume it is brand new and default it's
|
|
41
|
+
# mtime to `now` to avoid removing it
|
|
42
|
+
node.mtime = getMtime(node, layer_mtimes) ? now
|
|
41
43
|
node.isUsedByAContainer = usedImageIds.has(image.Id)
|
|
42
44
|
parent.children[image.Id] = node
|
|
43
45
|
|
package/lib/docker.coffee
CHANGED
|
@@ -6,28 +6,9 @@ fs = require 'mz/fs'
|
|
|
6
6
|
url = require 'url'
|
|
7
7
|
|
|
8
8
|
getDockerConnectOpts = (hostObj) ->
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
# Detect circleCi build
|
|
13
|
-
if process.env.CIRCLECI?
|
|
14
|
-
certs = ['ca.pem', 'cert.pem', 'key.pem'].map((file) -> path.join(process.env.DOCKER_CERT_PATH, file))
|
|
15
|
-
|
|
16
|
-
Promise.map(certs, (c) -> fs.readFile(c, 'utf-8'))
|
|
17
|
-
.then ([ca, cert, key]) ->
|
|
18
|
-
|
|
19
|
-
parsed = url.parse(process.env.DOCKER_HOST)
|
|
20
|
-
|
|
21
|
-
return {
|
|
22
|
-
host: 'https://' + parsed.hostname
|
|
23
|
-
port: parsed.port
|
|
24
|
-
ca
|
|
25
|
-
cert
|
|
26
|
-
key
|
|
27
|
-
Promise
|
|
28
|
-
}
|
|
29
|
-
else
|
|
30
|
-
return Promise.resolve({ socketPath: '/var/run/docker.sock', Promise })
|
|
9
|
+
if !_.isEmpty(hostObj)
|
|
10
|
+
return Promise.resolve(hostObj)
|
|
11
|
+
return Promise.resolve({ socketPath: '/var/run/docker.sock', Promise })
|
|
31
12
|
|
|
32
13
|
exports.getDocker = (hostObj) ->
|
|
33
14
|
getDockerConnectOpts(hostObj)
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "docker-storage-gc",
|
|
3
|
-
"version": "3.5.
|
|
3
|
+
"version": "3.5.4",
|
|
4
4
|
"main": "build/index.js",
|
|
5
5
|
"types": "index.d.ts",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"lint": "resin-lint lib test tools",
|
|
8
|
-
"pretest": "npm run lint",
|
|
8
|
+
"pretest": "npm run lint && docker rm -vf docker-storage-gc-tests && docker run --privileged --name docker-storage-gc-tests -v /tmp/dind:/var/run/ -d docker:24.0.5-dind && sleep 5 && docker exec docker-storage-gc-tests chown $(id -u) /var/run/docker.sock",
|
|
9
9
|
"test": "mocha --compilers coffee:coffee-script/register test",
|
|
10
|
-
"
|
|
10
|
+
"posttest": "docker rm -vf docker-storage-gc-tests",
|
|
11
11
|
"prepare": "coffee -o build -c lib"
|
|
12
12
|
},
|
|
13
13
|
"author": "",
|
|
@@ -33,6 +33,6 @@
|
|
|
33
33
|
"timekeeper": "0.0.5"
|
|
34
34
|
},
|
|
35
35
|
"versionist": {
|
|
36
|
-
"publishedAt": "2023-
|
|
36
|
+
"publishedAt": "2023-08-01T13:38:02.081Z"
|
|
37
37
|
}
|
|
38
38
|
}
|
package/test/index.coffee
CHANGED
|
@@ -32,8 +32,14 @@ describe 'Garbage collection', ->
|
|
|
32
32
|
@dockerStorage = new DockerGC()
|
|
33
33
|
# Use either local or CI docker
|
|
34
34
|
Promise.join(
|
|
35
|
-
dockerUtils.getDocker({
|
|
36
|
-
|
|
35
|
+
dockerUtils.getDocker({
|
|
36
|
+
socketPath: '/tmp/dind/docker.sock',
|
|
37
|
+
Promise,
|
|
38
|
+
})
|
|
39
|
+
@dockerStorage.setDocker({
|
|
40
|
+
socketPath: '/tmp/dind/docker.sock',
|
|
41
|
+
Promise,
|
|
42
|
+
})
|
|
37
43
|
(docker) =>
|
|
38
44
|
@dockerStorage.setupMtimeStream()
|
|
39
45
|
@docker = docker
|
|
@@ -57,7 +63,7 @@ describe 'Garbage collection', ->
|
|
|
57
63
|
.then ->
|
|
58
64
|
dockerStorage.garbageCollect(1)
|
|
59
65
|
.then ->
|
|
60
|
-
promiseToBool(docker.getImage(
|
|
66
|
+
promiseToBool(docker.getImage(IMAGES[0]).inspect())
|
|
61
67
|
.then (image_found) ->
|
|
62
68
|
expect(image_found).to.be.false
|
|
63
69
|
|
|
@@ -68,7 +74,7 @@ describe 'Garbage collection', ->
|
|
|
68
74
|
|
|
69
75
|
pullAsync(docker, NONE_TAG_IMAGES[0])
|
|
70
76
|
.then ->
|
|
71
|
-
docker.getImage(NONE_TAG_IMAGES[0])
|
|
77
|
+
docker.getImage(NONE_TAG_IMAGES[0]).inspect()
|
|
72
78
|
.then ->
|
|
73
79
|
dockerStorage.garbageCollect(1)
|
|
74
80
|
.then ->
|
|
@@ -84,7 +90,7 @@ describe 'Garbage collection', ->
|
|
|
84
90
|
Promise.each NONE_TAG_IMAGES, (image) ->
|
|
85
91
|
pullAsync(docker, image)
|
|
86
92
|
.then ->
|
|
87
|
-
docker.getImage(NONE_TAG_IMAGES[0])
|
|
93
|
+
docker.getImage(NONE_TAG_IMAGES[0]).inspect()
|
|
88
94
|
.then ->
|
|
89
95
|
dockerStorage.garbageCollect(1)
|
|
90
96
|
.then ->
|