feat: auto-detect podman/docker in agent, add studentId to activation response, fix download URLs

This commit is contained in:
root
2026-06-06 21:14:24 +00:00
parent a1883080d3
commit 349c8d0e2a
11 changed files with 132 additions and 20 deletions
+3 -2
View File
@@ -7,9 +7,10 @@ import (
)
type Activation struct {
Activated bool `json:"activated"`
Activated bool `json:"activated"`
StudentId string `json:"studentId,omitempty"`
StudentName string `json:"studentName,omitempty"`
Code string `json:"code,omitempty"`
Code string `json:"code,omitempty"`
}
func activationFile(dataDir string) string {
+10 -3
View File
@@ -10,6 +10,13 @@ func instanceDir(dataDir, instanceID string) string {
return filepath.Join(dataDir, "instances", instanceID)
}
func getContainerEngine() string {
if _, err := exec.LookPath("podman"); err == nil {
return "podman"
}
return "docker"
}
func writeCompose(dataDir, instanceID, compose string) error {
dir := instanceDir(dataDir, instanceID)
if err := os.MkdirAll(dir, 0755); err != nil {
@@ -21,7 +28,7 @@ func writeCompose(dataDir, instanceID, compose string) error {
func dockerComposeUp(dataDir, instanceID string) error {
dir := instanceDir(dataDir, instanceID)
cmd := exec.Command("docker", "compose", "-f", filepath.Join(dir, "docker-compose.yml"), "up", "-d")
cmd := exec.Command(getContainerEngine(), "compose", "-f", filepath.Join(dir, "docker-compose.yml"), "up", "-d")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
@@ -29,7 +36,7 @@ func dockerComposeUp(dataDir, instanceID string) error {
func dockerComposeDown(dataDir, instanceID string) error {
dir := instanceDir(dataDir, instanceID)
cmd := exec.Command("docker", "compose", "-f", filepath.Join(dir, "docker-compose.yml"), "down")
cmd := exec.Command(getContainerEngine(), "compose", "-f", filepath.Join(dir, "docker-compose.yml"), "down")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
@@ -37,7 +44,7 @@ func dockerComposeDown(dataDir, instanceID string) error {
func dockerComposeRm(dataDir, instanceID string) error {
dir := instanceDir(dataDir, instanceID)
cmd := exec.Command("docker", "compose", "-f", filepath.Join(dir, "docker-compose.yml"), "down", "-v")
cmd := exec.Command(getContainerEngine(), "compose", "-f", filepath.Join(dir, "docker-compose.yml"), "down", "-v")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
+2 -1
View File
@@ -15,6 +15,7 @@ type WSMessage struct {
Type string `json:"type,omitempty"`
Port int `json:"port,omitempty"`
ComposeConfig string `json:"composeConfig,omitempty"`
StudentId string `json:"studentId,omitempty"`
StudentName string `json:"studentName,omitempty"`
Error string `json:"error,omitempty"`
}
@@ -84,7 +85,7 @@ func handleMessage(conn *websocket.Conn, msg WSMessage, dataDir, nodeID string)
case "activate":
// handled by UI, but server can also push activation response
if msg.StudentName != "" {
act := &Activation{Activated: true, StudentName: msg.StudentName, Code: msg.Code}
act := &Activation{Activated: true, StudentId: msg.StudentId, StudentName: msg.StudentName, Code: msg.Code}
saveActivation(dataDir, act)
log.Printf("Activated as %s", msg.StudentName)
}