Skip to content

Commit a657a80

Browse files
committed
Remove discovery endpoint
1 parent b41a579 commit a657a80

11 files changed

Lines changed: 295 additions & 103 deletions

File tree

agent/cmd/agent/main.go

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,6 @@ func main() {
5454
}
5555

5656
var logsEndpoint string
57-
if logsEndpointFlag != "" {
58-
logsEndpoint = logsEndpointFlag
59-
} else {
60-
logsEndpoint = fetchLogsEndpoint(controlPlaneURL)
61-
}
6257

6358
if isProxy && runtime.GOOS != "linux" {
6459
log.Fatal("--proxy flag is only supported on Linux")
@@ -112,6 +107,12 @@ func main() {
112107

113108
log.Printf("Loaded config: serverID=%s, subnetId=%d, wireguardIP=%s", config.ServerID, config.SubnetID, config.WireGuardIP)
114109

110+
if logsEndpointFlag != "" {
111+
logsEndpoint = logsEndpointFlag
112+
} else if config.LoggingEndpoint != "" {
113+
logsEndpoint = config.LoggingEndpoint
114+
}
115+
115116
if err := container.EnsureNetwork(config.SubnetID); err != nil {
116117
log.Printf("Warning: Failed to ensure container network: %v", err)
117118
}
@@ -152,12 +153,39 @@ func main() {
152153
log.Fatalf("Failed to register: %v", err)
153154
}
154155

156+
var respLoggingEndpoint string
157+
if resp.LoggingEndpoint != nil {
158+
respLoggingEndpoint = *resp.LoggingEndpoint
159+
}
160+
161+
var registryURL, registryUsername, registryPassword string
162+
if resp.RegistryURL != nil {
163+
registryURL = *resp.RegistryURL
164+
}
165+
if resp.RegistryUsername != nil {
166+
registryUsername = *resp.RegistryUsername
167+
}
168+
if resp.RegistryPassword != nil {
169+
registryPassword = *resp.RegistryPassword
170+
}
171+
155172
config = &agent.Config{
156-
ServerID: resp.ServerID,
157-
SubnetID: resp.SubnetID,
158-
WireGuardIP: resp.WireGuardIP,
159-
EncryptionKey: resp.EncryptionKey,
160-
IsProxy: isProxy,
173+
ServerID: resp.ServerID,
174+
SubnetID: resp.SubnetID,
175+
WireGuardIP: resp.WireGuardIP,
176+
EncryptionKey: resp.EncryptionKey,
177+
IsProxy: isProxy,
178+
LoggingEndpoint: respLoggingEndpoint,
179+
RegistryURL: registryURL,
180+
RegistryUsername: registryUsername,
181+
RegistryPassword: registryPassword,
182+
RegistryInsecure: resp.RegistryInsecure,
183+
}
184+
185+
if logsEndpointFlag != "" {
186+
logsEndpoint = logsEndpointFlag
187+
} else if respLoggingEndpoint != "" {
188+
logsEndpoint = respLoggingEndpoint
161189
}
162190

163191
if err := saveConfig(configPath, config); err != nil {
@@ -201,6 +229,13 @@ func main() {
201229
}
202230
}
203231

232+
if config.RegistryURL != "" && config.RegistryUsername != "" {
233+
log.Printf("[registry] attempting login to %s", config.RegistryURL)
234+
if err := container.Login(config.RegistryURL, config.RegistryUsername, config.RegistryPassword, config.RegistryInsecure); err != nil {
235+
log.Printf("[registry] warning: failed to login to registry: %v", err)
236+
}
237+
}
238+
204239
reconciler := reconcile.NewReconciler(config.EncryptionKey, dataDir)
205240
client := agenthttp.NewClient(controlPlaneURL, config.ServerID, signingKeyPair, dataDir)
206241

@@ -331,35 +366,3 @@ func getPrivateIP() string {
331366

332367
return ""
333368
}
334-
335-
type discoverResponse struct {
336-
LoggingEndpoint *string `json:"loggingEndpoint"`
337-
Version int `json:"version"`
338-
}
339-
340-
func fetchLogsEndpoint(controlPlaneURL string) string {
341-
client := &http.Client{Timeout: 10 * time.Second}
342-
resp, err := client.Get(controlPlaneURL + "/api/v1/agent/discover")
343-
if err != nil {
344-
log.Printf("Failed to fetch discovery endpoint: %v", err)
345-
return ""
346-
}
347-
defer resp.Body.Close()
348-
349-
if resp.StatusCode != http.StatusOK {
350-
log.Printf("Discovery endpoint returned status %d", resp.StatusCode)
351-
return ""
352-
}
353-
354-
var discovery discoverResponse
355-
if err := json.NewDecoder(resp.Body).Decode(&discovery); err != nil {
356-
log.Printf("Failed to decode discovery response: %v", err)
357-
return ""
358-
}
359-
360-
if discovery.LoggingEndpoint == nil {
361-
return ""
362-
}
363-
364-
return *discovery.LoggingEndpoint
365-
}

agent/internal/agent/agent.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,16 @@ func (s AgentState) String() string {
3636
}
3737

3838
type Config struct {
39-
ServerID string `json:"serverId"`
40-
SubnetID int `json:"subnetId"`
41-
WireGuardIP string `json:"wireguardIp"`
42-
EncryptionKey string `json:"encryptionKey"`
43-
IsProxy bool `json:"isProxy"`
39+
ServerID string `json:"serverId"`
40+
SubnetID int `json:"subnetId"`
41+
WireGuardIP string `json:"wireguardIp"`
42+
EncryptionKey string `json:"encryptionKey"`
43+
IsProxy bool `json:"isProxy"`
44+
LoggingEndpoint string `json:"loggingEndpoint,omitempty"`
45+
RegistryURL string `json:"registryUrl,omitempty"`
46+
RegistryUsername string `json:"registryUsername,omitempty"`
47+
RegistryPassword string `json:"registryPassword,omitempty"`
48+
RegistryInsecure bool `json:"registryInsecure"`
4449
}
4550

4651
type ActualState struct {

agent/internal/api/client.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,15 @@ type RegisterRequest struct {
3333
}
3434

3535
type RegisterResponse struct {
36-
ServerID string `json:"serverId"`
37-
SubnetID int `json:"subnetId"`
38-
WireGuardIP string `json:"wireguardIp"`
39-
EncryptionKey string `json:"encryptionKey"`
36+
ServerID string `json:"serverId"`
37+
SubnetID int `json:"subnetId"`
38+
WireGuardIP string `json:"wireguardIp"`
39+
EncryptionKey string `json:"encryptionKey"`
40+
LoggingEndpoint *string `json:"loggingEndpoint"`
41+
RegistryURL *string `json:"registryUrl"`
42+
RegistryUsername *string `json:"registryUsername"`
43+
RegistryPassword *string `json:"registryPassword"`
44+
RegistryInsecure bool `json:"registryInsecure"`
4045
}
4146

4247
func (c *Client) Register(token, wireguardPublicKey, signingPublicKey, publicIP, privateIP string, isProxy bool) (*RegisterResponse, error) {

agent/internal/container/runtime_darwin.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,25 @@ func CheckPrerequisites() error {
417417
return nil
418418
}
419419

420+
func Login(registryURL, username, password string, insecure bool) error {
421+
if registryURL == "" || username == "" {
422+
return nil
423+
}
424+
425+
log.Printf("[docker:login] logging in to registry %s", registryURL)
426+
427+
args := []string{"login", "-u", username, "-p", password, registryURL}
428+
429+
cmd := exec.Command("docker", args...)
430+
output, err := cmd.CombinedOutput()
431+
if err != nil {
432+
return fmt.Errorf("failed to login to registry: %s: %w", string(output), err)
433+
}
434+
435+
log.Printf("[docker:login] successfully logged in to registry %s", registryURL)
436+
return nil
437+
}
438+
420439
func ImagePrune() {
421440
exec.Command("docker", "image", "prune", "-f").Run()
422441
}

agent/internal/container/runtime_linux.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,29 @@ func CheckPrerequisites() error {
418418
return nil
419419
}
420420

421+
func Login(registryURL, username, password string, insecure bool) error {
422+
if registryURL == "" || username == "" {
423+
return nil
424+
}
425+
426+
log.Printf("[podman:login] logging in to registry %s", registryURL)
427+
428+
args := []string{"login"}
429+
if insecure {
430+
args = append(args, "--tls-verify=false")
431+
}
432+
args = append(args, "-u", username, "-p", password, registryURL)
433+
434+
cmd := exec.Command("podman", args...)
435+
output, err := cmd.CombinedOutput()
436+
if err != nil {
437+
return fmt.Errorf("failed to login to registry: %s: %w", string(output), err)
438+
}
439+
440+
log.Printf("[podman:login] successfully logged in to registry %s", registryURL)
441+
return nil
442+
}
443+
421444
func ImagePrune() {
422445
exec.Command("podman", "image", "prune", "-f").Run()
423446
}

compose.yml

Lines changed: 0 additions & 44 deletions
This file was deleted.

deployment/.env.example

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Domain Configuration
2+
ROOT_DOMAIN=example.com
3+
4+
# Let's Encrypt
5+
ACME_EMAIL=admin@example.com
6+
7+
# PostgreSQL
8+
POSTGRES_USER=techulus
9+
POSTGRES_PASSWORD=your-secure-password
10+
POSTGRES_DB=techulus
11+
12+
# Database URL (uses Docker service name)
13+
DATABASE_URL=postgres://techulus:your-secure-password@postgres:5432/techulus
14+
15+
# Authentication
16+
BETTER_AUTH_SECRET=your-secret-key-here
17+
18+
# Encryption (32 bytes as 64-character hex string)
19+
ENCRYPTION_KEY=your-64-character-hex-string
20+
21+
# Victoria Logs Authentication
22+
VL_USERNAME=admin
23+
VL_PASSWORD=your-secure-logs-password
24+
VL_RETENTION=7d
25+
26+
# Registry Authentication (htpasswd format for registry server)
27+
# Generate with: htpasswd -nB admin
28+
# Escape $ as $$ in the value
29+
REGISTRY_AUTH=admin:$$2y$$05$$your-bcrypt-hash-here
30+
31+
# Registry Credentials (for agents to pull images)
32+
REGISTRY_URL=
33+
REGISTRY_USERNAME=
34+
REGISTRY_PASSWORD=
35+
REGISTRY_INSECURE=true
36+
37+
# GitHub App Integration (optional)
38+
GITHUB_APP_ID=
39+
GITHUB_APP_PRIVATE_KEY=
40+
GITHUB_WEBHOOK_SECRET=

deployment/README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Production Deployment
2+
3+
Docker Compose setup with Traefik for SSL termination via Let's Encrypt.
4+
5+
## Quick Start
6+
7+
```bash
8+
cp .env.example .env
9+
# Edit .env with your values
10+
11+
docker compose -f compose.production.yml up -d --build
12+
```
13+
14+
## Services
15+
16+
| Service | Endpoint |
17+
|---------|----------|
18+
| Web | `https://${ROOT_DOMAIN}` |
19+
| Registry | `https://registry.${ROOT_DOMAIN}` |
20+
| Logs | `https://logs.${ROOT_DOMAIN}` |
21+
| PostgreSQL | Internal only |
22+
23+
## Environment Setup
24+
25+
Generate registry auth:
26+
```bash
27+
htpasswd -nB admin
28+
# Escape $ as $$ in .env
29+
```
30+
31+
## Commands
32+
33+
```bash
34+
docker compose -f compose.production.yml ps
35+
docker compose -f compose.production.yml logs -f
36+
docker compose -f compose.production.yml down
37+
```

0 commit comments

Comments
 (0)