Compare commits

..

No commits in common. "main" and "v11" have entirely different histories.
main ... v11

8 changed files with 16 additions and 157 deletions

View file

@ -11,22 +11,20 @@ jobs:
deploy-production:
runs-on: [amd64, prod]
env:
NODES: node-22.rosti.cz node-23.rosti.cz node-24.rosti.cz node-25.rosti.cz node-28.rosti.cz node-29.rosti.cz
NODES: node-22.rosti.cz node-23.rosti.cz node-24.rosti.cz node-25.rosti.cz
steps:
- uses: actions/checkout@v4
- name: deploy
run: |
echo "Building for Debian 12 .."
docker run --rm --privileged -ti -v `pwd`:/srv golang:1.25-trixie /bin/sh -c "cd /srv && go build"
docker run --rm --privileged -ti -v `pwd`:/srv golang:1.21-bookworm /bin/sh -c "cd /srv && go build"
for NODE in $NODES; do
# Clear known hosts
rm -f ~/.ssh/known_hosts
echo "\033[0;32mDeploying $NODE\033[0m"
echo "\033[1;33m.. scanning SSH keys\033[0m"
ssh -o "StrictHostKeyChecking=no" root@$NODE echo "Setting up key"
echo "\033[1;33m.. copying the binary\033[0m"
scp -O node-api root@$NODE:/usr/local/bin/node-api_
scp node-api root@$NODE:/usr/local/bin/node-api_
echo "\033[1;33m.. replacing the binary\033[0m"
ssh root@$NODE mv /usr/local/bin/node-api_ /usr/local/bin/node-api
echo "\033[1;33m.. restarting service\033[0m"

View file

@ -7,7 +7,7 @@ on:
jobs:
unittests:
runs-on: [amd64, dev]
runs-on: [amd64, moon]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v3
@ -36,19 +36,17 @@ jobs:
# - 9001:9001
# options: server /data --console-address :9001
deploy-dev:
runs-on: [amd64, dev]
runs-on: [amd64, moon]
env:
NODES: "192.168.15.160"
NODES: "192.168.1.33"
steps:
- uses: actions/checkout@v4
- uses: webfactory/ssh-agent@v0.9.1
with:
ssh-private-key: ${{ secrets.SSH_MASTER_KEY }}
- name: deploy
run: |
# echo LS1
# ls
docker run --rm --privileged -ti -v `pwd`:/srv golang:1.25-trixie /bin/sh -c "cd /srv && go build"
docker run --rm --privileged -ti -v `pwd`:/srv golang:1.20-buster /bin/sh -c "cd /srv && go build"
# docker run --rm --privileged -ti -v `pwd`:/srv golang:1.20-buster /bin/sh -c "cd /srv && echo LS2 && ls"
for NODE in $NODES; do
echo "\033[0;32mDeploying $NODE\033[0m"
@ -61,4 +59,4 @@ jobs:
echo "\033[1;33m.. restarting service\033[0m"
ssh root@$NODE systemctl restart node-api
done

View file

@ -6,8 +6,8 @@ test:
# env DOCKER_SOCKET="unix:///var/run/docker.sock" go test -v containers/*.go # Doesn't work in Drone right now
build:
podman run --rm --privileged -ti -v ${shell pwd}:/srv docker.io/library/golang:1.24-bookworm /bin/sh -c "cd /srv && go build -o node-api-bookworm"
#go build -a -ldflags "-linkmode external -extldflags '-static' -s -w"
#podman run --rm --privileged -ti -v ${shell pwd}:/srv docker.io/library/golang:1.14-stretch /bin/sh -c "cd /srv && go build"
go build -a -ldflags "-linkmode external -extldflags '-static' -s -w"
.PHONY: minio
minio:

View file

