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:
parent
a52e09ffef
commit
6b4fe9e39b
2
Makefile
Normal file
2
Makefile
Normal 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"
|
@ -89,7 +89,7 @@ type App struct {
|
|||||||
func (a *App) Validate() []string {
|
func (a *App) Validate() []string {
|
||||||
var errors []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) {
|
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")
|
errors = append(errors, "name can contain only characters, numbers and underscores and has to be between 3 and 48 characters")
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ var db *gorm.DB
|
|||||||
func init() {
|
func init() {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
db, err = gorm.Open("sqlite3", "rosti.db")
|
db, err = gorm.Open("sqlite3", "/var/lib/node-api/rosti.db")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ const dockerSock = "/var/run/docker.sock"
|
|||||||
const podmanSock = "/run/podman/podman.sock"
|
const podmanSock = "/run/podman/podman.sock"
|
||||||
|
|
||||||
// DOCKER_API_VERSION set API version of Docker, 1.40 belongs to Docker 19.03.11
|
// 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
|
// Driver keeps everything for connection to Docker
|
||||||
type Driver struct{}
|
type Driver struct{}
|
||||||
@ -53,6 +53,7 @@ func (d *Driver) ConnectionStatus() (bool, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
defer cli.Close()
|
||||||
|
|
||||||
_, err = cli.ServerVersion(context.TODO())
|
_, err = cli.ServerVersion(context.TODO())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -86,6 +87,7 @@ func (d *Driver) Status(name string) (string, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return status, err
|
return status, err
|
||||||
}
|
}
|
||||||
|
defer cli.Close()
|
||||||
|
|
||||||
containerID, err := d.nameToID(name)
|
containerID, err := d.nameToID(name)
|
||||||
if err != nil && err.Error() == "no container found" {
|
if err != nil && err.Error() == "no container found" {
|
||||||
@ -112,6 +114,7 @@ func (d *Driver) RawStats(name string) (int64, int, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return 0.0, 0, err
|
return 0.0, 0, err
|
||||||
}
|
}
|
||||||
|
defer cli.Close()
|
||||||
|
|
||||||
containerID, err := d.nameToID(name)
|
containerID, err := d.nameToID(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -143,6 +146,7 @@ func (d *Driver) Stats(name string) (float64, int, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return 0.0, 0, err
|
return 0.0, 0, err
|
||||||
}
|
}
|
||||||
|
defer cli.Close()
|
||||||
|
|
||||||
containerID, err := d.nameToID(name)
|
containerID, err := d.nameToID(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -186,6 +190,7 @@ func (d *Driver) Remove(name string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
defer cli.Close()
|
||||||
|
|
||||||
containerID, err := d.nameToID(name)
|
containerID, err := d.nameToID(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -210,6 +215,7 @@ func (d *Driver) Start(name string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
defer cli.Close()
|
||||||
|
|
||||||
containerID, err := d.nameToID(name)
|
containerID, err := d.nameToID(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -228,6 +234,7 @@ func (d *Driver) Stop(name string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
defer cli.Close()
|
||||||
|
|
||||||
containerID, err := d.nameToID(name)
|
containerID, err := d.nameToID(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -250,6 +257,7 @@ func (d *Driver) IsExist(name string) ([]string, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return containerIDs, err
|
return containerIDs, err
|
||||||
}
|
}
|
||||||
|
defer cli.Close()
|
||||||
|
|
||||||
containers, err := cli.ContainerList(context.TODO(), types.ContainerListOptions{All: true})
|
containers, err := cli.ContainerList(context.TODO(), types.ContainerListOptions{All: true})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -276,6 +284,7 @@ func (d *Driver) pullImage(image string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
defer cli.Close()
|
||||||
|
|
||||||
stream, err := cli.ImagePull(context.TODO(), image, types.ImagePullOptions{})
|
stream, err := cli.ImagePull(context.TODO(), image, types.ImagePullOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -299,6 +308,7 @@ func (d *Driver) Create(name string, image string, volumePath string, HTTPPort i
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
defer cli.Close()
|
||||||
|
|
||||||
err = d.pullImage(image)
|
err = d.pullImage(image)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -385,6 +395,7 @@ func (d *Driver) Exec(name string, cmd []string, stdin string, env []string, att
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return &[]byte{}, err
|
return &[]byte{}, err
|
||||||
}
|
}
|
||||||
|
defer cli.Close()
|
||||||
|
|
||||||
containerID, err := d.nameToID(name)
|
containerID, err := d.nameToID(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
4
main.go
4
main.go
@ -46,7 +46,7 @@ func main() {
|
|||||||
e := echo.New()
|
e := echo.New()
|
||||||
e.Renderer = t
|
e.Renderer = t
|
||||||
|
|
||||||
/* e.Use(TokenMiddleware) */
|
e.Use(TokenMiddleware)
|
||||||
|
|
||||||
// UI
|
// UI
|
||||||
e.GET("/", homeHandler)
|
e.GET("/", homeHandler)
|
||||||
@ -102,5 +102,5 @@ func main() {
|
|||||||
// Return info about the node including performance index
|
// Return info about the node including performance index
|
||||||
e.GET("/v1/node", getNodeInfoHandler)
|
e.GET("/v1/node", getNodeInfoHandler)
|
||||||
|
|
||||||
e.Logger.Fatal(e.Start("127.0.0.1:1323"))
|
e.Logger.Fatal(e.Start(":1323"))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user