Skip to content
This repository has been archived by the owner on Nov 7, 2020. It is now read-only.

Commit

Permalink
New services: entrypoint and validation service
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmad N. Raja committed Nov 9, 2018
1 parent b2cca51 commit cf6d157
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 40 deletions.
40 changes: 20 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@
"description": "Run penneo services without any hassle",
"main": "main.js",
"scripts": {
"config": "node scripts/tasks/config.js",
"setup": "node scripts/tasks/setup.js",
"yeah": "node scripts/tasks/yeah.js",
"no": "node scripts/tasks/down.js",
"up": "node scripts/tasks/run.js up",
"start": "node scripts/tasks/run.js start",
"stop": "node scripts/tasks/run.js stop",
"kill": "node scripts/tasks/run.js kill",
"recreate": "node scripts/tasks/run.js recreate",
"defined": "node scripts/tasks/defined.js",
"auth": "node scripts/tasks/auth.js",
"status": "node scripts/tasks/status.js",
"env": "node scripts/tasks/env.js",
"monitor": "node scripts/tasks/monitor.js",
"enable": "node scripts/tasks/toggle.js enable",
"disable": "node scripts/tasks/toggle.js disable",
"docs": "node scripts/tasks/docs.js",
"readme": "node scripts/tasks/readme.js",
"image": "node scripts/tasks/run.js image",
"exec": "node scripts/tasks/exec.js"
"config" : "node scripts/tasks/config.js",
"setup" : "node scripts/tasks/setup.js",
"yeah" : "node scripts/tasks/yeah.js",
"no" : "node scripts/tasks/down.js",
"defined" : "node scripts/tasks/defined.js",
"readme" : "node scripts/tasks/readme.js",
"auth" : "node scripts/tasks/auth.js",
"status" : "node scripts/tasks/status.js",
"env" : "node scripts/tasks/env.js",
"monitor" : "node scripts/tasks/monitor.js",
"enable" : "node scripts/tasks/toggle.js enable",
"disable" : "node scripts/tasks/toggle.js disable",
"docs" : "node scripts/tasks/docs.js",
"exec" : "node scripts/tasks/exec.js",
"up" : "node scripts/tasks/run.js up",
"start" : "node scripts/tasks/run.js start",
"stop" : "node scripts/tasks/run.js stop",
"kill" : "node scripts/tasks/run.js kill",
"recreate" : "node scripts/tasks/run.js recreate",
"image" : "node scripts/tasks/run.js image"
},
"author": "Ahmad Nazir Raja",
"license": "MIT",
Expand Down
5 changes: 4 additions & 1 deletion scripts/lib/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ var childProcess = require('child_process');
var colors = require('colors');
var shelljs = require('shelljs');

