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