feat: init
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
var fs = require("fs");
|
||||
var child_process = require("child_process");
|
||||
|
||||
const plugin_repository = process.argv[2];
|
||||
const plugin_name = process.argv[3];
|
||||
var plugin_id = "";
|
||||
var plugin_secret = "";
|
||||
if (process.argv[4] && process.argv[5]) {
|
||||
plugin_id = process.argv[4];
|
||||
plugin_secret = process.argv[5];
|
||||
}
|
||||
var venv = "";
|
||||
if (process.argv[6]) venv = process.argv[6];
|
||||
|
||||
var port = 8001;
|
||||
|
||||
fs.readFile("/usr/src/app/plugins.json", function (err, data) {
|
||||
if (err) throw err;
|
||||
|
||||
var json = JSON.parse(data).plugins;
|
||||
var existing = false;
|
||||
|
||||
json.forEach((plugin) => {
|
||||
if (plugin.port >= port) {
|
||||
port = plugin.port + 1;
|
||||
}
|
||||
if (plugin.name === plugin_name) {
|
||||
console.log(`${plugin_name.toUpperCase()} is already saved`);
|
||||
existing = true;
|
||||
|
||||
return existing;
|
||||
}
|
||||
});
|
||||
|
||||
if (existing) return;
|
||||
|
||||
let obj = {
|
||||
name: plugin_name,
|
||||
repository: plugin_repository,
|
||||
port: port,
|
||||
id: plugin_id,
|
||||
secret: plugin_secret,
|
||||
venv: venv,
|
||||
};
|
||||
|
||||
json.push(obj);
|
||||
|
||||
child_process.exec(
|
||||
`git clone ${plugin_repository} /usr/src/app/plugins/${plugin_name}`,
|
||||
(err) => {
|
||||
if (err) throw err;
|
||||
fs.writeFile(
|
||||
"/usr/src/app/plugins.json",
|
||||
JSON.stringify({ plugins: json }),
|
||||
(err) => {
|
||||
if (err) throw err;
|
||||
console.log(
|
||||
`${plugin_name.toUpperCase()} is now cloned and saved \nWaiting for ${plugin_name.toUpperCase()} build`
|
||||
);
|
||||
}
|
||||
);
|
||||
child_process.exec(`build ${plugin_name} && up ${plugin_name}`, (err) => {
|
||||
if (err) throw err;
|
||||
console.log(
|
||||
`${plugin_name.toUpperCase()} built and running on port ${port}`
|
||||
);
|
||||
child_process.exec(`start_nginx`, () => {
|
||||
console.log(
|
||||
`${plugin_name.toUpperCase()} Reachable from host on http://localhost:8080/plugins/${plugin_name}`
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,22 @@
|
||||
var fs = require("fs");
|
||||
var child_process = require("child_process");
|
||||
|
||||
const plugin_name = process.argv[2];
|
||||
|
||||
fs.readFile("/usr/src/app/plugins.json", function (err, data) {
|
||||
if (err) throw err;
|
||||
|
||||
var json = JSON.parse(data).plugins;
|
||||
|
||||
json.forEach((plugin) => {
|
||||
if (plugin.name === plugin_name) {
|
||||
existing = true;
|
||||
child_process.exec(
|
||||
`cd /usr/src/app/plugins/${plugin_name} && docker build -t ${plugin_name} . && cd ../..`,
|
||||
(err) => {
|
||||
if (err) throw err;
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,37 @@
|
||||
var fs = require("fs");
|
||||
var child_process = require("child_process");
|
||||
|
||||
const plugin_name = process.argv[2];
|
||||
|
||||
fs.readFile("/usr/src/app/plugins.json", function (err, data) {
|
||||
if (err) throw err;
|
||||
|
||||
var json = JSON.parse(data).plugins;
|
||||
var existing = false;
|
||||
|
||||
json.forEach((plugin) => {
|
||||
if (plugin.name === plugin_name) {
|
||||
existing = true;
|
||||
child_process.exec(
|
||||
`cd /usr/src/app/plugins/ && rm -fr ${plugin_name} && docker stop ${plugin_name} && docker system prune -f -a --volumes `,
|
||||
(err) => {
|
||||
const new_json = json.filter((plugin) => plugin.name !== plugin_name);
|
||||
fs.writeFile(
|
||||
"/usr/src/app/plugins.json",
|
||||
JSON.stringify({ plugins: new_json }),
|
||||
(err) => {
|
||||
if (err) throw err;
|
||||
child_process.exec(`start_nginx`, () => {
|
||||
console.log(`nginx restarted`);
|
||||
});
|
||||
console.log(`${plugin_name.toUpperCase()} deleted`);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
if (!existing) {
|
||||
console.log(`${plugin_name.toUpperCase()} is not yet installed`);
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,18 @@
|
||||
var fs = require("fs");
|
||||
fs.readFile("/usr/src/app/plugins.json", function (err, data) {
|
||||
if (err) throw err;
|
||||
|
||||
var json = JSON.parse(data).plugins;
|
||||
var counter = 1;
|
||||
|
||||
if (json.length === 0) {
|
||||
console.log("No plugins saved");
|
||||
}
|
||||
|
||||
json.forEach((plugin) => {
|
||||
console.log(
|
||||
`${counter} - ${plugin.name} from ${plugin.repository} on local port ${plugin.port}`
|
||||
);
|
||||
counter++;
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,20 @@
|
||||
var fs = require("fs");
|
||||
var child_process = require("child_process");
|
||||
|
||||
fs.readFile("/usr/src/app/plugins.json", async function (err, data) {
|
||||
if (err) throw err;
|
||||
|
||||
var json = JSON.parse(data).plugins;
|
||||
|
||||
json.forEach((plugin) => {
|
||||
console.log(`Preparing plugin ${plugin.name}`);
|
||||
child_process.exec(
|
||||
`cd /usr/src/app/plugins/${plugin.name} && build ${plugin.name} && up ${plugin.name} && cd ../..`,
|
||||
(err) => {
|
||||
if (err) throw err;
|
||||
console.log(`Plugin ${plugin.name} running on port ${plugin.port}`);
|
||||
child_process.exec(`cd /usr/src/app && start_nginx`, () => {});
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,70 @@
|
||||
var fs = require("fs");
|
||||
var child_process = require("child_process");
|
||||
|
||||
fs.readFile("/usr/src/app/plugins.json", function (err, data) {
|
||||
if (err) throw err;
|
||||
|
||||
var json = JSON.parse(data).plugins;
|
||||
|
||||
const conf = generate_config(json);
|
||||
|
||||
fs.writeFile("/usr/src/app/nginx/nginx.conf", conf, (err) => {
|
||||
if (err) throw err;
|
||||
console.log("Plugins reverse proxy ready for building");
|
||||
});
|
||||
|
||||
child_process.exec(
|
||||
`docker stop nginx_host && docker system prune -f -a --volumes`,
|
||||
(err) => {
|
||||
console.log(`Clean nginx container and rebuild`);
|
||||
child_process.exec(
|
||||
`cd nginx && docker build -t nginx_host . && docker run --name nginx_host --network=test-net --restart unless-stopped -dp 8080:80 nginx_host && cd ..`,
|
||||
(err) => {
|
||||
if (err) throw err;
|
||||
console.log(
|
||||
`Plugins container reverse proxy built and running on port 8080`
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
const generate_config = (json) => {
|
||||
var conf = `
|
||||
events {}
|
||||
http {
|
||||
server {
|
||||
|
||||
listen 80 default_server;
|
||||
listen [::]:80 default_server;
|
||||
|
||||
sendfile on;
|
||||
tcp_nopush on;
|
||||
tcp_nodelay on;
|
||||
keepalive_timeout 65;
|
||||
types_hash_max_size 2048;
|
||||
|
||||
location / {
|
||||
# First attempt to serve request as file, then
|
||||
# as directory, then fall back to displaying a 404.
|
||||
try_files $uri $uri/ =408;
|
||||
}
|
||||
|
||||
location /api {
|
||||
#proxy_set_header X-Forwarded-Host $host
|
||||
proxy_pass http://172.21.0.1:3000;
|
||||
}
|
||||
|
||||
`;
|
||||
|
||||
json.forEach((plugin) => {
|
||||
conf += `
|
||||
location /plugins/${plugin.name} {
|
||||
proxy_pass http://172.64.0.1:${plugin.port};
|
||||
}
|
||||
`;
|
||||
});
|
||||
conf += `}}`;
|
||||
return conf;
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
var fs = require("fs");
|
||||
var child_process = require("child_process");
|
||||
|
||||
const plugin_name = process.argv[2];
|
||||
|
||||
fs.readFile("/usr/src/app/plugins.json", function (err, data) {
|
||||
if (err) throw err;
|
||||
|
||||
var json = JSON.parse(data).plugins;
|
||||
|
||||
json.forEach((plugin) => {
|
||||
if (plugin.name === plugin_name) {
|
||||
existing = true;
|
||||
child_process.exec(
|
||||
`cd /usr/src/app/plugins/${plugin_name} && docker run --name ${plugin_name} --network=dind-net --restart unless-stopped -dp ${plugin.port}:${plugin.port} -e SERVER_PORT=${plugin.port} -e SERVER_PREFIX='/plugins/${plugin_name}' -e CREDENTIALS_ENDPOINT='http://172.64.0.1:8080' -e CREDENTIALS_SECRET=${plugin.secret} -e CREDENTIALS_ID=${plugin.id} -e SERVER_ORIGIN='http://localhost:8080' ${plugin.venv} ${plugin_name} && cd ../..`,
|
||||
(err) => {
|
||||
if (err) throw err;
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,31 @@
|
||||
var fs = require("fs");
|
||||
var child_process = require("child_process");
|
||||
|
||||
const plugin_name = process.argv[2];
|
||||
|
||||
fs.readFile("/usr/src/app/plugins.json", function (err, data) {
|
||||
if (err) throw err;
|
||||
|
||||
var json = JSON.parse(data).plugins;
|
||||
var existing = false;
|
||||
|
||||
json.forEach((plugin) => {
|
||||
if (plugin.name === plugin_name) {
|
||||
existing = true;
|
||||
child_process.exec(
|
||||
`delete ${plugin_name} && add https://github.com/linagora/Twake-plugins-${plugin_name} ${plugin.id} ${plugin.secret} ${plugin.venv}`,
|
||||
(err) => {
|
||||
if (err) throw err;
|
||||
|
||||
console.log(
|
||||
`${plugin_name.toUpperCase()} is now updated, built, running and reachable from host on http://localhost:8080/plugins/${plugin_name}`
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
if (!existing) {
|
||||
console.log(`${plugin_name.toUpperCase()} is not yet installed`);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user