-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1dd476d
commit 775d5c3
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,49 @@ | ||
import axios from "axios" | ||
import logger from "../util/logger.js" | ||
import getLatestTag from "../util/get-latest-tag.js" | ||
import getHetznerImages from "../util/get-hetzner-images.js" | ||
|
||
const log = logger(); | ||
|
||
export default { | ||
description: 'deletes outdated images from hetzner', | ||
|
||
run: async ({ response }) => { | ||
|
||
//get github tags | ||
const latestTag = await getLatestTag(); | ||
|
||
//get hetzner images | ||
const images = await getHetznerImages(); | ||
|
||
//return if no images | ||
if (!images) { | ||
app.client.chat.postEphemeral({ | ||
channel: `${message.channel}`, | ||
user: `${message.user}`, | ||
text: `Failed to get image data` | ||
}); | ||
|
||
return; | ||
} | ||
|
||
//get the image to delete | ||
for (const image of images) { | ||
if (image.description !== latestTag) { | ||
//delete the image that doesn't have the latest tag | ||
await axios.delete(`https://api.hetzner.cloud/v1/images/${image.id}`, { | ||
headers: { | ||
'Authorization': `Bearer ${process.env.HETZNER_API_TOKEN}` | ||
} | ||
}) | ||
.catch(error => { | ||
log.error('Failed to delete image from hetzner', axiosError(error)); | ||
}); | ||
} | ||
} | ||
|
||
response({ | ||
text: `cleanup complete` | ||
}) | ||
} | ||
} |