Something

This commit is contained in:
rony5394
2026-02-20 21:47:11 +01:00
parent 91c16cf429
commit 11f01ab459
5 changed files with 174 additions and 90 deletions

View File

@@ -1,15 +1,19 @@
package host
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"os"
cfg "github.com/rony5394/blazena/config"
"github.com/moby/moby/client"
)
var token string = "12345";
var DockerClient *client.Client;
type aService struct{
ServiceId string `json:"serviceId"`;
@@ -26,15 +30,36 @@ func Run(Config cfg.Config) {
fmt.Println("Node", service.Node, "refferenced in", service.ServiceId ,"service does not exists!");
continue;
}
for _, volume := range service.VolumeNames{
remoteFilePath := Config.Nodes[service.Node].DockerVolumePath + "/" + volume;
remotePath := Config.User + "@" + Config.Nodes[service.Node].Ip + ":" + remoteFilePath;
base := "rsync -avh --delete --progress -e 'ssh -i ./ssh-key' ";
localPath := Config.LocalBasePath + "/@current/@" + service.Node;
var body struct{
ServiceId string `json:"serviceId"`
} = struct{ServiceId string "json:\"serviceId\""}{
ServiceId: service.ServiceId,
}
fmt.Println(base + remotePath + " " + localPath);
bodyEncoded, err := json.Marshal(body);
if err != nil {
panic("Failed to marshal body."+ err.Error());
}
rq, err := http.NewRequest("POST", Config.DockerManagerBaseUrl + "/prepare", bytes.NewBuffer(bodyEncoded));
if err != nil{
panic("Failed to create http request"+ err.Error());
}
rq.Header.Set("Authorization", "Bearer "+ token);
rq.Close = true;
rs, err := http.DefaultClient.Do(rq);
defer rs.Body.Close();
if err != nil{
panic("Failed to send http request"+ err.Error());
}
os.Exit(0);
}
}