Allow installation of local modules
This commit is contained in:
parent
069aed2c7a
commit
b747ad94f6
@ -5,7 +5,6 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
//"bytes"
|
||||
"net/http"
|
||||
@ -51,17 +50,17 @@ func getSchema(c echo.Context) error {
|
||||
key := c.Param("container")
|
||||
|
||||
|
||||
requestURL := fmt.Sprintf("http://%s/schema", key)
|
||||
requestURL := fmt.Sprintf("http://%s:8080/schema", key)
|
||||
resp, err := http.Get(requestURL)
|
||||
if err != nil {
|
||||
log.Fatalf("Request to container failed: %v", err)
|
||||
panic(err)
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to print Body: %v", err)
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return c.JSONBlob(resp.StatusCode, body)
|
||||
@ -74,14 +73,14 @@ func getComponent(c echo.Context) error {
|
||||
requestURL := fmt.Sprintf("http://%s:8080/component/%s", container, component)
|
||||
resp, err := http.Get(requestURL)
|
||||
if err != nil {
|
||||
log.Fatalf("Request to container failed: %v", err)
|
||||
panic(err)
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to print Body: %v", err)
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return c.JSONBlob(http.StatusOK, body)
|
||||
@ -94,14 +93,14 @@ func postComponent(c echo.Context) error {
|
||||
requestURL := fmt.Sprintf("http://%s:8080/component/%s", container, component)
|
||||
resp, err := http.Post(requestURL, "application/json", c.Request().Body)
|
||||
if err != nil {
|
||||
log.Fatalf("Request to container failed: %v", err)
|
||||
panic(err)
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to print Body: %v", err)
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return c.JSONBlob(http.StatusOK, body)
|
||||
@ -155,14 +154,14 @@ func postFromModule(c echo.Context) error {
|
||||
requestURL := fmt.Sprintf("http://%s", url)
|
||||
resp, err := http.Post(requestURL, "application/json", c.Request().Body)
|
||||
if err != nil {
|
||||
log.Fatalf("Request to container failed: %v", err)
|
||||
panic(err)
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to print Body: %v", err)
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return c.JSONBlob(http.StatusOK, body)
|
||||
@ -258,6 +257,7 @@ func CreateModule(c echo.Context) error {
|
||||
s, _ := json.MarshalIndent(module, "", " ")
|
||||
fmt.Println(string(s))
|
||||
mod_id := docker.CreateModule(module)
|
||||
fmt.Println(mod_id)
|
||||
stmt, err := db.Prepare(`INSERT INTO Module (name, container_name) VALUES ($1, $2);`)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
||||
@ -74,17 +74,18 @@ func CreateModule(module Module) string {
|
||||
ContainerConfig(module, &container, &host, &network)
|
||||
|
||||
image_out, err := cli.ImagePull(ctx, module.Image, types.ImagePullOptions{})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
if err == nil {
|
||||
defer image_out.Close()
|
||||
io.Copy(ioutil.Discard, image_out)
|
||||
}
|
||||
defer image_out.Close()
|
||||
io.Copy(ioutil.Discard, image_out)
|
||||
fmt.Println("test1")
|
||||
|
||||
resp, err := cli.ContainerCreate(ctx, &container, &host, &network, nil, module.Name)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println("test2")
|
||||
|
||||
if _, err := cli.NetworkInspect(ctx, module.ID, types.NetworkInspectOptions{}); err != nil {
|
||||
networkConfig := types.NetworkCreate{
|
||||
@ -94,14 +95,17 @@ func CreateModule(module Module) string {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
fmt.Println("test3")
|
||||
|
||||
if err := cli.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{}); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println("test3")
|
||||
|
||||
if err := cli.NetworkConnect(ctx, module.ID, os.Getenv("hostname"), &networktypes.EndpointSettings{}); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println("test4")
|
||||
|
||||
return resp.ID
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user