fix(controller): fixes for a remote update
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
socketio "github.com/googollee/go-socket.io"
|
||||
)
|
||||
|
||||
@@ -31,8 +32,6 @@ func registerUpdateChannel(server *socketio.Server) {
|
||||
server.OnEvent("/", "update", func(s socketio.Conn, payload UpdatePayload) {
|
||||
switch strings.ToLower(payload.Action) {
|
||||
case "copy":
|
||||
server.BroadcastToRoom("/", "update", "updateLogs",
|
||||
fmt.Sprintf("🚀 Copying latest build to %v", payload.Target))
|
||||
copyLatestBuild(server, payload.Target)
|
||||
|
||||
case "update":
|
||||
@@ -59,6 +58,7 @@ func updateServer(server *socketio.Server, target string) {
|
||||
|
||||
if strings.Contains(host, "VMS") || strings.Contains(host, "vms") {
|
||||
server.BroadcastToRoom("/", "update", "updateLogs", "Your are about to check for a new build and then update the server.")
|
||||
go UpdateApp(server)
|
||||
|
||||
return
|
||||
}
|
||||
@@ -80,16 +80,16 @@ func copyLatestBuild(server *socketio.Server, target string) {
|
||||
|
||||
func triggerRemoteUpdate(server *socketio.Server, remoteURL string, payload UpdatePayload) {
|
||||
|
||||
basePath := "/api/controller"
|
||||
if os.Getenv("NODE_ENV") != "production" {
|
||||
basePath = "/lst/api/controller"
|
||||
}
|
||||
// basePath := "/api/controller"
|
||||
// if os.Getenv("NODE_ENV") != "production" {
|
||||
// basePath = "/lst/api/controller"
|
||||
// }
|
||||
|
||||
// send POST request with JSON, expect SSE / streaming text back
|
||||
body, _ := json.Marshal(payload)
|
||||
|
||||
url := fmt.Sprintf("https://%v.alpla.net%v/update", remoteURL, basePath)
|
||||
//url := fmt.Sprintf("http://localhost:8080%v/update", basePath)
|
||||
//url := fmt.Sprintf("https://%v.alpla.net%v/update", remoteURL, basePath)
|
||||
url := fmt.Sprintf("http://%v:8080/api/controller/update", remoteURL)
|
||||
fmt.Println(url)
|
||||
resp, err := http.Post(url, "application/json", bytes.NewBuffer(body))
|
||||
if err != nil {
|
||||
@@ -116,3 +116,16 @@ func triggerRemoteUpdate(server *socketio.Server, remoteURL string, payload Upda
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func sendUpdate(c *gin.Context, flusher http.Flusher, server *socketio.Server, msg string) {
|
||||
// SSE stream
|
||||
if c != nil && flusher != nil {
|
||||
fmt.Fprintf(c.Writer, "event: log\ndata: %s\n\n", msg)
|
||||
flusher.Flush()
|
||||
}
|
||||
|
||||
// Socket.IO
|
||||
if server != nil {
|
||||
server.BroadcastToRoom("/", "update", "updateLogs", msg)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user