Katsu Script Manager
A simple automation tool that allows scripts to be configured and executed based on HTTP events.
Motivation
We wanted to make our daily deployment process into development environments smoother and without manual intervention. We do love shell-scripting (and have tons of scripts), but managing these by hand based on various events still require too much manual intervention, therefore we needed a tool that could capture these events (generally coming from the CI system), react to them based on the pre defined configuration, and perform the job.
Our mantra is: Focus on the solution, not in the tooling.
Origin of the name
The name was inspired by the team's favorite meal: The famous chicken katsu by ***** (venue's name ommited since they are not paying anything to us neither giving us free meals!).
Configure the workspace
Install dependencies
Navigate to the root folder and install the dependencies via the command
$ npm install
Add a .env file
At the root level of your project add a .env
file:
$ touch .env
By default the application listens http on port 3000
you can modify this port via the .env
file:
PORT=3000
You can setup any port number you wish.
You can define a SCRIPT_FOLDER
variable in the .env
file as well, otherwise it will search for scripts under config/scripts/
.
Add the following envs to connect to the database
POSTGRES_DATABASE =database
POSTGRES_USERNAME =username
POSTGRES_PASSWORD =password
POSTGRES_HOST =host
Setting up execution for Scripts
Configuring jobs
Navigate to the folder config/jobs and edit the file jobs.config.json
. e.g.
[
{
"name": "DEPLOY_UI_DEV01",
"jobName": "WEBUI",
"branch": "FEAT-DEV-INTEGRATION",
"scriptName": "deploy.bash",
"args": ["--env", "dev01"]
}
]
where :
-
name: is an id for the job, this will be used as a name to the logs files
-
jobName: the name of the job
-
branch: the name of the branch to execute from
-
scriptName: the name of the script to execute
-
args: the args to be passed to the script
Script logs
Script logs can be found in the folder scripts-logs/{CURRENT-DATE}
Endpoints
Run script in folder
POST /run-script/{SCRIPTNAME}
Any scripts found under the SCRIPT_FOLDER
path can be invoked via http post. For example a script named args.bash
can be executed with the parameters 1 2 3 4
using the following POST
:
POST http://localhost:3000/run-script/args.bash
With Body:
[1,2,3,4]
Curl:
curl -XPOST -H "Accept: application/json" -H "Content-Type: application/json" -d "[\"1\", \"2\", \"3\", \"4\"]" http://localhost:3000/run-script/args.bash
Executing jobs
POST /exec-job
POST http://localhost:3000/exec-job
With Body:
{
"jobName": "WEBUI",
"branch" : "FEAT-DEV-INTEGRATION"
}
Curl:
curl -XPOST -H "Accept: application/json" -H "Content-Type: application/json" -d "{
\"jobName\": \"WEBUI\",
\"branch\": \"FEAT-DEV-INTEGRATION\"
}" http://localhost:3000/exec-job
Adding a new job
POST /add-job
POST http://localhost:3000/add-job
With Body:
{
"name": "DEPLOY_UI_DEV01",
"jobName": "WEBUI",
"branch": "FEAT-DEV-INTEGRATION",
"scriptName": "deploy.bash",
"args": ["--env", "dev01"]
}
Deleting a job
DELETE /job/{NAME}
DELETE http://localhost:3000/job/DEPLOY_UI_DEV01
get all jobs
GET /jobs
GET http://localhost:3000/jobs
Running it
To run the application, on the root execute the command
$ npm start
Launch a web browser at http://localhost:3000