@ -338,22 +338,16 @@ func (d *Driver) Create(name string, image string, volumePath string, HTTPPort i
}
}
// OOMKillDisable := false
// if memory < 1500 {
// OOMKillDisable = true
// }
// We disable OOM killer because it keeps containers in resource heavy loop
// This is from some discussion: If OOM-killer is disabled, tasks under cgroup will hang/sleep in memory cgroup's OOM-waitqueue when they request accountable memory.
// Disabling OOM killer kills the whole machine because some kernel processes get under memory pressure and the host system becomes unresponsive.
OOMKillDisable := false
if memory < 1500 {
OOMKillDisable = true
}
envList := []string{}
for key, value := range env {
envList = append(envList, key+"="+value)
}
pidLimit := int64(2024)
createdContainer, err := cli.ContainerCreate(
context.Background(),
&container.Config{
@ -373,7 +367,6 @@ func (d *Driver) Create(name string, image string, volumePath string, HTTPPort i
Memory: int64(memory*110/100) * 1024 * 1024, // Allow 10 % more memory so we have space for MemoryReservation
MemoryReservation: int64(memory) * 1024 * 1024, // This should provide softer way how to limit the memory of our containers
OomKillDisable: &OOMKillDisable,
PidsLimit: &pidLimit,
},
PortBindings: portBindings,
AutoRemove: false,

View file

@ -100,9 +100,6 @@ func (p *Processor) waitForApp() error {
return err
}
if status.Status == "running" {
if i > 0 {
time.Sleep(sleepFor) // We wait a little bit more to make sure the container is fully started
}
return nil
}

View file

@ -3,6 +3,7 @@ package main
import (
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"os"
@ -235,7 +236,7 @@ func clearPasswordHandler(c echo.Context) error {
func setKeysHandler(c echo.Context) error {
name := c.Param("name")
body, err := io.ReadAll(c.Request().Body)
body, err := ioutil.ReadAll(c.Request().Body)
if err != nil {
return c.JSONPretty(http.StatusInternalServerError, Message{Message: err.Error()}, JSONIndent)
}
@ -494,119 +495,3 @@ func metricsHandler(c echo.Context) error {
return c.String(http.StatusOK, metrics)
}
func CreateSnapshotHandler(c echo.Context) error {
name := c.Param("name")
body := createSnapshotBody{}
err := c.Bind(body)
if err != nil {
return c.JSONPretty(http.StatusBadRequest, Message{Message: err.Error()}, JSONIndent)
}
processor := glue.Processor{
AppName: name,
DB: common.GetDBConnection(),
SnapshotProcessor: &snapshotProcessor,
DockerSock: config.DockerSocket,
BindIPHTTP: config.AppsBindIPHTTP,
BindIPSSH: config.AppsBindIPSSH,
AppsPath: config.AppsPath,
}
err = processor.CreateSnapshot(body.Labels)
if err != nil {
return c.JSONPretty(http.StatusInternalServerError, Message{Message: err.Error()}, JSONIndent)
}
return c.JSONPretty(http.StatusOK, Message{Message: "ok"}, JSONIndent)
}
func RestoreFromSnapshotHandler(c echo.Context) error {
name := c.Param("name")
snapshot := c.Param("snapshot")
processor := glue.Processor{
AppName: name,
DB: common.GetDBConnection(),
SnapshotProcessor: &snapshotProcessor,
DockerSock: config.DockerSocket,
BindIPHTTP: config.AppsBindIPHTTP,
BindIPSSH: config.AppsBindIPSSH,
AppsPath: config.AppsPath,
}
err := processor.RestoreFromSnapshot(snapshot)
if err != nil {
return c.JSONPretty(http.StatusInternalServerError, Message{Message: err.Error()}, JSONIndent)
}
return c.JSONPretty(http.StatusOK, Message{Message: "ok"}, JSONIndent)
}
func ListSnapshotsHandler(c echo.Context) error {
name := c.Param("name")
processor := glue.Processor{
AppName: name,
DB: common.GetDBConnection(),
SnapshotProcessor: &snapshotProcessor,
DockerSock: config.DockerSocket,
BindIPHTTP: config.AppsBindIPHTTP,
BindIPSSH: config.AppsBindIPSSH,
AppsPath: config.AppsPath,
}
snapshots, err := processor.ListSnapshots()
if err != nil {
return c.JSONPretty(http.StatusInternalServerError, Message{Message: err.Error()}, JSONIndent)
}
return c.JSON(http.StatusOK, snapshots)
}
func ListAppsSnapshotsHandler(c echo.Context) error {
name := c.Param("name")
apps := []string{}
err := c.Bind(&apps)
if err != nil {
return c.JSONPretty(http.StatusBadRequest, Message{Message: err.Error()}, JSONIndent)
}
processor := glue.Processor{
AppName: name,
DB: common.GetDBConnection(),
SnapshotProcessor: &snapshotProcessor,
DockerSock: config.DockerSocket,
BindIPHTTP: config.AppsBindIPHTTP,
BindIPSSH: config.AppsBindIPSSH,
AppsPath: config.AppsPath,
}
snapshots, err := processor.ListAppsSnapshots(apps)
if err != nil {
return c.JSONPretty(http.StatusInternalServerError, Message{Message: err.Error()}, JSONIndent)
}
return c.JSON(http.StatusOK, snapshots)
}
func ListSnapshotsByLabelHandler(c echo.Context) error {
label := c.Param("label")
processor := glue.Processor{
AppName: "",
DB: common.GetDBConnection(),
SnapshotProcessor: &snapshotProcessor,
DockerSock: config.DockerSocket,
BindIPHTTP: config.AppsBindIPHTTP,
BindIPSSH: config.AppsBindIPSSH,
AppsPath: config.AppsPath,
}
snapshots, err := processor.ListSnapshotsByLabel(label)
if err != nil {
return c.JSONPretty(http.StatusInternalServerError, Message{Message: err.Error()}, JSONIndent)
}
return c.JSON(http.StatusOK, snapshots)
}

View file

@ -198,13 +198,6 @@ func main() {
// Delete one app
e.DELETE("/v1/apps/:name", deleteAppHandler)
// Snapshots
e.POST("/v1/apps/:name/snapshots", CreateSnapshotHandler)
e.POST("/v1/apps/:name/snapshots/restore/:snapshot", RestoreFromSnapshotHandler)
e.GET("/v1/apps/:name/snapshots", ListSnapshotsHandler)
e.GET("/v1/snapshots", ListAppsSnapshotsHandler)
e.GET("/v1/snapshots/by-label", ListSnapshotsByLabelHandler)
// Orphans returns directories in /srv that doesn't match any hosted application
e.GET("/v1/orphans", getOrphansHander)

View file

@ -56,7 +56,6 @@ type QuickServices struct {
PHP bool `json:"php"`
Ruby bool `json:"ruby"`
Deno bool `json:"deno"`
Bun bool `json:"bun"`
Memcached bool `json:"memcached"`
Redis bool `json:"redis"`
}
@ -66,7 +65,3 @@ type Technology struct {
Name string
Version string
}
type createSnapshotBody struct {
Labels []string `json:"labels"`
}