Possibility to set technology version
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Adam Štrauch 2021-12-23 14:01:27 +01:00
parent 6f532b052e
commit 2a34177ab8
Signed by: cx
GPG key ID: 018304FFA8988F8D
3 changed files with 36 additions and 10 deletions

View file

@ -247,10 +247,18 @@ func (c *Container) SetFileContent(filename string, text string, mode string) er
// SetTechnology prepares container for given technology (Python, PHP, Node.js, ...)
// Where tech can be php, python or node and latest available version is used.
func (c *Container) SetTechnology(tech string) error {
// If version is empty string default version will be used.
func (c *Container) SetTechnology(tech string, version string) error {
driver := c.getDriver()
_, err := driver.Exec(c.App.Name, []string{"su", "app", "-c", "rosti " + tech}, "", []string{}, false)
var err error
// TODO: script injection here?
if version == "" {
_, err = driver.Exec(c.App.Name, []string{"su", "app", "-c", "rosti " + tech}, "", []string{}, false)
} else {
_, err = driver.Exec(c.App.Name, []string{"su", "app", "-c", "rosti " + tech + " " + version}, "", []string{}, false)
}
return err
}

View file

@ -320,49 +320,49 @@ func setServicesHandler(c echo.Context) error {
}
if quickServices.Python {
err = container.SetTechnology("python")
err = container.SetTechnology("python", "")
if err != nil {
return c.JSONPretty(http.StatusInternalServerError, Message{Message: err.Error()}, JSONIndent)
}
}
if quickServices.PHP {
err = container.SetTechnology("php")
err = container.SetTechnology("php", "")
if err != nil {
return c.JSONPretty(http.StatusInternalServerError, Message{Message: err.Error()}, JSONIndent)
}
}
if quickServices.Node {
err = container.SetTechnology("node")
err = container.SetTechnology("node", "")
if err != nil {
return c.JSONPretty(http.StatusInternalServerError, Message{Message: err.Error()}, JSONIndent)
}
}
if quickServices.Ruby {
err = container.SetTechnology("ruby")
err = container.SetTechnology("ruby", "")
if err != nil {
return c.JSONPretty(http.StatusInternalServerError, Message{Message: err.Error()}, JSONIndent)
}
}
if quickServices.Deno {
err = container.SetTechnology("deno")
err = container.SetTechnology("deno", "")
if err != nil {
return c.JSONPretty(http.StatusInternalServerError, Message{Message: err.Error()}, JSONIndent)
}
}
if quickServices.Memcached {
err = container.SetTechnology("memcached")
err = container.SetTechnology("memcached", "")
if err != nil {
return c.JSONPretty(http.StatusInternalServerError, Message{Message: err.Error()}, JSONIndent)
}
}
if quickServices.Redis {
err = container.SetTechnology("redis")
err = container.SetTechnology("redis", "")
if err != nil {
return c.JSONPretty(http.StatusInternalServerError, Message{Message: err.Error()}, JSONIndent)
}

View file

@ -15,6 +15,7 @@ import (
"encoding/json"
"fmt"
"log"
"regexp"
"strings"
"github.com/nats-io/nats.go"
@ -612,8 +613,25 @@ func processesEventHandler(m *nats.Msg, message *RequestMessage) error {
}
// Enable one of the supported technologies or services (python, node, redis, ...)
// If payload contains only name of the tech the default version for given image is selected.
// Otherwise it can be passed in format tech:version.
func enableTechEventHandler(m *nats.Msg, message *RequestMessage) error {
if !regexp.Match("[a-z0-9A-Z]*:?[0-9\.\-]*", []byte(message.Payload)) {
return errors.New("payload malformation, it has to be in format tech:version")
}
service := message.Payload
version := ""
if strings.Contains(service, ":") {
parts := strings.SplitN(message.Payload, ":", 2)
if len(parts) != 2 {
return errors.New("service and version malformat")
}
service = parts[0]
version = parts[1]
}
err := waitForApp(message.AppName)
if err != nil {
@ -636,7 +654,7 @@ func enableTechEventHandler(m *nats.Msg, message *RequestMessage) error {
App: app,
}
err = container.SetTechnology(service)
err = container.SetTechnology(service, version)
if err != nil {
log.Println("ERROR enable tech problem: " + err.Error())
publish(app.Name, "backend problem", true)