Compare commits

...

16 Commits
v2 ... main

Author SHA1 Message Date
cx 9e82bfc2b5 Chagne node-x ip
Unittests / unittests (push) Successful in 1m23s Details
Unittests / deploy-dev (push) Successful in 1m15s Details
2024-04-15 10:30:05 +00:00
Adam Štrauch e0b5832e75
Fix deps and crashing when deleting nonexistant app
Unittests / unittests (push) Successful in 9s Details
Unittests / deploy-dev (push) Successful in 59s Details
2024-03-03 02:55:05 +01:00
Adam Štrauch 863d857283
Restart container when tech changes
Unittests / unittests (push) Successful in 10s Details
Unittests / deploy-dev (push) Successful in 47s Details
2024-02-01 22:02:22 +01:00
Adam Štrauch 1c5b8d8f50
Add better debug message to SetTechnology
Unittests / unittests (push) Successful in 9s Details
Unittests / deploy-dev (push) Successful in 46s Details
2024-02-01 21:57:34 +01:00
Adam Štrauch bc4b6c7bff
Possibility to set tech during update
Unittests / unittests (push) Successful in 9s Details
Unittests / deploy-dev (push) Successful in 53s Details
2024-02-01 20:57:13 +01:00
Adam Štrauch 45899f3b0c
Set owner of metadata
Unittests / unittests (push) Successful in 9s Details
Unittests / deploy-dev (push) Successful in 45s Details
2024-01-31 00:16:40 +01:00
Adam Štrauch 5513da35b3
Fix endpoint name for metadata
Unittests / unittests (push) Successful in 9s Details
Unittests / deploy-dev (push) Successful in 44s Details
2024-01-30 23:52:33 +01:00
Adam Štrauch 31ba1ce5a3
Save metadata endpoint
Unittests / unittests (push) Successful in 9s Details
Unittests / deploy-dev (push) Successful in 46s Details
2024-01-30 23:50:03 +01:00
Adam Štrauch a3d0ee92ce
Stats errors in Sentry
Unittests / unittests (push) Successful in 9s Details
Unittests / deploy-dev (push) Successful in 52s Details
2024-01-26 21:43:45 +01:00
Adam Štrauch 7a170e56d6
Gather more errors in Sentry
Unittests / unittests (push) Successful in 9s Details
Unittests / deploy-dev (push) Successful in 54s Details
2024-01-26 21:15:14 +01:00
Adam Štrauch 4e9398512e
Removing drone pipeline 2024-01-26 21:13:58 +01:00
Adam Štrauch a4e2bac0ff
Adding Sentry
Unittests / unittests (push) Successful in 16s Details
Unittests / deploy-dev (push) Successful in 47s Details
2024-01-26 18:46:19 +01:00
Adam Štrauch 02cdf5f815
Fix archive path
Unittests / unittests (push) Successful in 14s Details
Unittests / deploy-dev (push) Successful in 1m0s Details
2023-12-13 17:45:17 +01:00
Adam Štrauch 036587a77a
Volume preparation fix
Unittests / unittests (push) Successful in 14s Details
Unittests / deploy-dev (push) Successful in 1m9s Details
2023-12-13 17:40:28 +01:00
Adam Štrauch 6d62b200a4
Change suffix to .tar.zst
Unittests / unittests (push) Successful in 17s Details
Unittests / deploy-dev (push) Successful in 1m7s Details
2023-12-13 17:32:20 +01:00
Adam Štrauch 9564118f40
Add possibility to prepare /srv from an archive
Unittests / unittests (push) Successful in 18s Details
Unittests / deploy-dev (push) Successful in 1m13s Details
2023-12-08 19:01:07 +01:00
16 changed files with 2426 additions and 902 deletions

View File

