Init this thing
This commit is contained in:
commit
2f13665dcc
26
.drone.yml
Normal file
26
.drone.yml
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
---
|
||||||
|
kind: pipeline
|
||||||
|
name: autonomic.zone/hetzner-ci-cd-nuke
|
||||||
|
steps:
|
||||||
|
- name: nuke resources
|
||||||
|
image: golang:1.16
|
||||||
|
environment:
|
||||||
|
HCLOUD_TOKEN:
|
||||||
|
from_secret: hetzner_ci_cd_token
|
||||||
|
commands:
|
||||||
|
- go run hccn.go
|
||||||
|
|
||||||
|
- name: notify rocket chat
|
||||||
|
image: plugins/slack
|
||||||
|
settings:
|
||||||
|
webhook:
|
||||||
|
from_secret: rc_builds_url
|
||||||
|
username: comradebritney
|
||||||
|
channel: "internal.builds"
|
||||||
|
template: "{{repo.owner}}/{{repo.name}} build failed: {{build.link}}"
|
||||||
|
when:
|
||||||
|
status:
|
||||||
|
- failure
|
||||||
|
trigger:
|
||||||
|
branch:
|
||||||
|
- main
|
5
.envrc.sample
Normal file
5
.envrc.sample
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# The path to our pass credentials store
|
||||||
|
export PASSWORD_STORE_DIR=$(pwd)/../passwords/passwords/
|
||||||
|
|
||||||
|
# The Hetzner Cloud API token for managing our instances
|
||||||
|
export HCLOUD_TOKEN=$(pass show logins/hetzner/cicd/api_key)
|
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
hetzner-ci-cd-nuke
|
13
README.md
Normal file
13
README.md
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# hetzner-ci-cd-nuke
|
||||||
|
|
||||||
|
> Nuke Hetzner resources for CI/CD clean up.
|
||||||
|
|
||||||
|
Running on a daily cron via [drone.autonomic.zone](https://drone.autonomic.zone).
|
||||||
|
|
||||||
|
## Run
|
||||||
|
|
||||||
|
```
|
||||||
|
cp .envrc.sample .envrc
|
||||||
|
direnv allow
|
||||||
|
go run hccn.go
|
||||||
|
```
|
5
go.mod
Normal file
5
go.mod
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
module autonomic.zone/hetzner-ci-cd-nuke
|
||||||
|
|
||||||
|
go 1.16
|
||||||
|
|
||||||
|
require github.com/hetznercloud/hcloud-go v1.28.0
|
15
go.sum
Normal file
15
go.sum
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||||
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w=
|
||||||
|
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
|
github.com/hetznercloud/hcloud-go v1.28.0 h1:T2a0CVGETf7BoWIdZ/TACqmTZAa/ROutcfdUHYiPAQ4=
|
||||||
|
github.com/hetznercloud/hcloud-go v1.28.0/go.mod h1:2C5uMtBiMoFr3m7lBFPf7wXTdh33CevmZpQIIDPGYJI=
|
||||||
|
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/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||||
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/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 h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
36
hccn.go
Normal file
36
hccn.go
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/hetznercloud/hcloud-go/hcloud"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
token := os.Getenv("HCLOUD_TOKEN")
|
||||||
|
if token == "" {
|
||||||
|
log.Fatal("HCLOUD_TOKEN missing!")
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx := context.Background()
|
||||||
|
client := hcloud.NewClient(hcloud.WithToken(token))
|
||||||
|
|
||||||
|
servers, err := client.Server.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, server := range servers {
|
||||||
|
fmt.Println("Deleting: ", server.Name)
|
||||||
|
client.Server.Delete(ctx, server)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(servers) > 0 {
|
||||||
|
fmt.Printf("Success! Deleted %v server(s)", len(servers))
|
||||||
|
} else {
|
||||||
|
fmt.Println("No servers found, bailing out gracefully")
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user