-
Notifications
You must be signed in to change notification settings - Fork 2
Change: Rewrite Dockerhost scripts in Go #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
CGoodwin90
wants to merge
45
commits into
main
Choose a base branch
from
change/refactor_dockerhost_scripts_golang
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 11 commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
6cd3653
Refactoring dockerhost scripts to golang
CGoodwin90 2d2d9de
Refactored update-push-images
CGoodwin90 995fae6
Add cron for each function
CGoodwin90 8de7b96
Removing bash scripts
CGoodwin90 37f8f9c
Updated dockerfile cmd
CGoodwin90 6a67c2c
Moved cmd directive into go
CGoodwin90 b0c18e7
Updated cmd
CGoodwin90 e088a2f
Updated cmd and added error handling
CGoodwin90 80125d2
Added api version negotiation
CGoodwin90 14c2756
Merged conflicts
CGoodwin90 dad6dda
Adding cron schedules + filters as env vars
CGoodwin90 b85f72a
Various improvements
CGoodwin90 1dd265e
Updated filter
CGoodwin90 b8f0d84
Updated image filter
CGoodwin90 8e12322
Updated dockerfile env to match new filter
CGoodwin90 7e1f908
update docker to v24
tobybellwood 08b9361
Reduce log noise
CGoodwin90 245b4fa
Included a variable to set log level
CGoodwin90 6be93e1
Changed log output to only log updated images
CGoodwin90 6188bad
Refactoring dockerhost scripts to golang
CGoodwin90 2b2fafe
Refactored update-push-images
CGoodwin90 684fd37
Add cron for each function
CGoodwin90 f06bd9c
Removing bash scripts
CGoodwin90 423dd9b
Updated dockerfile cmd
CGoodwin90 148d8d8
Moved cmd directive into go
CGoodwin90 0a9baba
Updated cmd
CGoodwin90 6bfc576
Updated cmd and added error handling
CGoodwin90 e586b54
Added api version negotiation
CGoodwin90 b5042e6
Adding cron schedules + filters as env vars
CGoodwin90 70b9333
Various improvements
CGoodwin90 f016bd2
Updated filter
CGoodwin90 66659fe
Updated image filter
CGoodwin90 312543d
Updated dockerfile env to match new filter
CGoodwin90 e2def92
update docker to v24
tobybellwood 730dcbf
Reduce log noise
CGoodwin90 fe7d006
Included a variable to set log level
CGoodwin90 6f9c0e1
Changed log output to only log updated images
CGoodwin90 2ac9c4f
build: update golang to 1.22
tobybellwood cbf34f1
Merged main
CGoodwin90 9eb6117
Initial pass at adding pruneDanglingSchedule & updates go.mod
CGoodwin90 2ae5d75
Updated Dockerfile
CGoodwin90 98df40b
feat: add builder cache prune
shreddedbacon c482341
refactor: clean up any containers, not just exited
shreddedbacon a9df02b
chore: fix exited container check filter
shreddedbacon 67efcaf
chore: dockerfile AS
shreddedbacon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| module docker-host | ||
|
|
||
| go 1.19 | ||
|
|
||
| require ( | ||
| github.com/docker/docker v23.0.3+incompatible | ||
| github.com/robfig/cron/v3 v3.0.1 | ||
| ) | ||
|
|
||
| require ( | ||
| github.com/Microsoft/go-winio v0.6.0 // indirect | ||
| github.com/docker/distribution v2.8.1+incompatible // indirect | ||
| github.com/docker/go-connections v0.4.0 // indirect | ||
| github.com/docker/go-units v0.5.0 // indirect | ||
| github.com/gogo/protobuf v1.3.2 // indirect | ||
| github.com/moby/term v0.0.0-20221205130635-1aeaba878587 // indirect | ||
| github.com/morikuni/aec v1.0.0 // indirect | ||
| github.com/opencontainers/go-digest v1.0.0 // indirect | ||
| github.com/opencontainers/image-spec v1.0.2 // indirect | ||
| github.com/pkg/errors v0.9.1 // indirect | ||
| github.com/stretchr/testify v1.8.2 // indirect | ||
| github.com/uselagoon/machinery v0.0.7 // indirect | ||
| golang.org/x/mod v0.10.0 // indirect | ||
| golang.org/x/net v0.9.0 // indirect | ||
| golang.org/x/sys v0.7.0 // indirect | ||
| golang.org/x/time v0.3.0 // indirect | ||
| golang.org/x/tools v0.8.0 // indirect | ||
| gotest.tools/v3 v3.4.0 // indirect | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8= | ||
| github.com/Microsoft/go-winio v0.6.0 h1:slsWYD/zyx7lCXoZVlvQrj0hPTM1HI4+v1sIda2yDvg= | ||
| github.com/Microsoft/go-winio v0.6.0/go.mod h1:cTAf44im0RAYeL23bpB+fzCyDH2MJiz2BO69KH/soAE= | ||
| github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
| github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
| github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
| github.com/docker/distribution v2.8.1+incompatible h1:Q50tZOPR6T/hjNsyc9g8/syEs6bk8XXApsHjKukMl68= | ||
| github.com/docker/distribution v2.8.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= | ||
| github.com/docker/docker v23.0.2+incompatible h1:q81C2qQ/EhPm8COZMUGOQYh4qLv4Xu6CXELJ3WK/mlU= | ||
| github.com/docker/docker v23.0.2+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= | ||
| github.com/docker/docker v23.0.3+incompatible h1:9GhVsShNWz1hO//9BNg/dpMnZW25KydO4wtVxWAIbho= | ||
| github.com/docker/docker v23.0.3+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= | ||
| github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ= | ||
| github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec= | ||
| github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4= | ||
| github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= | ||
| github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= | ||
| github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= | ||
| github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= | ||
| github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= | ||
| github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= | ||
| github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= | ||
| github.com/moby/term v0.0.0-20221205130635-1aeaba878587 h1:HfkjXDfhgVaN5rmueG8cL8KKeFNecRCXFhaJ2qZ5SKA= | ||
| github.com/moby/term v0.0.0-20221205130635-1aeaba878587/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y= | ||
| github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= | ||
| github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= | ||
| github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= | ||
| github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= | ||
| github.com/opencontainers/image-spec v1.0.2 h1:9yCKha/T5XdGtO0q9Q9a6T5NUCsTn/DrBg0D7ufOcFM= | ||
| github.com/opencontainers/image-spec v1.0.2/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0= | ||
| github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= | ||
| github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= | ||
| github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
| github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
| github.com/robfig/cron/v3 v3.0.0 h1:kQ6Cb7aHOHTSzNVNEhmp8EcWKLb4CbiMW9h9VyIhO4E= | ||
| github.com/robfig/cron/v3 v3.0.0/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro= | ||
| github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs= | ||
| github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro= | ||
| github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
| github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= | ||
| github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= | ||
| github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= | ||
| github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= | ||
| github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= | ||
| github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= | ||
| github.com/uselagoon/machinery v0.0.7 h1:fBIURDQRVnaB/Gime1Lfp6kgQYmuQpa0gmdfPwo7dkc= | ||
| github.com/uselagoon/machinery v0.0.7/go.mod h1:dGAvkxWQkRu/eLQeWLrTl5HvNoFsiXlXInCptHUxzUw= | ||
| github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= | ||
| github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= | ||
| golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= | ||
| golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= | ||
| golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= | ||
| golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= | ||
| golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= | ||
| golang.org/x/mod v0.9.0 h1:KENHtAZL2y3NLMYZeHY9DW8HW8V+kQyJsY/V9JlKvCs= | ||
| golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= | ||
| golang.org/x/mod v0.10.0 h1:lFO9qtOdlre5W1jxS3r/4szv2/6iXxScdzjoBMXNhYk= | ||
| golang.org/x/mod v0.10.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= | ||
| golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= | ||
| golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= | ||
| golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= | ||
| golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= | ||
| golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ= | ||
| golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= | ||
| golang.org/x/net v0.9.0 h1:aWJ/m6xSmxWBx+V0XRHTlrYrPG56jKsLdTFmsSsCzOM= | ||
| golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= | ||
| golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | ||
| golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | ||
| golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | ||
| golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= | ||
| golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||
| golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
| golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
| golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
| golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= | ||
| golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
| golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU= | ||
| golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
| golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= | ||
| golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= | ||
| golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4= | ||
| golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= | ||
| golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= | ||
| golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= | ||
| golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= | ||
| golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= | ||
| golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= | ||
| golang.org/x/tools v0.7.0 h1:W4OVu8VVOaIO0yzWMNdepAulS7YfoS3Zabrm8DOXXU4= | ||
| golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s= | ||
| golang.org/x/tools v0.8.0 h1:vSDcovVPld282ceKgDimkRSC8kpaH1dgyc9UMzlt84Y= | ||
| golang.org/x/tools v0.8.0/go.mod h1:JxBZ99ISMI5ViVkT1tr6tdNmXeTrcpVSD3vZ1RsRdN4= | ||
| golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= | ||
| golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= | ||
| golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= | ||
| golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= | ||
| gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
| gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= | ||
| gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= | ||
| gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= | ||
| gotest.tools/v3 v3.4.0 h1:ZazjZUfuVeZGLAmlKKuyv3IKP5orXcwtOwDQH6YVr6o= | ||
| gotest.tools/v3 v3.4.0/go.mod h1:CtbdzLSsqVhDgMtKsx03ird5YTGB3ar27v0u/yKBW5g= |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "io" | ||
| "log" | ||
| "os" | ||
| "os/exec" | ||
|
|
||
| "github.com/docker/docker/api/types" | ||
| "github.com/docker/docker/api/types/filters" | ||
| "github.com/docker/docker/client" | ||
| "github.com/robfig/cron/v3" | ||
| machineryvars "github.com/uselagoon/machinery/utils/variables" | ||
| ) | ||
|
|
||
| const EnvOverrideHost = "DOCKER_HOST" | ||
|
|
||
| var dockerHost = machineryvars.GetEnv("DOCKER_HOST", "docker-host") | ||
| var repo = machineryvars.GetEnv("REPOSITORY_TO_UPDATE", "amazeeio") | ||
| var REGISTRY = machineryvars.GetEnv("REGISTRY", "docker-registry.default.svc:5000") | ||
| var BIP = machineryvars.GetEnv("BIP", "172.16.0.1/16") | ||
| var REGISTRY_MIRROR = machineryvars.GetEnv("REGISTRY_MIRROR", "https://imagecache.amazeeio.cloud") | ||
CGoodwin90 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| var pruneImagesSchedule = machineryvars.GetEnv("PRUNE_SCHEDULE", "22 1 * * *") | ||
| var removeExitedSchedule = machineryvars.GetEnv("REMOVE_EXITED_SCHEDULE", "22 */4 * * *") | ||
| var updateImagesSchedule = machineryvars.GetEnv("UPDATE_IMAGES_SCHEDULE", "*/15 * * * *") | ||
| var pruneImagesUntil = machineryvars.GetEnv("PRUNE_IMAGES_UNTIL", "168h") | ||
| var danglingFilter = machineryvars.GetEnv("DANGLING_FILTER", "true") | ||
|
|
||
| func main() { | ||
| cli, err := client.NewClientWithOpts( | ||
| client.WithHostFromEnv(), | ||
| client.WithAPIVersionNegotiation(), | ||
| ) | ||
| if err != nil { | ||
| fmt.Println("Error", err) | ||
CGoodwin90 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| defer cli.Close() | ||
|
|
||
| var command = fmt.Sprintf("/usr/local/bin/dind /usr/local/bin/dockerd --host=tcp://0.0.0.0:2375 --host=unix:///var/run/docker.sock --insecure-registry=%s --insecure-registry=harbor-harbor-core.harbor.svc.cluster.local:80 --bip=%s --storage-driver=overlay2 --storage-opt=overlay2.override_kernel_check=1 --registry-mirror=%s", REGISTRY, BIP, REGISTRY_MIRROR) | ||
CGoodwin90 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| var cmd = exec.Command("sh", "-c", command) | ||
|
|
||
| if dockerHost != cli.DaemonHost() { | ||
| fmt.Sprintf("Could not connect to %s", dockerHost) | ||
CGoodwin90 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| c := cron.New() | ||
| pruneImages(cli, c) | ||
| removeExited(cli, c) | ||
| updateImages(cli, c) | ||
| c.Start() | ||
| cmd.Stdout = os.Stdout | ||
| cmd.Stderr = os.Stderr | ||
| if err := cmd.Run(); err != nil { | ||
| fmt.Println("could not run command: ", err) | ||
CGoodwin90 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| func pruneImages(client *client.Client, c *cron.Cron) { | ||
| c.AddFunc(pruneImagesSchedule, func() { | ||
| log.Println("Starting image prune") | ||
| ageFilter := filters.NewArgs() | ||
| pruneDanglingFilter := filters.NewArgs() | ||
| ageFilter.Add("until", pruneImagesUntil) | ||
| pruneDanglingFilter.Add("dangling", danglingFilter) | ||
|
|
||
| // # prune all images older than 7 days or what is specified in the environment variable | ||
| _, err := client.ImagesPrune(context.Background(), ageFilter) | ||
| if err != nil { | ||
| log.Println(err) | ||
| } | ||
| // # prune all docker build cache images older than 7 days or what is specified in the environment variable | ||
| _, buildErr := client.BuildCachePrune(context.Background(), types.BuildCachePruneOptions{Filters: ageFilter}) | ||
| if buildErr != nil { | ||
| log.Println(buildErr) | ||
| } | ||
| // # after old images are pruned, clean up dangling images | ||
| _, pruneErr := client.ImagesPrune(context.Background(), pruneDanglingFilter) | ||
| if pruneErr != nil { | ||
| log.Println(pruneErr) | ||
| } | ||
| log.Println("Prune complete") | ||
| }) | ||
| } | ||
|
|
||
| func removeExited(client *client.Client, c *cron.Cron) { | ||
| c.AddFunc(removeExitedSchedule, func() { | ||
| log.Println("Starting removeExited") | ||
| ctx := context.Background() | ||
| statusFilter := filters.NewArgs() | ||
| statusFilter.Add("status", "exited") | ||
| containers, err := client.ContainerList(ctx, types.ContainerListOptions{ | ||
| Filters: statusFilter, | ||
| }) | ||
| if err != nil { | ||
| log.Println(err) | ||
CGoodwin90 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| // # remove all exited containers | ||
| for _, container := range containers { | ||
| err := client.ContainerRemove(ctx, container.ID, types.ContainerRemoveOptions{ | ||
| Force: true, | ||
| RemoveVolumes: true, | ||
| }) | ||
| if err != nil { | ||
| log.Println(err) | ||
| } | ||
| } | ||
| log.Println("removeExited complete") | ||
| }) | ||
| } | ||
|
|
||
| func updateImages(client *client.Client, c *cron.Cron) { | ||
| c.AddFunc(updateImagesSchedule, func() { | ||
| log.Println("Starting update images") | ||
| ctx := context.Background() | ||
| filters := filters.NewArgs() | ||
| filters.Add("reference", fmt.Sprintf("%s/*:*", repo)) | ||
CGoodwin90 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| images, err := client.ImageList(ctx, types.ImageListOptions{Filters: filters}) | ||
| if err != nil { | ||
| log.Println(err) | ||
CGoodwin90 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| var imgRepoTags []string | ||
| for _, img := range images { | ||
| imgRepoTags = append(imgRepoTags, img.RepoTags...) | ||
| } | ||
|
|
||
| // # Iterates through all images that have the name of the repository we are interested in in it | ||
| for _, image := range imgRepoTags { | ||
| out, err := client.ImagePull(ctx, image, types.ImagePullOptions{}) | ||
| if err != nil { | ||
| log.Println(err) | ||
CGoodwin90 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| defer out.Close() | ||
| io.Copy(os.Stdout, out) | ||
| } | ||
| log.Println("Update images complete") | ||
| }) | ||
| } | ||
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.