@ -1,264 +0,0 @@
kind: pipeline
type: docker
name: testing
steps:
- name: unittests
image: golang:1.18-bullseye
environment:
SNAPSHOTS_S3_ENDPOINT: minio:9000
TEST_S3_ENDPOINT: minio:9000
volumes:
- name: dockersock
path: /var/run
commands:
- apt update && apt upgrade -y
- apt install -y tar zstd
- sleep 10
- go mod tidy
- make test
services:
- name: minio
image: minio/minio:latest
environment:
MINIO_ROOT_USER: test
MINIO_ROOT_PASSWORD: testtest
command:
- server
- /data
- --console-address
- :9001
- name: docker
image: docker:dind
privileged: true
volumes:
- name: dockersock
path: /var/run
volumes:
- name: dockersock
temp: {}
---
kind: pipeline
type: docker
name: Dev deploy
steps:
- name: build
# image: golang:1.17-buster # this one is used in production
image: golang:1.17-bullseye # this one is used in dev
commands:
- go mod tidy
- make build
- name: deploy
image: debian:buster
environment:
#NODE: node-x.rosti.cz
NODES: 192.168.1.236 192.168.1.220
SSH_KEY:
from_secret: SSH_KEY
commands:
- apt update && apt install -y ssh
- |
for NODE in $NODES; do
echo "\033[0;32mDeploying $NODE\033[0m"
mkdir -p ~/.ssh && echo "$SSH_KEY" > ~/.ssh/id_ed25519 && chmod 600 ~/.ssh/id_ed25519
echo "\033[1;33m.. scanning SSH keys\033[0m"
ssh-keyscan $NODE > ~/.ssh/known_hosts
echo "\033[1;33m.. copying the binary\033[0m"
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"
ssh root@$NODE systemctl restart node-api
done
trigger:
branch:
- main
event:
- push
- custom
depends_on:
- testing
---
kind: pipeline
type: docker
name: Production deploy (Debian 10)
steps:
- name: build
image: golang:1.17-buster # this one is used in production
#image: golang:1.17-bullseye # this one is used in dev
commands:
- go mod tidy
- make build
- name: deploy
image: debian:buster
environment:
PROXY: saturn.rosti.cz
NODES: node-18.rosti.cz node-19.rosti.cz
SSH_KEY:
from_secret: SSH_KEY
HOST_KEYS: |
node-18.rosti.cz ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDp0KZ82dxmBJMJXuqHMiukRqVGHxyfN/nyjqPPemEz1AG2kA80od7Z9TPXYpM6Drnz0Dfcipuys7w8tbcWQGz7W+Tv1x6NWWI2r4WVfVlRkP52zdNUM/ASH88xNVmKK5FfjNyYM0khGnBcdV+ZcH/Mb7ZLLraol7B/uLahFYA5y1v+hH5ZftT8YnpOmVsx0m7PhE1zB6f5VFscSIJ5LQjhHaXkOd5zxxYJtxG6BjzqKdx5AJ2pPa6astzX4EAstpk6KzImCZ12mEEtg7bT3rLuGXg+j1DWFcHpDs0JJxF3GKGooHqbB5s26mTigqTjnytJsIzMgtfslmsLCsJGGO3B
node-18.rosti.cz ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBM4ukB6uTrCzVPjsANlkD6WYoE5bNbzr62ja/nYmEKe+zvgYAb67aXLAt+pals5Hvx5cuZstQkwuTkThBcyltsg=
node-18.rosti.cz ssh-ed25519 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wvBD64rHIfKiRp/YPNc=
saturn.rosti.cz ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBLEY5PSiOR3pklXRm0sAKc2NP2I0LZggdiRTTqrNXwUarhd7n6tdXQNf/ALh+NJ0KhcgI87Igl/jLo8YoWfeqWM=
commands:
- apt update && apt install -y ssh rsync
- |
for NODE in $NODES; do
echo "\033[0;32mDeploying $NODE\033[0m"
mkdir -p ~/.ssh && echo "$SSH_KEY" > ~/.ssh/id_ed25519 && chmod 600 ~/.ssh/id_ed25519
echo "\033[1;33m.. setting up SSH host keys\033[0m"
echo "$HOST_KEYS" > ~/.ssh/known_hosts
echo "\033[1;33m.. copying the binary\033[0m"
rsync -ave "ssh -J root@$PROXY" node-api root@$NODE:/usr/local/bin/node-api_
echo "\033[1;33m.. replacing the binary\033[0m"
ssh -J root@$PROXY root@$NODE mv /usr/local/bin/node-api_ /usr/local/bin/node-api
echo "\033[1;33m.. restarting service\033[0m"
ssh -J root@$PROXY root@$NODE systemctl restart node-api
done
depends_on:
- testing
trigger:
event:
- promote
target:
- production
---
kind: pipeline
type: docker
name: Production deploy (Debian 11)
steps:
- name: build
image: golang:1.18-bullseye # this one is used in production
#image: golang:1.17-bullseye # this one is used in dev
commands:
- go mod tidy
- make build
- name: deploy
image: debian:bullseye
environment:
PROXY: saturn.rosti.cz
NODES: node-20.rosti.cz
SSH_KEY:
from_secret: SSH_KEY
HOST_KEYS: |
node-18.rosti.cz ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDp0KZ82dxmBJMJXuqHMiukRqVGHxyfN/nyjqPPemEz1AG2kA80od7Z9TPXYpM6Drnz0Dfcipuys7w8tbcWQGz7W+Tv1x6NWWI2r4WVfVlRkP52zdNUM/ASH88xNVmKK5FfjNyYM0khGnBcdV+ZcH/Mb7ZLLraol7B/uLahFYA5y1v+hH5ZftT8YnpOmVsx0m7PhE1zB6f5VFscSIJ5LQjhHaXkOd5zxxYJtxG6BjzqKdx5AJ2pPa6astzX4EAstpk6KzImCZ12mEEtg7bT3rLuGXg+j1DWFcHpDs0JJxF3GKGooHqbB5s26mTigqTjnytJsIzMgtfslmsLCsJGGO3B
node-18.rosti.cz ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBM4ukB6uTrCzVPjsANlkD6WYoE5bNbzr62ja/nYmEKe+zvgYAb67aXLAt+pals5Hvx5cuZstQkwuTkThBcyltsg=
node-18.rosti.cz ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBAdTePM+EllZc+ZQsxuhdfiw9cRX5lAx2c9drWARSWL
node-19.rosti.cz ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC6ASSidNCyGTyxlWhpm0wH/jW8a25GwAdgH29bC3pLniewTvFcKNFcW3gLjEzIb1v2um98d/OkjeUC2wBJfcoLIkfb7x3pSqQhGVYeD+vbzOMNHIEiyicnqc8bqBN/21kCaZ37KRpz2UEVgPcbawzR3v8toBUL9uSoPbnMrc6p05hTTd2zTiHPnZrmY21vQDqDYCM8YOd0KT60cSW+62B+B8t5nHOOfTZVAEvL5LK56vlFuiYDEumorSN++xpSV6IoZOKqO4WbwLh1OQn/0q85bMzkzTbBbLO7jZl1SepqbBdIg6VtsiWIWtbGf8XgBNgbNEHARoskznvL6whBiwW5
node-19.rosti.cz ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBLvXp6VGcBToKNE8T1/T6ghO3MRA+lWrwCPdXRLKb1QbGKUMI/1XXdouVWNhzDdjlOeQzrAyYG9BjYdu0HS3Z9E=
node-19.rosti.cz ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIC8Ti8HnOClESyv+ORPKKC23ScvyxvsPR+hInrnh8ab3
node-20.rosti.cz ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDaCUbo/dSs1j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713XIQXWuK27zlrU6VTFSrr1nvDGn10ZaJULQ2XVhNfoysJSDU3nDyxM02qwDQp2cZ0J5fkgvvlvACHDnGgX1e+lHPhyZFhOmTiz7e4fXTuzkzUgjdih4NNDJdm1Em/25L9flnunzHtjvKNqtIL0nFxtJzN0TFRuO1BrykIMYBYBlofJYwc4ssgm8+eSxzjF8W/0rhsoq8JmFWVAvUYrMLCAejHvhG76/BNFEbGPfjt7SdwRVcr1BcgWlDDlNogPESIM1/9SzGi/IYEPKwIemrLRNw2X8QLJ5y2cr7PHTYSVp2NRlyrwvBD64rHIfKiRp/YPNc=
saturn.rosti.cz ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBLEY5PSiOR3pklXRm0sAKc2NP2I0LZggdiRTTqrNXwUarhd7n6tdXQNf/ALh+NJ0KhcgI87Igl/jLo8YoWfeqWM=
commands:
- apt update && apt install -y ssh rsync
- |
for NODE in $NODES; do
echo "\033[0;32mDeploying $NODE\033[0m"
mkdir -p ~/.ssh && echo "$SSH_KEY" > ~/.ssh/id_ed25519 && chmod 600 ~/.ssh/id_ed25519
echo "\033[1;33m.. setting up SSH host keys\033[0m"
echo "$HOST_KEYS" > ~/.ssh/known_hosts
echo "\033[1;33m.. copying the binary\033[0m"
rsync -ave "ssh -J root@$PROXY" node-api root@$NODE:/usr/local/bin/node-api_
echo "\033[1;33m.. replacing the binary\033[0m"
ssh -J root@$PROXY root@$NODE mv /usr/local/bin/node-api_ /usr/local/bin/node-api
echo "\033[1;33m.. restarting service\033[0m"
ssh -J root@$PROXY root@$NODE systemctl restart node-api
done
depends_on:
- testing
trigger:
event:
- promote
target:
- production
---
kind: pipeline
type: docker
name: Production deploy (Debian 12)
steps:
- name: build
image: golang:1.20-bookworm # this one is used in production
commands:
- go mod tidy
- make build
- name: deploy
image: debian:bookworm
environment:
PROXY: saturn.rosti.cz
NODES: node-22.rosti.cz node-23.rosti.cz node-24.rosti.cz
S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p5kVKXMALqi93HuWfnkk/5/p+Zew1Xlndarq3g8PudLzzmEOINPYKPsIhMTwKQSec=
node-23.rosti.cz ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBEP/VYaCRHFHNDDS870AUBTeI9rigLUB8wqoVCYtx6++bSztWqx8aHNjokVSXBwhBrWKK+UXiBMCxd/1hMnGgRw=
node-23.rosti.cz ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBRFZyIvMy1hJs7IL13VwNHoxKk35I7Y0enJ2TBAj/r2
node-24.rosti.cz ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQClN27YKYii8+Tp2Q4VO8mruA/ixeCZBZulxIZH+tT+G2MuvQrupS8gK/ieZWKUzqt70Fjwof787S7IIkokNHGdZi8ix/lhJYVS1k/bZ1kYrImUsphY7kSXEyI8M8OOANo0HnZ/yK047scEuH5yR/fPjrZffq/HzckCl6BUy8ggumb74dNMUaZw3QC3hc7YQbFdZP2dYtaDrSQrN70mfxl1pufTHHuhipxd4yO5qXh8eowwy7BpzGGFDox7u/EAXX0Owow5fo/EPcmhZnnPiY/juR5uyq6jHuxAkD9FLA7Ot55OyrtWHsH4ee8Ks+Jiu9wVZqpMDROcB/PJ1jOD/ust/Nd1A33FM4uOlePc1WUDpUvrwm+JC9OlD30YwxMbRmIfp57wSuU4bk+AFfrQZ/cwkEZmI/jYgiJwdcflNe7oFSOEn45fX/QNRK784+GHgdg+rY+Ce2YYKUCNpi9BITUnQGG61hhSrLJ8VVCEtJSaHb9r2VC/YNAxAsnd6fuW5Vk=
node-24.rosti.cz ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBGZRGv88qAG0AGRf0d77ChSU2DbDN84LZMCOWPss3RUlRvO72DJSp2706pEpbznDFSoawZ00dY0nH0p09U5ddZY=
node-24.rosti.cz ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKFw8qvLWdwOan2PHVNl8a+az2mbrzRhtFReUu84Uy3o
commands:
- apt update && apt install -y ssh rsync
- |
for NODE in $NODES; do
echo "\033[0;32mDeploying $NODE\033[0m"
mkdir -p ~/.ssh && echo "$SSH_KEY" > ~/.ssh/id_ed25519 && chmod 600 ~/.ssh/id_ed25519
echo "\033[1;33m.. setting up SSH host keys\033[0m"
echo "$HOST_KEYS" > ~/.ssh/known_hosts
echo "\033[1;33m.. copying the binary\033[0m"
rsync -ave "ssh -J root@$PROXY" node-api root@$NODE:/usr/local/bin/node-api_
echo "\033[1;33m.. replacing the binary\033[0m"
ssh -J root@$PROXY root@$NODE mv /usr/local/bin/node-api_ /usr/local/bin/node-api
echo "\033[1;33m.. restarting service\033[0m"
ssh -J root@$PROXY root@$NODE systemctl restart node-api
done
depends_on:
- testing
trigger:
event:
- promote
target:
- production

