Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
github
/
dependabot-action
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
0
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security
Insights
Files
6d06230
.github
.husky
.vscode
__fixtures__
__tests__
dist
docker
script
src
api-client.ts
cleanup.ts
cli.ts
config-types.ts
container-service.ts
docker-tags.ts
fetch-images.ts
image-service.ts
inputs.ts
main.ts
proxy.ts
update-containers.ts
updater-builder.ts
updater.ts
utils.ts
tmp
.editorconfig
.eslintignore
.eslintrc.json
.gitattributes
.gitignore
.nvmrc
.prettierignore
.prettierrc.json
CODEOWNERS
CODE_OF_CONDUCT.md
LICENSE
README.md
action.yml
jest.config.js
package-lock.json
package.json
tsconfig.eslint.json
tsconfig.json
Breadcrumbs
dependabot-action
/
src
/
cleanup.ts
Blame
Blame
Latest commit
Landon Grindheim
and
GitHub
Handle errors as
unknown
(not
any
)
Aug 30, 2022
47d7a37
·
Aug 30, 2022
History
History
77 lines (71 loc) · 2.54 KB
Breadcrumbs
dependabot-action
/
src
/
cleanup.ts
Top
File metadata and controls
Code
Blame
77 lines (71 loc) · 2.54 KB
Raw
import * as core from '@actions/core' import Docker from 'dockerode' import { UPDATER_IMAGE_NAME, PROXY_IMAGE_NAME, repositoryName } from './docker-tags' // This method performs housekeeping checks to remove Docker artifacts // which were left behind by old versions of the action or any jobs // which may have crashed before deleting their own containers or networks // // cutoff - a Go duration string to pass to the Docker API's 'until' argument, default '24h' export async function run(cutoff = '24h'): Promise<void> { try { const docker = new Docker() const untilFilter = {until: [cutoff]} core.info(`Pruning networks older than ${cutoff}`) await docker.pruneNetworks({filters: untilFilter}) core.info(`Pruning containers older than ${cutoff}`) await docker.pruneContainers({filters: untilFilter}) await cleanupOldImageVersions(docker, UPDATER_IMAGE_NAME) await cleanupOldImageVersions(docker, PROXY_IMAGE_NAME) } catch (error: unknown) { if (error instanceof Error) { core.error(`Error cleaning up: ${error.message}`) } } } export async function cleanupOldImageVersions( docker: Docker, imageName: string ): Promise<void> { const repo = repositoryName(imageName) const options = { filters: { reference: [repo] } } core.info(`Cleaning up images for ${repo}`) docker.listImages(options, async function (err, imageInfoList) { if (imageInfoList && imageInfoList.length > 0) { for (const imageInfo of imageInfoList) { // The given imageName is expected to be a digest, however to avoid any surprises in future // we fail over to check for a match on tags as well. // // This means we won't remove any image which matches an imageName of either of these notations: // - dependabot/image@sha256:$REF (current implementation) // - dependabot/image:v1 // // Without checking imageInfo.RepoTags for a match, we would actually remove the latter even if // this was the active version. if ( imageInfo.RepoDigests?.includes(imageName) || imageInfo.RepoTags?.includes(imageName) ) { core.info(`Skipping current image ${imageInfo.Id}`) continue } core.info(`Removing image ${imageInfo.Id}`) try { await docker.getImage(imageInfo.Id).remove() } catch (error: unknown) { if (error instanceof Error) { core.info(`Unable to remove ${imageInfo.Id} -- ${error.message}`) } } } } }) } run()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
You can’t perform that action at this time.