diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..3e61608 --- /dev/null +++ b/Makefile @@ -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" diff --git a/apps/types.go b/apps/types.go index b1a2a8a..a9a6513 100644 --- a/apps/types.go +++ b/apps/types.go @@ -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") } diff --git a/common/db.go b/common/db.go index 249866c..fd33d2b 100644 --- a/common/db.go +++ b/common/db.go @@ -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) } diff --git a/docker/docker.go b/docker/docker.go index f95858c..2f47925 100644 --- a/docker/docker.go +++ b/docker/docker.go @@ -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 { diff --git a/main.go b/main.go index 5bafa4d..61195f8 100644 --- a/main.go +++ b/main.go @@ -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")) }