fixed adding public key as parameter when spawning a container
This commit is contained in:
@@ -20,18 +20,17 @@ import (
|
||||
)
|
||||
|
||||
type DockerVM struct {
|
||||
SSHUsername string `json:"SSHUsername"`
|
||||
SSHPublcKey string `json:"SSHPublicKey"`
|
||||
SSHPrivateKey string `json:"SSHPrivateKey"`
|
||||
ID string `json:"ID"`
|
||||
TagName string `json:"TagName"`
|
||||
ImagePath string `json:"ImagePath"`
|
||||
Ports Ports `json:"Ports"`
|
||||
GPU string `json:"GPU"`
|
||||
TempPath string
|
||||
BaseImage string
|
||||
LogsPath string
|
||||
SSHCommand string `json:"SSHCommand"`
|
||||
SSHUsername string `json:"SSHUsername"`
|
||||
SSHPublcKey string `json:"SSHPublicKey"`
|
||||
ID string `json:"ID"`
|
||||
TagName string `json:"TagName"`
|
||||
ImagePath string `json:"ImagePath"`
|
||||
Ports Ports `json:"Ports"`
|
||||
GPU string `json:"GPU"`
|
||||
TempPath string
|
||||
BaseImage string
|
||||
LogsPath string
|
||||
SSHCommand string `json:"SSHCommand"`
|
||||
}
|
||||
|
||||
type DockerContainers struct {
|
||||
@@ -68,7 +67,7 @@ var dockerRegistryUserID = ""
|
||||
|
||||
// BuildRunContainer Function is incharge to invoke building and running contianer and also allocating external
|
||||
// ports
|
||||
func BuildRunContainer(NumPorts int, GPU string, ContainerName string, baseImage string) (*DockerVM, error) {
|
||||
func BuildRunContainer(NumPorts int, GPU string, ContainerName string, baseImage string, publicKey string) (*DockerVM, error) {
|
||||
//Docker Struct Variable
|
||||
var RespDocker *DockerVM = new(DockerVM)
|
||||
|
||||
@@ -95,8 +94,7 @@ func BuildRunContainer(NumPorts int, GPU string, ContainerName string, baseImage
|
||||
}
|
||||
RespDocker.ImagePath = config.DefaultDockerFile
|
||||
RespDocker.LogsPath = config.DockerRunLogs
|
||||
RespDocker.SSHPublcKey = config.PublicKeyFile
|
||||
RespDocker.SSHPrivateKey = config.PrivateKeyFile
|
||||
RespDocker.SSHPublcKey = publicKey
|
||||
|
||||
// We are checking if the container name is not nil and not equal to the default one used
|
||||
// which is docker-ubuntu-sshd
|
||||
@@ -198,10 +196,9 @@ func (d *DockerVM) imageBuild(dockerClient *client.Client) error {
|
||||
//defer cancel()
|
||||
|
||||
var cmd bytes.Buffer
|
||||
cmd.WriteString("docker build -t " + d.TagName + " " + d.ImagePath + "/" + d.TagName + ` --build-arg SSH_KEY="$(cat ` + d.SSHPublcKey + `)"`)
|
||||
cmd.WriteString("docker build -t " + d.TagName + " " + d.ImagePath + "/" + d.TagName + ` --build-arg SSH_KEY="` + d.SSHPublcKey + `"`)
|
||||
//"-v=/opt/data:/data p2p-ubuntu /start > /dev/null"
|
||||
cmdStr := cmd.String()
|
||||
fmt.Println(cmdStr)
|
||||
output, err := exec.Command("/bin/sh", "-c", cmdStr).Output()
|
||||
fmt.Printf("%s", output)
|
||||
if err != nil {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
b64 "encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/Akilan1999/p2p-rendering-computation/client/clientIPTable"
|
||||
@@ -108,14 +109,26 @@ func Server() (*gin.Engine, error) {
|
||||
GPU := c.DefaultQuery("GPU", "false")
|
||||
ContainerName := c.DefaultQuery("ContainerName", "")
|
||||
BaseImage := c.DefaultQuery("BaseImage", "")
|
||||
PublicKey := c.DefaultQuery("PublicKey", "")
|
||||
var PortsInt int
|
||||
|
||||
if PublicKey == "" {
|
||||
c.String(http.StatusInternalServerError, fmt.Sprintf("error: %s", "Publickey not passed"))
|
||||
}
|
||||
|
||||
PublicKeyDecoded, err := b64.StdEncoding.DecodeString(PublicKey)
|
||||
if err != nil {
|
||||
c.String(http.StatusInternalServerError, fmt.Sprintf("error: %s", err))
|
||||
}
|
||||
|
||||
// Convert Get Request value to int
|
||||
fmt.Sscanf(Ports, "%d", &PortsInt)
|
||||
|
||||
fmt.Println(string(PublicKeyDecoded[:]))
|
||||
|
||||
// Creates container and returns-back result to
|
||||
// access container
|
||||
resp, err := docker.BuildRunContainer(PortsInt, GPU, ContainerName, BaseImage)
|
||||
resp, err := docker.BuildRunContainer(PortsInt, GPU, ContainerName, BaseImage, string(PublicKeyDecoded[:]))
|
||||
|
||||
if err != nil {
|
||||
c.String(http.StatusInternalServerError, fmt.Sprintf("error: %s", err))
|
||||
|
||||
Reference in New Issue
Block a user