[release] v0.15.0-unstable26

This commit is contained in:
Yann Stepienik
2024-03-29 17:35:18 +00:00
parent 48bd1c565c
commit 70c8bd9ca5
4 changed files with 80 additions and 3 deletions
+1
View File
@@ -23,6 +23,7 @@
- Added optionals vars to DNS challenge setup (like timeout)
- Added a check on hostname to prevent protocols
- Added hint to TCP proxying
- Fix issue with favicon retrieval post-migration to host mode
## Version 0.14.6
- Fix custom back-up folder logic
+1 -1
View File
@@ -128,7 +128,7 @@ export const CronManager = () => {
field: (r) => {
return <div style={{maxWidth: '400px'}} >{{
'running': <Alert icon={<LoadingOutlined />} severity={'info'} color={'info'}>Running since {r.LastStarted}</Alert>,
'success': <Alert severity={'success'} color={'success'}>Last run finished on {r.LastRun}</Alert>,
'success': <Alert severity={'success'} color={'success'}>Last run finished on {r.LastRun}, duration {(new Date(r.LastRun).getTime() - new Date(r.LastStarted).getTime()) / 1000}s</Alert>,
'error': <Alert severity={'error'} color={'error'}>Last run exited with an error on {r.LastRun}</Alert>,
'never': <Alert severity={'info'} color={'info'}>Never ran</Alert>
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "cosmos-server",
"version": "0.15.0-unstable25",
"version": "0.15.0-unstable26",
"description": "",
"main": "test-server.js",
"bugs": {
+77 -1
View File
@@ -8,10 +8,14 @@ import (
"io"
"bufio"
"os/exec"
"fmt"
"github.com/go-co-op/gocron/v2"
"github.com/azukaar/cosmos-server/src/docker"
"github.com/azukaar/cosmos-server/src/utils"
"github.com/docker/docker/api/types"
)
var scheduler gocron.Scheduler
@@ -32,6 +36,7 @@ type ConfigJob struct {
Logs []string
Ctx context.Context `json:"-"`
CancelFunc context.CancelFunc `json:"-"`
Container string
}
var jobsList = map[string]map[string]ConfigJob{}
@@ -108,6 +113,75 @@ func JobFromCommand(command string, args ...string) func(OnLog func(string), OnF
}
}
func JobFromContainerCommand(containerID string, command string, args ...string) func(OnLog func(string), OnFail func(error), OnSuccess func(), ctx context.Context, cancel context.CancelFunc) {
return func(OnLog func(string), OnFail func(error), OnSuccess func(), ctx context.Context, cancel context.CancelFunc) {
// Connect to Docker
err := docker.Connect()
if err != nil {
OnFail(err)
return
}
// Check if the container is running
containerJSON, err := docker.DockerClient.ContainerInspect(ctx, containerID)
if err != nil {
OnFail(err)
return
}
if !containerJSON.State.Running {
OnFail(fmt.Errorf("Container %s is not running", containerID))
return
}
// Create exec configuration
execConfig := types.ExecConfig{
Cmd: append([]string{command}, args...),
AttachStdout: true,
AttachStderr: true,
}
// Create exec instance
execID, err := docker.DockerClient.ContainerExecCreate(ctx, containerID, execConfig)
if err != nil {
OnFail(err)
return
}
// Attach to exec instance
execAttach, err := docker.DockerClient.ContainerExecAttach(ctx, execID.ID, types.ExecStartCheck{})
if err != nil {
OnFail(err)
return
}
defer execAttach.Close()
// Stream logs from exec
go streamLogs(execAttach.Reader, OnLog)
// Inspect exec process to wait for completion
for {
execInspect, err := docker.DockerClient.ContainerExecInspect(ctx, execID.ID)
if err != nil {
OnFail(err)
return
}
if !execInspect.Running {
if execInspect.ExitCode == 0 {
OnSuccess()
} else {
OnFail(fmt.Errorf("exec process exited with code %d", execInspect.ExitCode))
}
break
}
// Don't spam the API
time.Sleep(500 * time.Millisecond)
}
}
}
func InitJobs() {
CRONLock <- true
defer func() { <-CRONLock }()
@@ -122,8 +196,9 @@ func InitJobs() {
for _, job := range configJobsList {
cmd := JobFromCommand("sh", "-c", job.Command)
if job.Container != "" {
cmd = JobFromCommand("docker", "exec", job.Container, "sh", "-c", job.Command)
cmd = JobFromContainerCommand(job.Container, "sh", "-c", job.Command)
}
if job.Enabled {
@@ -143,6 +218,7 @@ func InitJobs() {
LastStarted: time.Time{},
Logs: []string{},
Disabled: !job.Enabled,
Container: job.Container,
}
if CustomScheduler, ok := jobsList["Custom"]; ok {