Skip to content

Commit

Permalink
Merge 2 or more configuration files
Browse files Browse the repository at this point in the history
  • Loading branch information
F1bonacc1 committed Jan 22, 2023
1 parent a151556 commit e064219
Show file tree
Hide file tree
Showing 29 changed files with 1,674 additions and 740 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ testrace:
go test -race ./src/...

coverhtml:
go test -coverprofile=coverage.out ./src
go test -coverprofile=coverage.out ./src/...
go tool cover -html=coverage.out

run:
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ require (
github.com/fatih/color v1.13.0
github.com/gdamore/tcell/v2 v2.5.3
github.com/gin-gonic/gin v1.8.1
github.com/imdario/mergo v0.3.13
github.com/joho/godotenv v1.4.0
github.com/pkg/errors v0.9.1
github.com/rivo/tview v0.0.0-20221128165837-db36428c92d9
github.com/spf13/cobra v1.6.1
github.com/swaggo/swag v1.8.8
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk=
github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg=
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
Expand Down Expand Up @@ -142,6 +144,7 @@ github.com/pelletier/go-toml/v2 v2.0.1/go.mod h1:r9LEWfGN8R5k0VXJ+0BkIe7MYkRdwZO
github.com/pelletier/go-toml/v2 v2.0.6 h1:nrzqCb7j9cDFj2coyLNLaZuJTLjWjlaz6nvTvIwycIU=
github.com/pelletier/go-toml/v2 v2.0.6/go.mod h1:eumQOmlWiOPt5WriQQqoM5y18pDHwha2N+QD+EUNTek=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down Expand Up @@ -282,5 +285,6 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
132 changes: 132 additions & 0 deletions process-compose.override.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
version: "0.5"
log_level: debug
log_length: 3000
environment:
- 'ABC=222'
log_location: ./pc.log
shell:
shell_command: "zsh"
shell_argument: "-c"

processes:
process0:
command: "ls -lFa --color=always"
working_dir: "/"

process1:
command: "./test_loop.bash ${PROC4}"
availability:
restart: "on_failure"
backoff_seconds: 2
depends_on:
_process2:
condition: process_completed_successfully
process3:
condition: process_completed
# process4:
# condition: process_completed_successfully
environment:
- 'EXIT_CODE=0'
shutdown:
command: "sleep 2 && pkill -f process1"
signal: 15
timeout_seconds: 4

_process2:
command: "./test_loop.bash process2"
log_location: ./pc.proc2.log
availability:
restart: "on_failure"
# depends_on:
# process3:
# condition: process_completed_successfully
environment:
- 'ABC=2221'
- 'PRINT_ERR=111'
- 'EXIT_CODE=2'
shutdown:
command: "sleep 2 && pkill -f 'test_loop.bash process2'"
signal: 15
timeout_seconds: 4
readiness_probe:
http_get:
host: "google.com"
scheme: "https"
initial_delay_seconds: 5
period_seconds: 5
timeout_seconds: 2
success_threshold: 1
failure_threshold: 3

process3:
command: "./test_loop.bash process3"
availability:
restart: "always"
backoff_seconds: 2
depends_on:
nginx:
condition: process_healthy

process4:
command: "./test_loop.bash process4-override"
disable_ansi_colors: true
# availability:
# restart: on_failure
environment:
- 'ABC=2221'
- 'EXIT_CODE=4'
readiness_probe:
exec:
command: "ps -ef | grep -v grep | grep process4"
initial_delay_seconds: 5
period_seconds: 2
timeout_seconds: 1
success_threshold: 1
failure_threshold: 3

nginx:
command: "docker run -d --rm -p80:80 --name nginx_test nginx"
# availability:
# restart: on_failure
is_daemon: true
shutdown:
command: "docker stop nginx_test"
signal: 15
timeout_seconds: 5
liveness_probe:
exec:
command: "[ $(docker inspect -f '{{.State.Running}}' nginx_test) = 'true' ]"
initial_delay_seconds: 5
period_seconds: 2
timeout_seconds: 5
success_threshold: 1
failure_threshold: 3
readiness_probe:
http_get:
host: 127.0.0.1
path: "/"
port: 80
initial_delay_seconds: 5
period_seconds: 10
timeout_seconds: 5
success_threshold: 1
failure_threshold: 3
availability:
restart: "always"
backoff_seconds: 2

pc_log:
command: "tail -f -n100 process-compose-${USER}.log"
working_dir: "/tmp"
environment:
- 'REDACTED=1'
- 'ADDED=2'
depends_on:
process0:
condition: process_completed


bat_config:
command: "batcat -f process-compose.yaml"


75 changes: 38 additions & 37 deletions process-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
version: "0.5"
log_level: debug
log_level: info
log_length: 3000
environment:
- 'ABC=222'
log_location: ./pc.log
shell:
shell_command: "zsh"
shell_argument: "-c"

processes:
process0:
command: "ls -lFa --color=always"
Expand Down Expand Up @@ -77,36 +84,36 @@ processes:
success_threshold: 1
failure_threshold: 3

nginx:
command: "docker run -d --rm -p80:80 --name nginx_test nginx"
# availability:
# restart: on_failure
is_daemon: true
shutdown:
command: "docker stop nginx_test"
signal: 15
timeout_seconds: 5
liveness_probe:
exec:
command: "[ $(docker inspect -f '{{.State.Running}}' nginx_test) = 'true' ]"
initial_delay_seconds: 5
period_seconds: 2
timeout_seconds: 5
success_threshold: 1
failure_threshold: 3
readiness_probe:
http_get:
host: 127.0.0.1
path: "/"
port: 80
initial_delay_seconds: 5
period_seconds: 10
timeout_seconds: 5
success_threshold: 1
failure_threshold: 3
availability:
restart: "always"
backoff_seconds: 2
# nginx:
# command: "docker run -d --rm -p80:80 --name nginx_test nginx"
# # availability:
# # restart: on_failure
# is_daemon: true
# shutdown:
# command: "docker stop nginx_test"
# signal: 15
# timeout_seconds: 5
# liveness_probe:
# exec:
# command: "[ $(docker inspect -f '{{.State.Running}}' nginx_test) = 'true' ]"
# initial_delay_seconds: 5
# period_seconds: 2
# timeout_seconds: 5
# success_threshold: 1
# failure_threshold: 3
# readiness_probe:
# http_get:
# host: 127.0.0.1
# path: "/"
# port: 80
# initial_delay_seconds: 5
# period_seconds: 10
# timeout_seconds: 5
# success_threshold: 1
# failure_threshold: 3
# availability:
# restart: "always"
# backoff_seconds: 2

kcalc:
command: "kcalc"
Expand All @@ -125,9 +132,3 @@ processes:
bat_config:
command: "batcat -f process-compose.yaml"

environment:
- 'ABC=222'
log_location: ./pc.log
shell:
shell_command: "zsh"
shell_argument: "-c"
5 changes: 3 additions & 2 deletions src/api/pc_api.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package api

import (
"github.com/f1bonacc1/process-compose/src/types"
"net/http"
"strconv"

Expand All @@ -17,9 +18,9 @@ import (
// @Success 200 {object} object "Processes Status"
// @Router /processes [get]
func GetProcesses(c *gin.Context) {
procs := app.PROJ.GetLexicographicProcessNames()
procs := app.PROJ.GetProject().GetLexicographicProcessNames()

states := []*app.ProcessState{}
states := []*types.ProcessState{}
for _, name := range procs {
states = append(states, app.PROJ.GetProcessState(name))
}
Expand Down
6 changes: 4 additions & 2 deletions src/app/daemon.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package app

import "github.com/f1bonacc1/process-compose/src/types"

func (p *Process) waitForDaemonCompletion() {
if !p.isDaemonLaunched() {
return
Expand All @@ -9,7 +11,7 @@ loop:
for {
status := <-p.procStateChan
switch status {
case ProcessStateCompleted:
case types.ProcessStateCompleted:
break loop
}
}
Expand All @@ -18,7 +20,7 @@ loop:

func (p *Process) notifyDaemonStopped() {
if p.isDaemonLaunched() {
p.procStateChan <- ProcessStateCompleted
p.procStateChan <- types.ProcessStateCompleted
}
}

Expand Down
Loading

0 comments on commit e064219

Please sign in to comment.