Skip to content

Commit f8a8615

Browse files
authored
CR-19603-fix-vulns updated deps (#44)
* updated deps * updated version to `1.28.0`
1 parent 9922e7c commit f8a8615

File tree

9 files changed

+152
-245
lines changed

9 files changed

+152
-245
lines changed

Dockerfile

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
ARG DOCKER_VERSION=20.10.24
1+
ARG DOCKER_VERSION=24.0.5
22

33
# dind-cleaner
4-
FROM golang:1.16-alpine3.15 AS cleaner
4+
FROM golang:1.21-alpine3.18 AS cleaner
55

66
COPY cleaner/dind-cleaner/* /go/src/github.com/codefresh-io/dind-cleaner/
77
WORKDIR /go/src/github.com/codefresh-io/dind-cleaner/
@@ -15,11 +15,11 @@ RUN CGO_ENABLED=0 go build -o /usr/local/bin/dind-cleaner ./cmd && \
1515
rm -rf /go/*
1616

1717
# bolter
18-
FROM golang:1.19-alpine3.16 AS bolter
18+
FROM golang:1.21-alpine3.18 AS bolter
1919
RUN go install github.com/hasit/[email protected]
2020

2121
# node-exporter
22-
FROM quay.io/prometheus/node-exporter:v1.5.0 AS node-exporter
22+
FROM quay.io/prometheus/node-exporter:v1.6.1 AS node-exporter
2323

2424
# Main
2525
FROM docker:${DOCKER_VERSION}-dind

Dockerfile.bolter

-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@
22
FROM golang:1.12.6-alpine3.9
33
RUN apk add git
44
RUN go get -u github.com/hasit/bolter
5-

cleaner/dind-cleaner/cmd/main.go

+73-71
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ limitations under the License.
1717
package main
1818

1919
import (
20-
"time"
20+
"bufio"
2121
"flag"
2222
"os"
23-
"bufio"
24-
"github.com/golang/glog"
23+
"time"
24+
2525
"github.com/docker/docker/api/types"
2626
"github.com/docker/docker/client"
27+
"github.com/golang/glog"
2728
"golang.org/x/net/context"
2829
)
2930

@@ -34,70 +35,72 @@ func readFileLines(path string) ([]string, error) {
3435
}
3536
file, err := os.Open(path)
3637
if err != nil {
37-
return nil, err
38+
return nil, err
3839
}
3940
defer file.Close()
4041

4142
scanner := bufio.NewScanner(file)
4243
for scanner.Scan() {
43-
lines = append(lines, scanner.Text())
44+
lines = append(lines, scanner.Text())
4445
}
4546
return lines, scanner.Err()
4647
}
4748

4849
var dryRun *bool
50+
4951
const (
50-
cmdImages = "images"
51-
52-
statusFound = "found"
53-
statusRemoved = "removed"
54-
statusRetainedByList = "retainedByList"
55-
statusRetainedByDate = "retainedByDate"
56-
statusChildRetained = "childRetained"
57-
statusChildFailedToRemove = "childFailedToRemove"
58-
statusFailedToRemove = "failedToRemove"
52+
cmdImages = "images"
53+
54+
statusFound = "found"
55+
statusRemoved = "removed"
56+
statusRetainedByList = "retainedByList"
57+
statusRetainedByDate = "retainedByDate"
58+
statusChildRetained = "childRetained"
59+
statusChildFailedToRemove = "childFailedToRemove"
60+
statusFailedToRemove = "failedToRemove"
5961
)
6062

6163
func _stringInList(list []string, s string) bool {
6264
for _, a := range list {
63-
if a == s {
64-
return true
65-
}
66-
}
67-
return false
65+
if a == s {
66+
return true
67+
}
68+
}
69+
return false
6870
}
6971

7072
func cleanImages(retainedImagesList []string, retainPeriod int64) {
7173
glog.Infof("Entering cleanImages, length of retainedImagesList = %d", len(retainedImagesList))
7274
if os.Getenv("DOCKER_API_VERSION") == "" {
7375
os.Setenv("DOCKER_API_VERSION", "1.35")
7476
}
75-
76-
cli, err := client.NewEnvClient()
77+
78+
cli, err := client.NewClientWithOpts(
79+
client.FromEnv,
80+
)
7781
if err != nil {
7882
panic(err)
7983
}
8084

8185
type imageToCleanStruct = struct {
82-
ID string
83-
Created int64
84-
ParentID string
85-
status string
86-
tags []string
86+
ID string
87+
Created int64
88+
ParentID string
89+
status string
90+
tags []string
8791
childrenIDs map[string]string
88-
size int64
92+
size int64
8993
}
9094

91-
9295
/*
93-
Purpose: remove images starting from first child excluding ids in retainedImagesList
94-
Logic:
95-
1. get All images (with All=true)
96-
2. fill map of imageToCleanStruct - for each image fill its children in the map of [id]"status"
97-
3. find images with no children
98-
4. loop by found images with no children and delete them, then update childrenList of whole map of imageToCleanStruct.
99-
Skip deletion for images in retainedImagesList
100-
--- Repeat 3-4 until images to delete found
96+
Purpose: remove images starting from first child excluding ids in retainedImagesList
97+
Logic:
98+
1. get All images (with All=true)
99+
2. fill map of imageToCleanStruct - for each image fill its children in the map of [id]"status"
100+
3. find images with no children
101+
4. loop by found images with no children and delete them, then update childrenList of whole map of imageToCleanStruct.
102+
Skip deletion for images in retainedImagesList
103+
--- Repeat 3-4 until images to delete found
101104
102105
*/
103106

@@ -115,12 +118,12 @@ func cleanImages(retainedImagesList []string, retainPeriod int64) {
115118
images := make(map[string]*imageToCleanStruct)
116119
for _, img := range imagesFullList {
117120
images[img.ID] = &imageToCleanStruct{
118-
ID: img.ID,
119-
Created: img.Created,
120-
ParentID: img.ParentID,
121-
status: statusFound,
122-
tags: img.RepoTags,
123-
size: img.Size,
121+
ID: img.ID,
122+
Created: img.Created,
123+
ParentID: img.ParentID,
124+
status: statusFound,
125+
tags: img.RepoTags,
126+
size: img.Size,
124127
childrenIDs: make(map[string]string),
125128
}
126129
}
@@ -131,7 +134,7 @@ func cleanImages(retainedImagesList []string, retainPeriod int64) {
131134
parentImage, parentImageInList := images[img.ParentID]
132135
if parentImageInList {
133136
parentImage.childrenIDs[imageID] = statusFound
134-
}
137+
}
135138
}
136139
}
137140

