16440a89f2
- internal/traefik/install.go: shared Traefik installer (download + systemd unit + dynamic dir). Default v3.3.0, configurable. - orca init: installs Traefik on localhost (idempotent, non-fatal if offline) - proxmox bootstrap: installs Traefik on PVE host + downloads LXC template (default ubuntu-24.04, --lxc-template flag) - linux bootstrap: installs Traefik on worker - emitter/traefik.go: directory provider (was single file); register pve-ct/pve-vm in RegisterTraefik - --lxc-template flag on node join (default ubuntu-24.04) ---ci--- project: orca milestone: v0.12.18 phase: B status: complete requirements: covered: [165, 167] ---/ci---
79 lines
2.3 KiB
Go
79 lines
2.3 KiB
Go
package traefik
|
|
|
|
import (
|
|
"fmt"
|
|
"os/exec"
|
|
"strings"
|
|
)
|
|
|
|
const DefaultVersion = "v3.3.0"
|
|
|
|
func downloadURL(version string) string {
|
|
return fmt.Sprintf("https://github.com/traefik/traefik/releases/download/%s/traefik_%s_linux_amd64.tar.gz", version, version)
|
|
}
|
|
|
|
func InstallLocal(version string) error {
|
|
if version == "" {
|
|
version = DefaultVersion
|
|
}
|
|
if _, err := exec.LookPath("traefik"); err == nil {
|
|
ensureDirs()
|
|
return nil
|
|
}
|
|
url := downloadURL(version)
|
|
cmd := exec.Command("bash", "-c",
|
|
fmt.Sprintf(`curl -fsSL %s | tar -xzf - -C /usr/local/bin/ traefik && chmod +x /usr/local/bin/traefik`, url))
|
|
if out, err := cmd.CombinedOutput(); err != nil {
|
|
return fmt.Errorf("download traefik %s: %w (output: %s)", version, err, string(out))
|
|
}
|
|
ensureDirs()
|
|
writeSystemdUnit()
|
|
_ = exec.Command("systemctl", "daemon-reload").Run()
|
|
_ = exec.Command("systemctl", "enable", "--now", "orca-traefik").Run()
|
|
return nil
|
|
}
|
|
|
|
type RemoteExecFunc func(cmd string) ([]byte, error)
|
|
|
|
func InstallRemote(version string, execFn RemoteExecFunc) error {
|
|
if version == "" {
|
|
version = DefaultVersion
|
|
}
|
|
if out, err := execFn("command -v traefik"); err == nil && len(strings.TrimSpace(string(out))) > 0 {
|
|
_, _ = execFn("mkdir -p /etc/traefik/dynamic")
|
|
return nil
|
|
}
|
|
url := downloadURL(version)
|
|
installCmd := fmt.Sprintf(`curl -fsSL %s | tar -xzf - -C /usr/local/bin/ traefik && chmod +x /usr/local/bin/traefik && mkdir -p /etc/traefik/dynamic`, url)
|
|
if out, err := execFn(installCmd); err != nil {
|
|
return fmt.Errorf("download traefik on remote: %w (output: %s)", err, string(out))
|
|
}
|
|
unit := systemdUnitContent()
|
|
_, _ = execFn(fmt.Sprintf(`echo '%s' > /etc/systemd/system/orca-traefik.service`, unit))
|
|
_, _ = execFn("systemctl daemon-reload && systemctl enable --now orca-traefik")
|
|
return nil
|
|
}
|
|
|
|
func ensureDirs() {
|
|
_ = exec.Command("mkdir", "-p", "/etc/traefik/dynamic").Run()
|
|
}
|
|
|
|
func writeSystemdUnit() {
|
|
_ = exec.Command("bash", "-c", fmt.Sprintf(`echo '%s' > /etc/systemd/system/orca-traefik.service`, systemdUnitContent())).Run()
|
|
}
|
|
|
|
func systemdUnitContent() string {
|
|
return `[Unit]
|
|
Description=Orca Traefik Data Plane
|
|
After=network.target
|
|
|
|
[Service]
|
|
Type=simple
|
|
ExecStart=/usr/local/bin/traefik --configFile=/etc/traefik/traefik.yml
|
|
Restart=on-failure
|
|
RestartSec=5s
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target`
|
|
}
|