From 3d4aa5e358df8872c5f6fcbcc34c95d5a1a309c0 Mon Sep 17 00:00:00 2001 From: Eslam-Nawara Date: Sat, 17 Dec 2022 16:35:48 +0200 Subject: [PATCH] add files structure --- README.md | 42 +++++++++++++++++++++++++- cmd/foreman/main.go | 1 + foreman.go | 1 + foreman_test.go | 2 ++ internal/depgraph/depgraph.go | 1 + internal/procparser/procfile_parser.go | 1 + test-procfiles/Procfile | 19 ++++++++++++ test-procfiles/Procfile-bad-test | 1 + test-procfiles/Procfile-cyclic-test | 15 +++++++++ test-procfiles/Procfile-test | 13 ++++++++ 10 files changed, 95 insertions(+), 1 deletion(-) mode change 100644 => 100755 README.md create mode 100755 cmd/foreman/main.go create mode 100755 foreman.go create mode 100755 foreman_test.go create mode 100755 internal/depgraph/depgraph.go create mode 100755 internal/procparser/procfile_parser.go create mode 100755 test-procfiles/Procfile create mode 100755 test-procfiles/Procfile-bad-test create mode 100755 test-procfiles/Procfile-cyclic-test create mode 100755 test-procfiles/Procfile-test diff --git a/README.md b/README.md old mode 100644 new mode 100755 index 4848919..088b6e0 --- a/README.md +++ b/README.md @@ -1 +1,41 @@ -# foreman \ No newline at end of file +# Foreman +It is a [foreman](https://github.com/ddollar/foreman) implementation in GO. + +## Description +Foreman is a manager for [Procfile-based](https://en.wikipedia.org/wiki/Procfs) applications. Its aim is to abstract away the details of the Procfile format, and allow you to run your services directly. + +## Features +- Run procfile-backed apps. +- Able to run with dependency resolution. + +## Procfile +Procfile is simply `key: value` format like: +```yaml +app1: + cmd: ping -c 1 google.com + run_once: false + checks: + cmd: ps aux | grep google + deps: + - redis +app2: + cmd: ping -c 5 yahoo.com + checks: + cmd: ps aux | grep yahoo + +redis: + cmd: redis-server --port 6010 + checks: + cmd: redis-cli -p 6010 ping + tcp_ports: [6010] +``` +**Here** we defined three services `app1`, `app2` and `redis` with check commands and dependency matrix + +## How to use +**First:** modify the procfile with processes or services you want to run. + +**second**: Simply run with command: +```sh +$ ./foreman +``` + diff --git a/cmd/foreman/main.go b/cmd/foreman/main.go new file mode 100755 index 0000000..06ab7d0 --- /dev/null +++ b/cmd/foreman/main.go @@ -0,0 +1 @@ +package main diff --git a/foreman.go b/foreman.go new file mode 100755 index 0000000..54a67dd --- /dev/null +++ b/foreman.go @@ -0,0 +1 @@ +package foreman diff --git a/foreman_test.go b/foreman_test.go new file mode 100755 index 0000000..26cbdf3 --- /dev/null +++ b/foreman_test.go @@ -0,0 +1,2 @@ +package foreman + diff --git a/internal/depgraph/depgraph.go b/internal/depgraph/depgraph.go new file mode 100755 index 0000000..1383e7f --- /dev/null +++ b/internal/depgraph/depgraph.go @@ -0,0 +1 @@ +package depgraph diff --git a/internal/procparser/procfile_parser.go b/internal/procparser/procfile_parser.go new file mode 100755 index 0000000..a46c2b1 --- /dev/null +++ b/internal/procparser/procfile_parser.go @@ -0,0 +1 @@ +package procparser diff --git a/test-procfiles/Procfile b/test-procfiles/Procfile new file mode 100755 index 0000000..e2534d7 --- /dev/null +++ b/test-procfiles/Procfile @@ -0,0 +1,19 @@ +service_ping: + cmd: ping -c 2 google.com | grep google + checks: + cmd: ls + deps: + - service_redis + +service_sleep: + cmd: sleep 5 + checks: + cmd: ls + deps: + - service_ping + +service_redis: + cmd: redis-server --port 6010 + run_once: true + checks: + cmd: redis-cli -p 6010 ping diff --git a/test-procfiles/Procfile-bad-test b/test-procfiles/Procfile-bad-test new file mode 100755 index 0000000..228d6f5 --- /dev/null +++ b/test-procfiles/Procfile-bad-test @@ -0,0 +1 @@ +this is invalid Procfile syntax, Procfile must be yaml file. diff --git a/test-procfiles/Procfile-cyclic-test b/test-procfiles/Procfile-cyclic-test new file mode 100755 index 0000000..fe7c5e5 --- /dev/null +++ b/test-procfiles/Procfile-cyclic-test @@ -0,0 +1,15 @@ +sleeper: + run_once: true + cmd: sleep infinity + checks: + cmd: ls + tcp_ports: [4759, 1865] + udp_ports: [4500, 3957] + deps: + - hello + +hello: + run_once: true + cmd: echo "hello" + deps: + - sleeper diff --git a/test-procfiles/Procfile-test b/test-procfiles/Procfile-test new file mode 100755 index 0000000..c109ead --- /dev/null +++ b/test-procfiles/Procfile-test @@ -0,0 +1,13 @@ +sleeper: + run_once: true + cmd: sleep infinity + checks: + cmd: ls + tcp_ports: [4759, 1865] + udp_ports: [4500, 3957] + deps: + - hello + +hello: + run_once: true + cmd: echo "hello"