Delete page "Infrastructure"
parent
fc1cb4122e
commit
d9653d5b41
1 changed files with 0 additions and 229 deletions
|
|
@ -1,229 +0,0 @@
|
|||
# Infrastructure
|
||||
|
||||
API reference for the `infra` package -- Hetzner Cloud, Hetzner Robot, and CloudNS DNS management. See [[Home]] for installation.
|
||||
|
||||
## Infrastructure Config (`infra.yaml`)
|
||||
|
||||
The `Config` struct models the full production infrastructure from a YAML file.
|
||||
|
||||
### Loading
|
||||
|
||||
```go
|
||||
import "forge.lthn.ai/core/go-devops/infra"
|
||||
|
||||
// Load from explicit path
|
||||
cfg, err := infra.Load("infra.yaml")
|
||||
|
||||
// Auto-discover by walking up from a directory
|
||||
cfg, path, err := infra.Discover("/path/to/project")
|
||||
```
|
||||
|
||||
`Discover` searches the given directory and all parent directories for `infra.yaml`.
|
||||
|
||||
### Config Structure
|
||||
|
||||
```go
|
||||
type Config struct {
|
||||
Hosts map[string]*Host
|
||||
LoadBalancer LoadBalancer
|
||||
Network Network
|
||||
DNS DNS
|
||||
SSL SSL
|
||||
Database Database
|
||||
Cache Cache
|
||||
Containers map[string]*Container
|
||||
S3 S3Config
|
||||
CDN CDN
|
||||
CICD CICD
|
||||
Monitoring Monitoring
|
||||
Backups Backups
|
||||
}
|
||||
```
|
||||
|
||||
### Host
|
||||
|
||||
```go
|
||||
type Host struct {
|
||||
FQDN string // Fully qualified domain name
|
||||
IP string // Public IP
|
||||
PrivateIP string // Private network IP
|
||||
Type string // "hcloud" or "hrobot"
|
||||
Role string // "bastion", "app", "builder"
|
||||
SSH SSHConf // User, Key path (~/ expanded), Port (default 22)
|
||||
Services []string // Services running on this host
|
||||
}
|
||||
```
|
||||
|
||||
### Querying Hosts
|
||||
|
||||
```go
|
||||
appServers := cfg.AppServers() // hosts with role "app"
|
||||
bastions := cfg.HostsByRole("bastion") // hosts with role "bastion"
|
||||
```
|
||||
|
||||
### Other Config Types
|
||||
|
||||
- **`LoadBalancer`** -- Name, FQDN, provider, algorithm, backends, health checks, listeners, SSL
|
||||
- **`Network`** -- CIDR, name
|
||||
- **`DNS`** -- Provider, nameservers, zones with records
|
||||
- **`Database`** -- Engine, version, cluster nodes, SST method, backup config
|
||||
- **`Cache`** -- Engine, version, sentinel flag, nodes
|
||||
- **`Container`** -- Image, port, runtime, command, replicas, dependencies
|
||||
- **`S3Config`** -- Endpoint, buckets with purpose and paths
|
||||
- **`CDN`** -- Provider, origin, zones
|
||||
- **`CICD`** -- Provider, URL, runner, registry, deploy hook
|
||||
- **`Monitoring`** -- Health endpoints with intervals, alert thresholds
|
||||
- **`Backups`** -- Daily and weekly backup jobs
|
||||
|
||||
---
|
||||
|
||||
## Hetzner Cloud API
|
||||
|
||||
HTTP client for the Hetzner Cloud API (`api.hetzner.cloud/v1`).
|
||||
|
||||
### Client
|
||||
|
||||
```go
|
||||
hcloud := infra.NewHCloudClient(token) // Bearer token auth
|
||||
```
|
||||
|
||||
### Servers
|
||||
|
||||
```go
|
||||
type HCloudServer struct {
|
||||
ID int
|
||||
Name string
|
||||
Status string // "running", "off", etc.
|
||||
PublicNet HCloudPublicNet // .IPv4.IP
|
||||
PrivateNet []HCloudPrivateNet // .IP, .Network
|
||||
ServerType HCloudServerType // .Name, .Cores, .Memory, .Disk
|
||||
Datacenter HCloudDatacenter // .Name, .Description
|
||||
Labels map[string]string
|
||||
}
|
||||
|
||||
servers, err := hcloud.ListServers(ctx)
|
||||
```
|
||||
|
||||
### Load Balancers
|
||||
|
||||
```go
|
||||
type HCloudLoadBalancer struct {
|
||||
ID int
|
||||
Name string
|
||||
PublicNet HCloudLBPublicNet // .Enabled, .IPv4.IP
|
||||
Algorithm HCloudLBAlgorithm // .Type
|
||||
Services []HCloudLBService // listeners with health checks
|
||||
Targets []HCloudLBTarget // IP or server targets with health status
|
||||
Location HCloudDatacenter
|
||||
Labels map[string]string
|
||||
}
|
||||
|
||||
lbs, err := hcloud.ListLoadBalancers(ctx)
|
||||
lb, err := hcloud.GetLoadBalancer(ctx, id)
|
||||
lb, err := hcloud.CreateLoadBalancer(ctx, HCloudLBCreateRequest{...})
|
||||
err := hcloud.DeleteLoadBalancer(ctx, id)
|
||||
```
|
||||
|
||||
### Snapshots
|
||||
|
||||
```go
|
||||
err := hcloud.CreateSnapshot(ctx, serverID, "pre-deploy backup")
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Hetzner Robot API
|
||||
|
||||
HTTP client for the Hetzner Robot API (`robot-ws.your-server.de`) -- dedicated/bare-metal servers.
|
||||
|
||||
### Client
|
||||
|
||||
```go
|
||||
hrobot := infra.NewHRobotClient(user, password) // Basic auth
|
||||
```
|
||||
|
||||
### Servers
|
||||
|
||||
```go
|
||||
type HRobotServer struct {
|
||||
ServerIP string
|
||||
ServerName string
|
||||
Product string
|
||||
Datacenter string
|
||||
Status string
|
||||
Cancelled bool
|
||||
PaidUntil string
|
||||
}
|
||||
|
||||
servers, err := hrobot.ListServers(ctx)
|
||||
server, err := hrobot.GetServer(ctx, "1.2.3.4")
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## CloudNS DNS API
|
||||
|
||||
HTTP client for the CloudNS DNS API (`api.cloudns.net`).
|
||||
|
||||
### Client
|
||||
|
||||
```go
|
||||
dns := infra.NewCloudNSClient(authID, password) // auth-id authentication
|
||||
```
|
||||
|
||||
### Zones
|
||||
|
||||
```go
|
||||
type CloudNSZone struct {
|
||||
Name string
|
||||
Type string
|
||||
Zone string
|
||||
Status string
|
||||
}
|
||||
|
||||
zones, err := dns.ListZones(ctx)
|
||||
```
|
||||
|
||||
### Records
|
||||
|
||||
```go
|
||||
type CloudNSRecord struct {
|
||||
ID string
|
||||
Type string // A, AAAA, CNAME, TXT, MX, etc.
|
||||
Host string // subdomain or @ for root
|
||||
Record string // value
|
||||
TTL string
|
||||
Priority string
|
||||
Status int
|
||||
}
|
||||
|
||||
records, err := dns.ListRecords(ctx, "example.com") // map[id]CloudNSRecord
|
||||
```
|
||||
|
||||
### CRUD Operations
|
||||
|
||||
```go
|
||||
// Create
|
||||
id, err := dns.CreateRecord(ctx, "example.com", "www", "A", "1.2.3.4", 3600)
|
||||
|
||||
// Update
|
||||
err := dns.UpdateRecord(ctx, "example.com", recordID, "www", "A", "5.6.7.8", 3600)
|
||||
|
||||
// Delete
|
||||
err := dns.DeleteRecord(ctx, "example.com", recordID)
|
||||
|
||||
// Upsert (create or update to match desired state, returns true if changed)
|
||||
changed, err := dns.EnsureRecord(ctx, "example.com", "www", "A", "1.2.3.4", 3600)
|
||||
```
|
||||
|
||||
### ACME DNS-01 Challenges
|
||||
|
||||
Helper methods for Let's Encrypt DNS-01 validation:
|
||||
|
||||
```go
|
||||
// Create _acme-challenge TXT record (TTL 60s)
|
||||
id, err := dns.SetACMEChallenge(ctx, "example.com", challengeValue)
|
||||
|
||||
// Remove all _acme-challenge TXT records
|
||||
err := dns.ClearACMEChallenge(ctx, "example.com")
|
||||
```
|
||||
Loading…
Add table
Reference in a new issue