function runRaw(cmd) {
function runRaw(cmd, path) {
if (path) {
cmd = 'cd ' + path + ' && ' + cmd;
}
console.log(colors.gray(cmd));
var exec = shelljs.exec(cmd, {silent: true});
console.log(colors.gray(exec.stdout || exec.stderr));
Expand Down
17 changes: 11 additions & 6 deletions scripts/lib/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,12 @@ function exec(id, cmd, options) {
c = service.commands && service.commands.kill || definitions.COMMAND.kill;
break;
case 'stop':
// @todo: need to find a better way to determine whether the cmd is raw
// or not
// @todo: update all relevant commands and make them objects so that we
// can determine which ones are raw instead of only making the stop
// commands raw, e.g.:
//
// {raw: "command ..."}
//
if (service.commands && service.commands.stop) {
raw = true;
c = service.commands.stop;
Expand All @@ -152,9 +156,6 @@ function exec(id, cmd, options) {
case 'env':
c = service.commands && service.commands.env || definitions.COMMAND.env;
break;
case 'exec':
c = service.commands && service.commands.exec || definitions.COMMAND.exec;
break;
case 'monitor':
// @todo: move this to a separate file (lib/monitor.js)
var files = options.profile
Expand All @@ -172,8 +173,12 @@ function exec(id, cmd, options) {
var cs = (typeof c === 'object' && c.constructor === Array) ? c : [c];

cs.forEach(function(c) {
if (typeof c !== 'string') {
raw = true;
c = c.raw;
}
if (raw) {
command.runRaw(c);
command.runRaw(c, service.path);
} else {
command.run(c, service.path);
}
Expand Down
5 changes: 4 additions & 1 deletion scripts/tasks/exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ serviceIds.split(',').forEach((serviceId, index) => {
console.log('Single quotes not allowed in the command:'.red);
return;
}
c = definitions.COMMAND.exec.replace('{{COMMAND}}', c);

c = (service.commands && service.commands.exec || definitions.COMMAND.exec)
.replace('{{COMMAND}}', c);

command.run(c, service.path);
});
5 changes: 4 additions & 1 deletion scripts/tasks/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ var mkdirp = require('mkdirp');

mkdirp(config.dir);

console.log("Disabled this for now..");
process.exit(-1);

// Clone repos
var servicesData = services.getDefined();
for (var id in servicesData) {
services.displayInfo(id, true);
services.clone(config.dir, servicesData[id].name, servicesData[id].url);
services.bootstrap(servicesData[id].path);
}
}
90 changes: 79 additions & 11 deletions service-definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,25 @@ var services = {
gateway: {
name: "gateway-service",
commands: {
env: 'project-runner/login.sh prod'
env: 'project-runner/login.sh prod',
image: 'project-runner/load-image.sh prod'
},
logs: {
directories: ['app/log'],
profiles: {
default: [
'app/log/nginx_access.log',
'app/log/nginx_error.log'
]
}
},

},
entrypoint: {
name: "mock-entrypoint",
commands: {
env: 'project-runner/login.sh prod',
image: 'project-runner/load-image.sh prod'
},
logs: {
directories: ['app/log'],
Expand All @@ -28,6 +46,24 @@ var services = {
]
}
},
port: 8008,
docs: {
publicUrl: "/app_dev.php/api/docs"
}
},
validation: {
name: "validation-service",
logs: {
directories: ['app/logs', 'app/logs/server'],
profiles: {
default: [
'app/logs/server/nginx_access.log',
'app/logs/server/nginx_error.log',
'app/logs/penneo_error_dev.log',
'app/logs/penneo_core_dev.log'
]
}
},
port: 8000,
docs: {
publicUrl: "/app_dev.php/api/docs"
Expand Down Expand Up @@ -93,19 +129,51 @@ var services = {
}
},

xign: {
name: "xign",
logs: {
directories: ['app/logs', 'app/logs/server'],
profiles: {
default: [
'app/logs/server/nginx_access.log',
'app/logs/server/nginx_error.log',
'app/logs/penneo_error_prod.log',
'app/logs/penneo_core_prod.log'
]
}
},
port: 8000,
docs: {
publicUrl: "/api/docs"
},
commands: {
up : {raw: "./penneo-run.sh deployable up -d"},
start : 'project-runner/run.sh deployable start',
recreate : {raw: "./penneo-run.sh deployable up -d --force-recreate"},
stop : {raw: "./penneo-run.sh deployable stop"},
kill : {raw: "./penneo-run.sh deployable kill"},
env : "./login.sh xign_app",
bootstrap : 'echo "Not supported"',
exec : "./project-runner/run.sh deployable run --rm app sh -c '{{COMMAND}}'",
image : 'scripts/deploy/build-image.sh'
}
},

// Default settings for the services
COMMAND: {
up: 'project-runner/run.sh dev',
start: 'project-runner/run.sh dev start',
recreate: 'project-runner/run.sh dev up -d --force-recreate',
stop: 'project-runner/run.sh dev stop',
kill: 'project-runner/run.sh dev kill',
isRunning: 'docker ps | grep {service-id}',
env: 'project-runner/login.sh dev',
bootstrap: 'scripts/bootstrap.sh',
image: ['project-runner/load-image.sh -d prod', 'project-runner/load-image.sh -d dev'],
exec: "./project-runner/run.sh dev run --rm app sh -c '{{COMMAND}}'"
up : 'project-runner/run.sh dev',
start : 'project-runner/run.sh dev start',
recreate : 'project-runner/run.sh dev up -d --force-recreate',
stop : 'project-runner/run.sh dev stop',
kill : 'project-runner/run.sh dev kill',
env : 'project-runner/login.sh dev',
isRunning : 'docker ps | grep {service-id}',
bootstrap : 'scripts/bootstrap.sh',
exec : "./project-runner/run.sh dev run --rm app sh -c '{{COMMAND}}'",
image : ['project-runner/load-image.sh -d prod', 'project-runner/load-image.sh -d dev']
}
};

module.exports = services;


0 comments on commit cf6d157

Please sign in to comment.