-
Notifications
You must be signed in to change notification settings - Fork 3
31 lines (28 loc) · 1.19 KB
/
cleanup.yaml
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
name: Clean up hcloud resources
# prevent mutliple concurrent workflow executions to avoid hcloud resources interfering with each other
concurrency: hcloud
on:
workflow_dispatch:
schedule:
- cron: "0 3 * * *"
# run the workflow after a packer build workflow is finished to clean up all images created by the workflow (and potentially also left-over servers)
workflow_run:
workflows: ["Packer build"]
types:
- completed
jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- name: setup hcloud
run: |
curl -o hcloud-linux-amd64.tar.gz -L https://github.com/hetznercloud/cli/releases/download/v1.34.0/hcloud-linux-amd64.tar.gz
sudo tar xf hcloud-linux-amd64.tar.gz -C /usr/bin hcloud
sudo chmod +x /usr/bin/hcloud
- name: clean up resources
env:
HCLOUD_TOKEN: ${{ secrets.HCLOUD_TOKEN }}
run: |
for i in $(hcloud ssh-key list -o noheader -o columns=id); do hcloud ssh-key delete $i; done
for i in $(hcloud server list -o noheader -o columns=id); do hcloud server delete $i; done
for i in $(hcloud image list -t snapshot -o noheader -o columns=id); do hcloud image delete $i; done