Ready for production* Token middleware enabled again,* Production build Makefile Target (for older Debian)* Application name validation fix* Changed database location to /var/lib/node-api* Docker version changed a little lower to 1.38 (older Docker on some nodes)

This commit is contained in:
Adam Štrauch 2020-08-29 15:12:29 +02:00
parent a52e09ffef
commit 6b4fe9e39b
Signed by: cx
GPG Key ID: 018304FFA8988F8D
5 changed files with 18 additions and 5 deletions

2
Makefile Normal file
View File

@ -0,0 +1,2 @@
production-build:
podman run --rm --privileged -ti -v ${shell pwd}:/srv docker.io/library/golang:1.14-stretch /bin/sh -c "cd /srv && go build"

View File

@ -89,7 +89,7 @@ type App struct {
func (a *App) Validate() []string {
var errors []string
nameRegExp := regexp.MustCompile(`^[a-z0-9_]{3,48}$`)
nameRegExp := regexp.MustCompile(`^[a-z0-9_\-]{3,48}$`)
if !nameRegExp.MatchString(a.Name) {
errors = append(errors, "name can contain only characters, numbers and underscores and has to be between 3 and 48 characters")
}

View File

@ -13,7 +13,7 @@ var db *gorm.DB
func init() {
var err error
db, err = gorm.Open("sqlite3", "rosti.db")
db, err = gorm.Open("sqlite3", "/var/lib/node-api/rosti.db")
if err != nil {
log.Fatalln(err)
}

View File

@ -30,7 +30,7 @@ const dockerSock = "/var/run/docker.sock"
const podmanSock = "/run/podman/podman.sock"
// DOCKER_API_VERSION set API version of Docker, 1.40 belongs to Docker 19.03.11
const dockerAPIVersion = "1.40"
const dockerAPIVersion = "1.38"
// Driver keeps everything for connection to Docker
type Driver struct{}
@ -53,6 +53,7 @@ func (d *Driver) ConnectionStatus() (bool, error) {
if err != nil {
return false, err
}
defer cli.Close()
_, err = cli.ServerVersion(context.TODO())
if err != nil {
@ -86,6 +87,7 @@ func (d *Driver) Status(name string) (string, error) {
if err != nil {
return status, err
}
defer cli.Close()
containerID, err := d.nameToID(name)
if err != nil && err.Error() == "no container found" {
@ -112,6 +114,7 @@ func (d *Driver) RawStats(name string) (int64, int, error) {
if err != nil {
return 0.0, 0, err
}
defer cli.Close()
containerID, err := d.nameToID(name)
if err != nil {
@ -143,6 +146,7 @@ func (d *Driver) Stats(name string) (float64, int, error) {
if err != nil {
return 0.0, 0, err
}
defer cli.Close()
containerID, err := d.nameToID(name)
if err != nil {
@ -186,6 +190,7 @@ func (d *Driver) Remove(name string) error {
if err != nil {
return err
}
defer cli.Close()
containerID, err := d.nameToID(name)
if err != nil {
@ -210,6 +215,7 @@ func (d *Driver) Start(name string) error {
if err != nil {
return err
}
defer cli.Close()
containerID, err := d.nameToID(name)
if err != nil {
@ -228,6 +234,7 @@ func (d *Driver) Stop(name string) error {
if err != nil {
return err
}
defer cli.Close()
containerID, err := d.nameToID(name)
if err != nil {
@ -250,6 +257,7 @@ func (d *Driver) IsExist(name string) ([]string, error) {
if err != nil {
return containerIDs, err
}
defer cli.Close()
containers, err := cli.ContainerList(context.TODO(), types.ContainerListOptions{All: true})
if err != nil {
@ -276,6 +284,7 @@ func (d *Driver) pullImage(image string) error {
if err != nil {
return err
}
defer cli.Close()
stream, err := cli.ImagePull(context.TODO(), image, types.ImagePullOptions{})
if err != nil {
@ -299,6 +308,7 @@ func (d *Driver) Create(name string, image string, volumePath string, HTTPPort i
if err != nil {
return "", err
}
defer cli.Close()
err = d.pullImage(image)
if err != nil {
@ -385,6 +395,7 @@ func (d *Driver) Exec(name string, cmd []string, stdin string, env []string, att
if err != nil {
return &[]byte{}, err
}
defer cli.Close()
containerID, err := d.nameToID(name)
if err != nil {

View File

@ -46,7 +46,7 @@ func main() {
e := echo.New()
e.Renderer = t
/* e.Use(TokenMiddleware) */
e.Use(TokenMiddleware)
// UI
e.GET("/", homeHandler)
@ -102,5 +102,5 @@ func main() {
// Return info about the node including performance index
e.GET("/v1/node", getNodeInfoHandler)
e.Logger.Fatal(e.Start("127.0.0.1:1323"))
e.Logger.Fatal(e.Start(":1323"))
}