@@ -164,8 +167,8 @@ func cleanImages(retainedImagesList []string, retainPeriod int64) {
164167
glog.Infof(" Skiping image %s - %v , it appears in retained list", imageID, images[imageID].tags)
165168
images[imageID].status = statusRetainedByList
166169
} else if retainPeriod > 0 && images[imageID].Created > 0 && images[imageID].Created < currentTs &&
167-
currentTs - images[imageID].Created < retainPeriod {
168-
170+
currentTs-images[imageID].Created < retainPeriod {
171+
169172
glog.Infof(" Skiping image %s - %v , its created more than retainPeriod %d seconds ago", imageID, images[imageID].tags, retainPeriod)
170173
images[imageID].status = statusRetainedByDate
171174
} else {
@@ -175,9 +178,9 @@ func cleanImages(retainedImagesList []string, retainPeriod int64) {
175178
if !*dryRun {
176179
_, err = cli.ImageRemove(ctx, imageID, types.ImageRemoveOptions{Force: true, PruneChildren: false})
177180
} else {
178-
glog.Infof( "DRY RUN - do not actually delete")
181+
glog.Infof("DRY RUN - do not actually delete")
179182
}
180-
183+
181184
if err == nil {
182185
glog.Infof(" image %s - %v has been deleted", imageID, images[imageID].tags)
183186
images[imageID].status = statusRemoved
@@ -187,17 +190,17 @@ func cleanImages(retainedImagesList []string, retainPeriod int64) {
187190
}
188191
}
189192

190-
glog.Infof(" setting image status to %s", images[imageID].status)
193+
glog.Infof(" setting image status to %s", images[imageID].status)
191194
for _, img := range images {
192195
if _, ok := img.childrenIDs[imageID]; ok {
193196
if images[imageID].status == statusRemoved {
194197
glog.Infof(" deleting the child from parent image %s - %v", img.ID, img.tags)
195198
delete(img.childrenIDs, imageID)
196-
} else if images[imageID].status == statusRetainedByList || images[imageID].status == statusRetainedByDate {
199+
} else if images[imageID].status == statusRetainedByList || images[imageID].status == statusRetainedByDate {
197200
glog.Infof(" setting child status %s for image %s - %v", images[imageID].status, img.ID, img.tags)
198201
img.childrenIDs[imageID] = images[imageID].status
199202
img.status = statusChildRetained
200-
203+
201204
} else if images[imageID].status == statusFailedToRemove {
202205
glog.Infof(" setting child status %s and deleting the from parent image %s - %v", images[imageID].status, img.ID, img.tags)
203206
delete(img.childrenIDs, imageID)
@@ -215,7 +218,7 @@ func cleanImages(retainedImagesList []string, retainPeriod int64) {
215218
for childID, childStatus := range img.childrenIDs {
216219
glog.Infof(" Child: %s - %s (grandchild retained)", childID, childStatus)
217220
}
218-
221+
219222
totalImagesSize += img.size
220223
switch img.status {
221224
case statusRemoved:
@@ -229,17 +232,17 @@ func cleanImages(retainedImagesList []string, retainPeriod int64) {
229232
}
230233
}
231234

232-
glog.Infof("\n-----------\n" +
233-
" total images shared size: %.3f Mb \n" +
234-
" removed shared size: %.3f Mb \n" +
235-
"retained shared by list size: %.3f Mb \n" +
236-
"retained shared by date size: %.3f Mb \n" +
237-
" failed to remove size: %.3f Mb ",
238-
float64(totalImagesSize)/1024/1024.0,
239-
float64(removedSize)/1024/1024.0,
240-
float64(retainedByListSize)/1024/1024.0,
241-
float64(retainedByDateSize)/1024/1024.0,
242-
float64(failedToRemoveSize)/1024/1024.0)
235+
glog.Infof("\n-----------\n"+
236+
" total images shared size: %.3f Mb \n"+
237+
" removed shared size: %.3f Mb \n"+
238+
"retained shared by list size: %.3f Mb \n"+
239+
"retained shared by date size: %.3f Mb \n"+
240+
" failed to remove size: %.3f Mb ",
241+
float64(totalImagesSize)/1024/1024.0,
242+
float64(removedSize)/1024/1024.0,
243+
float64(retainedByListSize)/1024/1024.0,
244+
float64(retainedByDateSize)/1024/1024.0,
245+
float64(failedToRemoveSize)/1024/1024.0)
243246
}
244247

245248
func main() {
@@ -254,18 +257,18 @@ Commands:
254257
flag.Set("v", "4")
255258
flag.Set("alsologtostderr", "true")
256259
validCommands := []string{"images"}
257-
if len(os.Args) < 2 {
260+
if len(os.Args) < 2 {
258261
glog.Errorf("%s", usage)
259262
os.Exit(2)
260-
} else if !_stringInList(validCommands,os.Args[1]) {
263+
} else if !_stringInList(validCommands, os.Args[1]) {
261264
glog.Errorf("Invalid command %s\n%s", os.Args[1], usage)
262265
os.Exit(2)
263266
}
264267

265268
imagesCommand := flag.NewFlagSet("images", flag.ExitOnError)
266269
retainedImagesListFile := imagesCommand.String("retained-images-file", "", "Retained images list file")
267270
imageRetainPeriod := imagesCommand.Int64("image-retain-period", 86400, "image retain period")
268-
271+
269272
dryRun = imagesCommand.Bool("dry-run", false, "dry run - only print actions")
270273

271274
switch os.Args[1] {
@@ -281,13 +284,12 @@ Commands:
281284
*dryRun = true
282285
}
283286

284-
285287
glog.Infof("\n----------------\n Started dind-cleaner")
286-
287-
glog.Infof("First verson - only image cleaner. " +
288-
"retainedImagesListFile = %s " +
289-
"retainedImagesPeriod = %d " +
290-
"dry-run = %t" , *retainedImagesListFile, *imageRetainPeriod, *dryRun)
288+
289+
glog.Infof("First verson - only image cleaner. "+
290+
"retainedImagesListFile = %s "+
291+
"retainedImagesPeriod = %d "+
292+
"dry-run = %t", *retainedImagesListFile, *imageRetainPeriod, *dryRun)
291293

292294
retainedImagesList, err := readFileLines(*retainedImagesListFile)
293295
if err != nil {

cleaner/dind-cleaner/go.mod

+21-17
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
11
module github.com/codefresh-io/dind-cleaner
22

3-
go 1.16
3+
go 1.21
44

55
require (
6-
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
7-
github.com/Microsoft/go-winio v0.4.11 // indirect
8-
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 // indirect
9-
github.com/docker/distribution v2.6.0-rc.1.0.20170726174610-edc3ab29cdff+incompatible // indirect
10-
github.com/docker/docker v17.12.0-ce-rc1.0.20180826111245-fe3bc75cc44e+incompatible
6+
github.com/docker/docker v24.0.5+incompatible
7+
github.com/golang/glog v1.1.2
8+
golang.org/x/net v0.14.0
9+
)
10+
11+
require (
12+
github.com/Microsoft/go-winio v0.6.1 // indirect
13+
github.com/davecgh/go-spew v1.1.1 // indirect
14+
github.com/docker/distribution v2.8.2+incompatible // indirect
1115
github.com/docker/go-connections v0.4.1-0.20180821093606-97c2040d34df // indirect
12-
github.com/docker/go-units v0.3.3 // indirect
13-
github.com/gogo/protobuf v0.0.0-20170330071051-c0656edd0d9e // indirect
14-
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
15-
github.com/gorilla/mux v1.8.0 // indirect
16-
github.com/opencontainers/go-digest v0.0.0-20170106003457-a6d0ee40d420 // indirect
17-
github.com/opencontainers/image-spec v1.0.1-0.20180411145040-e562b0440392 // indirect
18-
github.com/pkg/errors v0.8.1-0.20180311214515-816c9085562c // indirect
19-
github.com/sirupsen/logrus v1.8.1 // indirect
16+
github.com/docker/go-units v0.5.0 // indirect
17+
github.com/gogo/protobuf v1.3.2 // indirect
18+
github.com/moby/term v0.5.0 // indirect
19+
github.com/morikuni/aec v1.0.0 // indirect
20+
github.com/opencontainers/go-digest v1.0.0 // indirect
21+
github.com/opencontainers/image-spec v1.0.2 // indirect
22+
github.com/pkg/errors v0.9.1 // indirect
2023
github.com/stretchr/testify v1.7.0 // indirect
21-
golang.org/x/net v0.10.0
24+
golang.org/x/mod v0.12.0 // indirect
25+
golang.org/x/sys v0.11.0 // indirect
2226
golang.org/x/time v0.0.0-20210611083556-38a9dc6acbc6 // indirect
23-
google.golang.org/grpc v1.39.0 // indirect
24-
gotest.tools v2.2.0+incompatible // indirect
27+
golang.org/x/tools v0.12.0 // indirect
28+
gotest.tools/v3 v3.5.0 // indirect
2529
)

0 commit comments

Comments
 (0)