View File

@ -38,7 +38,7 @@ jobs:
deploy-dev:
runs-on: [amd64, moon]
env:
NODES: 192.168.1.236 192.168.1.220
NODES: "192.168.1.33"
steps:
- uses: actions/checkout@v4
- name: deploy

View File

@ -111,6 +111,7 @@ type App struct {
Tech string `json:"tech"`
TechVersion string `json:"tech_version"`
Password string `json:"password"`
ArchiveURL string `json:"archive_url"` // Archive with content of /srv
} `json:"setup,omitempty" gorm:"-"`
}

View File

@ -3,7 +3,7 @@ package main
import (
"strings"
"github.com/labstack/echo"
"github.com/labstack/echo/v4"
)
var skipPaths []string = []string{"/metrics"}

View File

@ -23,6 +23,8 @@ type Config struct {
SnapshotsS3SSL bool `envconfig:"SNAPSHOTS_S3_SSL" required:"false" default:"true"`
SnapshotsS3Bucket string `envconfig:"SNAPSHOTS_S3_BUCKET" required:"false" default:"snapshots"`
SnapshotsIndexLabel string `envconfig:"SNAPSHOTS_INDEX_LABEL" required:"false" default:"owner_id"` // Label that will be part of the object name and it will be used as index to quick listing
SentryDSN string `envconfig:"SENTRY_DSN" required:"false"`
SentryENV string `envconfig:"SENTRY_ENV" default:"development"`
}
// GetConfig return configuration created based on environment variables

View File

@ -202,13 +202,13 @@ func (d *Driver) Remove(name string) error {
return err
}
timeout := time.Duration(dockerTimeout * time.Second)
err = cli.ContainerStop(context.TODO(), containerID, &timeout)
timeout := dockerTimeout
err = cli.ContainerStop(context.TODO(), containerID, container.StopOptions{Timeout: &timeout})
if err != nil {
return err
}
err = cli.ContainerRemove(context.TODO(), containerID, types.ContainerRemoveOptions{})
err = cli.ContainerRemove(context.TODO(), containerID, container.RemoveOptions{})
return err
}
@ -246,8 +246,8 @@ func (d *Driver) Stop(name string) error {
return err
}
timeout := time.Duration(dockerTimeout * time.Second)
err = cli.ContainerStop(context.TODO(), containerID, &timeout)
timeout := dockerTimeout
err = cli.ContainerStop(context.TODO(), containerID, container.StopOptions{Timeout: &timeout})
return err
}

View File

@ -57,7 +57,7 @@ func (c *Container) getDriver() *Driver {
}
// volumeHostPath each container has one volume mounted into it,
func (c *Container) volumeHostPath() string {
func (c *Container) VolumeHostPath() string {
return path.Join(c.AppsPath, c.App.Name)
}
@ -132,7 +132,7 @@ func (c *Container) Status() (ContainerStatus, error) {
// DiskUsage returns number of bytes and inodes used by the container in it's mounted volume
func (c *Container) DiskUsage() (int, int, error) {
return du(c.volumeHostPath())
return du(c.VolumeHostPath())
}
// ResourceUsage returns amount of memory in B and CPU in % that the app occupies
@ -153,7 +153,7 @@ func (c *Container) Create() error {
_, err := driver.Create(
c.App.Name,
c.App.Image,
c.volumeHostPath(),
c.VolumeHostPath(),
c.App.HTTPPort,
c.App.SSHPort,
c.App.CPU,
@ -430,7 +430,7 @@ func (c *Container) SetTechnology(tech string, version string) error {
output, err = driver.Exec(c.App.Name, []string{"su", "app", "-c", "rosti " + tech + " " + version}, "", []string{}, false)
}
log.Printf("DEBUG: enable tech for %s output: %s", c.App.Name, string(*output))
log.Printf("DEBUG: enable tech %s/%s for %s output: %s", tech, version, c.App.Name, string(*output))
return err
}
@ -586,7 +586,7 @@ func (c *Container) GetTechs() (apps.AppTechs, error) {
// Returns info about active technology
func (c *Container) GetActiveTech() (*TechInfo, error) {
info, err := getTechAndVersion(path.Join(c.volumeHostPath(), "bin", "primary_tech"))
info, err := getTechAndVersion(path.Join(c.VolumeHostPath(), "bin", "primary_tech"))
if err != nil {
return info, err
}

View File

@ -3,7 +3,12 @@ package glue
import (
"errors"
"fmt"
"io"
"log"
"net/http"
"os"
"os/exec"
"path"
"strings"
"time"
@ -200,6 +205,66 @@ func (p *Processor) Get(noUpdate bool) (apps.App, error) {
return app, nil
}
// Takes URL with an tar archive and prepares container's volume from it.
func (p *Processor) volumeFromURL(url string, container *docker.Container) error {
// Validation, check if url ends with tar.zst
if !strings.HasSuffix(url, ".tar.zst") {
return fmt.Errorf("archive has to end with .tar.zst")
}
volumePath := container.VolumeHostPath()
// Prepare volume path
err := os.MkdirAll(volumePath, 0755)
if err != nil {
return fmt.Errorf("failed to create volume path: %v", err)
}
// Download the archive
archivePath := path.Join(volumePath, "archive.tar.zst")
log.Printf("%s: downloading archive from %s\n", container.App.Name, url)
f, err := os.Create(archivePath)
if err != nil {
return fmt.Errorf("failed to create archive file: %v", err)
}
defer f.Close()
resp, err := http.Get(url)
if err != nil {
return fmt.Errorf("failed to download archive: %v", err)
}
defer resp.Body.Close()
n, err := io.Copy(f, resp.Body)
if err != nil {
return fmt.Errorf("failed to download archive: %v", err)
}
log.Printf("downloaded %d bytes\n", n)
// Extract the archive
log.Printf("%s: extracting archive\n", container.App.Name)
// Call tar xf archive.tar.zst -C /volume
cmd := exec.Command("tar", "-xf", archivePath, "-C", volumePath)
err = cmd.Run()
if err != nil {
log.Printf("%s: failed to extract archive: %v", container.App.Name, err)
return err
}
// Remove archive
log.Printf("%s: removing archive\n", container.App.Name)
err = os.Remove(volumePath + "/archive.tar.zst")
if err != nil {
return fmt.Errorf("failed to remove archive: %v", err)
}
log.Printf("%s: volume preparing done\n", container.App.Name)
return nil
}
// Create creates a single app in the system
func (p *Processor) Create(appTemplate apps.App) error {
if appTemplate.EnvRaw == nil {
@ -219,6 +284,17 @@ func (p *Processor) Create(appTemplate apps.App) error {
AppsPath: p.AppsPath,
}
if len(appTemplate.Snapshot) > 0 && len(appTemplate.Setup.ArchiveURL) > 0 {
return fmt.Errorf("snapshot and archive_url cannot be used together")
}
if len(appTemplate.Setup.ArchiveURL) > 0 {
err = p.volumeFromURL(appTemplate.Setup.ArchiveURL, &container)
if err != nil {
return fmt.Errorf("failed to prepare volume: %v", err)
}
}
err = container.Create()
if err != nil {
return err
@ -346,6 +422,25 @@ func (p *Processor) Update(appTemplate apps.App) error {
return err
}
// Setup technology if it's noted in the request
if len(appTemplate.Setup.Tech) > 0 {
err := p.waitForApp()
if err != nil {
return err
}
err = p.EnableTech(appTemplate.Setup.Tech, appTemplate.Setup.TechVersion)
if err != nil {
return fmt.Errorf("failed to enable tech: %v", err)
}
// We restart the container so everything can use the new tech
err = container.Restart()
if err != nil {
return err
}
}
return nil
}
@ -355,6 +450,7 @@ func (p *Processor) Delete() error {
container, err := p.getContainer()
if err != nil {
log.Println("ERROR: delete app:", err.Error())
return err
}
status, err := container.Status()
@ -558,6 +654,42 @@ func (p *Processor) GetHostKey() (string, error) {
return hostKey, nil
}
// Save meta data about app into a file
func (p *Processor) SaveMetadata(metadata string) error {
container, err := p.getContainer()
if err != nil {
return err
}
volumePath := container.VolumeHostPath()
f, err := os.Create(path.Join(volumePath, ".metadata.json"))
if err != nil {
return err
}
defer f.Close()
_, err = f.Write([]byte(metadata))
if err != nil {
return err
}
// Set permissions
err = os.Chmod(path.Join(volumePath, ".metadata.json"), 0600)
if err != nil {
return err
}
// Set owner
err = os.Chown(path.Join(volumePath, ".metadata.json"), ownerUID, ownerGID)
if err != nil {
return err
}
return nil
}
// Processes returns list of supervisord processes
func (p *Processor) Processes() ([]docker.Process, error) {
container, err := p.getContainer()

View File

@ -3,6 +3,7 @@ package glue
import (
"log"
"github.com/getsentry/sentry-go"
"github.com/jinzhu/gorm"
"github.com/rosti-cz/node-api/apps"
docker "github.com/rosti-cz/node-api/containers"
@ -102,6 +103,7 @@ func (s *StatsProcessor) GatherStats() error {
for _, app := range appList {
err := s.UpdateUsage(app.Name)
if err != nil {
sentry.CaptureException(err)
log.Println("STATS ERROR:", err.Error())
}
}
@ -120,6 +122,7 @@ func (s *StatsProcessor) GatherStates() error {
for _, app := range appList {
err := s.UpdateState(app.Name)
if err != nil {
sentry.CaptureException(err)
log.Println("STATE ERROR:", err.Error())
}
}

View File

@ -2,6 +2,9 @@ package glue
import "github.com/rosti-cz/node-api/apps"
const ownerUID = 1000
const ownerGID = 1000
// Path where authorized keys are
const sshPubKeysLocation = "/srv/.ssh/authorized_keys"

36
go.mod
View File

@ -3,37 +3,31 @@ module github.com/rosti-cz/node-api
go 1.14
require (
github.com/Microsoft/go-winio v0.4.18 // indirect
github.com/StackExchange/wmi v0.0.0-20210224194228-fe8f1750fd46 // indirect
github.com/containerd/containerd v1.5.9 // indirect
github.com/docker/docker v20.10.12+incompatible
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/distribution/reference v0.5.0 // indirect
github.com/docker/docker v25.0.3+incompatible
github.com/docker/go-connections v0.4.0
github.com/go-ole/go-ole v1.2.5 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/getsentry/sentry-go v0.26.0
github.com/gobuffalo/packr v1.30.1
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/jinzhu/gorm v1.9.14
github.com/kelseyhightower/envconfig v1.4.0
github.com/kr/pretty v0.3.0 // indirect
github.com/labstack/echo v3.3.10+incompatible
github.com/labstack/gommon v0.3.0 // indirect
github.com/mattn/go-sqlite3 v1.14.17 // indirect
github.com/labstack/echo/v4 v4.10.0
github.com/minio/minio-go/v7 v7.0.14
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6 // indirect
github.com/moby/term v0.5.0 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/nats-io/nats-server/v2 v2.6.1 // indirect
github.com/nats-io/nats.go v1.12.3
github.com/nats-io/nats.go v1.23.0
github.com/opencontainers/image-spec v1.0.2
github.com/pkg/errors v0.9.1
github.com/satori/go.uuid v1.2.0
github.com/shirou/gopsutil v2.20.6+incompatible
github.com/stretchr/testify v1.8.1
golang.org/x/crypto v0.6.0 // indirect
google.golang.org/grpc v1.44.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
github.com/stretchr/testify v1.8.4
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.24.0 // indirect
gorm.io/driver/mysql v1.4.7
gorm.io/gorm v1.25.2-0.20230530020048-26663ab9bf55
gotest.tools/v3 v3.1.0 // indirect
gotest.tools/v3 v3.5.1 // indirect
)

2781
go.sum

File diff suppressed because it is too large Load Diff

View File

@ -2,13 +2,14 @@ package main
import (
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"os"
"strings"
"github.com/labstack/echo"
"github.com/labstack/echo/v4"
"github.com/rosti-cz/node-api/apps"
"github.com/rosti-cz/node-api/common"
"github.com/rosti-cz/node-api/glue"
@ -362,6 +363,33 @@ func getOrphansHander(c echo.Context) error {
return c.JSON(http.StatusOK, []string{})
}
// Save metadata for the app
func saveMetadataHandler(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,
}
body, err := io.ReadAll(c.Request().Body)
if err != nil {
return fmt.Errorf("error reading request body: %v", err)
}
err = processor.SaveMetadata(string(body))
if err != nil {
return fmt.Errorf("error while save metadata: %v", err.Error())
}
return nil
}
// Return info about the node including performance index
func getNodeInfoHandler(c echo.Context) error {
processor := glue.Processor{

View File

@ -18,6 +18,7 @@ import (
"regexp"
"strings"
"github.com/getsentry/sentry-go"
"github.com/nats-io/nats.go"
"github.com/pkg/errors"
"github.com/rosti-cz/node-api/apps"
@ -34,6 +35,7 @@ func _messageHandler(m *nats.Msg) error {
message := RequestMessage{}
err := json.Unmarshal(m.Data, &message)
if err != nil {
sentry.CaptureException(err)
log.Println(errors.Wrap(err, "invalid JSON data in the incoming message"))
return err
}
@ -61,6 +63,7 @@ func _messageHandler(m *nats.Msg) error {
"add_label": addLabelEventHandler,
"remove_label": removeLabelEventHandler,
"list_orphans": listOrphansEventHandler,
"save_metadata": saveMetadataEventHandler,
"node": getNodeEventHandler,
"create_snapshot": createSnapshotEventHandler,
"restore_from_snapshot": restoreFromSnapshotEventHandler,
@ -74,7 +77,12 @@ func _messageHandler(m *nats.Msg) error {
}
if eventHandler, ok := eventHandlerMap[message.Type]; ok {
return eventHandler(m, &message)
err = eventHandler(m, &message)
if err != nil {
sentry.CaptureException(err)
}
return err
} else {
log.Println("ERROR: event handler not defined for " + message.Type)
}
@ -712,6 +720,26 @@ func listOrphansEventHandler(m *nats.Msg, message *RequestMessage) error {
return nil
}
// Save metadata for the app
func saveMetadataEventHandler(m *nats.Msg, message *RequestMessage) error {
processor := glue.Processor{
AppName: message.AppName,
DB: common.GetDBConnection(),
SnapshotProcessor: &snapshotProcessor,
DockerSock: config.DockerSocket,
BindIPHTTP: config.AppsBindIPHTTP,
BindIPSSH: config.AppsBindIPSSH,
AppsPath: config.AppsPath,
}
err := processor.SaveMetadata(message.Payload)
if err != nil {
return fmt.Errorf("error while save metadata: %v", err.Error())
}
return nil
}
/*
getNodeEventHandler returns info about the node including performance index
*/

20
main.go
View File

@ -5,7 +5,9 @@ import (
"log"
"time"
"github.com/labstack/echo"
"github.com/getsentry/sentry-go"
sentryecho "github.com/getsentry/sentry-go/echo"
"github.com/labstack/echo/v4"
"github.com/nats-io/nats.go"
"github.com/rosti-cz/node-api/apps"
"github.com/rosti-cz/node-api/apps/drivers"
@ -30,9 +32,18 @@ func _init() {
// Load config from environment variables
config = *common.GetConfig()
// Sentry
sentry.Init(sentry.ClientOptions{
Dsn: config.SentryDSN,
AttachStacktrace: true,
Environment: config.SentryENV,
TracesSampleRate: 0.1,
})
// Connect to the NATS service
nc, err = nats.Connect(config.NATSURL)
if err != nil {
sentry.CaptureException(err)
log.Fatalln(err)
}
@ -69,6 +80,7 @@ func _init() {
func main() {
_init()
defer nc.Drain()
defer sentry.Flush(time.Second * 10)
// Close database at the end
db := common.GetDBConnection()
@ -92,6 +104,7 @@ func main() {
start := time.Now()
err := statsProcessor.GatherStats()
if err != nil {
sentry.CaptureException(err)
log.Println("LOOP ERROR:", err.Error())
}
elapsed := time.Since(start)
@ -106,6 +119,7 @@ func main() {
for {
err := nodeProcessor.Log()
if err != nil {
sentry.CaptureException(err)
log.Println("NODE PERFORMANCE LOG ERROR:", err.Error())
}
time.Sleep(5 * time.Minute)
@ -117,6 +131,7 @@ func main() {
e.Renderer = t
e.Use(TokenMiddleware)
e.Use(sentryecho.New(sentryecho.Options{}))
// NATS handling
// admin.apps.ALIAS.events
@ -168,6 +183,9 @@ func main() {
// Rebuilds existing app, it keeps the data but creates the container again
e.PUT("/v1/apps/:name/rebuild", rebuildAppHandler)
// Save metadata about app
e.POST("/v1/apps/:name/metadata", saveMetadataHandler)
// Adds new label
e.POST("/v1/apps/:name/labels", addLabelHandler)

View File

@ -5,7 +5,7 @@ import (
"io"
"github.com/gobuffalo/packr"
"github.com/labstack/echo"
"github.com/labstack/echo/v4"
)
// Template struct