fix for deployement
This commit is contained in:
@@ -5,7 +5,6 @@ const bodyParser = require("body-parser");
|
||||
const glob = require("glob");
|
||||
const path = require("path");
|
||||
const Mustache = require("mustache");
|
||||
const hosts = require("hosts");
|
||||
const cors = require("cors");
|
||||
const express = require("express");
|
||||
const process = require("process");
|
||||
@@ -34,29 +33,13 @@ apxtri.main = async () => {
|
||||
} else {
|
||||
await apxtri.setup();
|
||||
}
|
||||
//const conf = require(path.resolve(`../itm/adminapi.json`));
|
||||
//const conf = fs.readJsonSync(`../adminapi/objects/tribes/idx/tribes_dns.json`);
|
||||
//let doms = conf.dns; // only dns of town during the init process
|
||||
//let tribelist;
|
||||
/*if (!fs.existsSync(`../adminapi/objects/tribes/idx/tribes_dns.json`)) {
|
||||
console.log("ERROR,Missing ../adminapi/objects/tribes/idx/tribes_dns.json");
|
||||
process.exit(0);
|
||||
}
|
||||
*/
|
||||
/* const tribesdns = fs.readJsonSync(`../adminapi/objects/tribes/idx/tribes_dns.json`);
|
||||
let doms=[]
|
||||
for (const tribe in tribedns){
|
||||
tribedns[tribe].forEach(d=>{
|
||||
if (!doms.includes(d)) doms.push(d);
|
||||
})
|
||||
}
|
||||
*/
|
||||
//apxtri.runexpress(fs.readJsonSync(`../adminapi/objects/tribes/idx/tribes_dns.json`));
|
||||
};
|
||||
|
||||
apxtri.setup = async () => {
|
||||
console.log("Warning, this is a first install");
|
||||
const initadminapi = fs.readJsonSync("../adminapi/apxtri/initadminapi.json");
|
||||
const initadminapi = fs.readJsonSync(
|
||||
"../adminapi/apxtri/setup/initadminapi.json"
|
||||
);
|
||||
try {
|
||||
initadminapi.townpath = __dirname.replace("/adminapi/apxtri", "");
|
||||
const townnation = initadminapi.townpath.split("/").slice(-1)[0].split("-");
|
||||
@@ -112,7 +95,11 @@ apxtri.setup = async () => {
|
||||
}
|
||||
}
|
||||
}*/
|
||||
if (!fs.existsSync("../adminapi/objects/nations")) {
|
||||
//check nation exist and town does not exist
|
||||
if (
|
||||
!fs.existsSync("../adminapi/objects/nations/idx/lst_nations.json") ||
|
||||
!fs.existsSync("../adminapi/objects/towns/idx/lst_towns.json")
|
||||
) {
|
||||
console.log(
|
||||
`Sorry, check setup.sh process that was not able to init your adminapi/objects `
|
||||
);
|
||||
@@ -147,27 +134,30 @@ apxtri.setup = async () => {
|
||||
fs.outputJSONSync("../adminapi/objects/tribes/idx/tribes.json", idxadminapi, {
|
||||
space: 2,
|
||||
});
|
||||
// check nginx conf and eventually adapt
|
||||
let etcnginx = fs.readFileSync("/etc/nginx/nginx.conf")
|
||||
const etcnginxlines=etcnginx.slipt("\n");
|
||||
if (etcnginx.slipt("\n")[0] !== `user ${initadminapi.sudoUser};`){
|
||||
// check nginx conf and eventually change if not starting by user "current user";
|
||||
let etcnginx = fs.readFileSync("/etc/nginx/nginx.conf", "utf8");
|
||||
if (etcnginx.split("\n")[0] !== `user ${initadminapi.sudoUser};`) {
|
||||
const nginxmain = fs.readFileSync("../adminapi/apxtri/setup/nginx.maincf");
|
||||
fs.outputFileSync("/etc/nginx/nginx.conf",Mustache.render(nginxmain,initadminapi),{adAdmin:true})
|
||||
|
||||
console.log("Modify /etc/nginx/nginx.conf");
|
||||
fs.outputFileSync(
|
||||
"/etc/nginx/nginx.conf",
|
||||
Mustache.render(nginxmain, initadminapi),
|
||||
{ adAdmin: true }
|
||||
);
|
||||
}
|
||||
|
||||
const nginxapx = fs.readFileSync("./nginx/nginx.wwwscf");
|
||||
fs.outputSync(
|
||||
`/etc/nginx/nginx.conf`,
|
||||
Mustache.render(nginxmain, initadminapi, "utf-8")
|
||||
// add conf for http://adminapx.adminapi
|
||||
const nginxapx = fs.readFileSync(
|
||||
"../adminapi/apxtri/setup/nginx.wwwscf",
|
||||
"utf8"
|
||||
);
|
||||
fs.outputSync(
|
||||
`../nginx/adminapi-apx.conf`,
|
||||
Mustache.render(nginxapx, initadminapi, "utf-8")
|
||||
initadminapi.website="adminapx";
|
||||
fs.outputFileSync(
|
||||
`../adminapi/nginx/adminapx.adminapi.conf`,
|
||||
Mustache.render(nginxapx, initadminapi)
|
||||
);
|
||||
if (!hosts.exists("127.0.0.1", "apx.adminapi")) {
|
||||
hosts.add("127.0.0.1", "apx.adminapi");
|
||||
}
|
||||
// add hosts entry for local access
|
||||
// this command is ran by the setup.sh
|
||||
// sudo sed -i '/127.0.0.1 adminapx.adminapi/c\127.0.0.1 adminapx.adminapi' /etc/hosts
|
||||
const { exec } = require("child_process");
|
||||
exec(initadminapi.nginx.restart, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
@@ -179,6 +169,10 @@ apxtri.setup = async () => {
|
||||
);
|
||||
}
|
||||
});
|
||||
apxtri.runexpress(
|
||||
fs.readJsonSync(`../adminapi/objects/tribes/idx/tribes_dns.json`),
|
||||
fs.readJSONSync("../adminapi/objects/tribes/itm/adminapi.json")
|
||||
);
|
||||
};
|
||||
|
||||
apxtri.runexpress = async (tribesdns, conf) => {
|
||||
@@ -240,12 +234,12 @@ apxtri.runexpress = async (tribesdns, conf) => {
|
||||
const log = conf.api.activelog
|
||||
? conf.api.activelog.includes(currentmod)
|
||||
: false;
|
||||
|
||||
console.log(
|
||||
currentmod,
|
||||
" Allowed DOMs to access to this apxtri server:",
|
||||
JSON.stringify(doms)
|
||||
);
|
||||
|
||||
console.log(
|
||||
currentmod,
|
||||
" Allowed DOMs to access to this apxtri server:",
|
||||
JSON.stringify(doms)
|
||||
);
|
||||
console.log(currentmod, " app.locals.tribeids", app.locals.tribeids);
|
||||
|
||||
// Cors management
|
||||
|
@@ -3,7 +3,7 @@
|
||||
"urlinit":["http://apx.adminapi","https://testwall-ants.ndda.fr"],
|
||||
"idxname":{"towns":"towns","nation":"nations","pagans":"alias"},
|
||||
"dns": [
|
||||
"apx.adminapi"
|
||||
"adminapx.adminapi"
|
||||
],
|
||||
"status": "unchain",
|
||||
"nationId": "ants",
|
||||
|
@@ -1,4 +1,4 @@
|
||||
user {{sudoUser}};
|
||||
user {{{sudoUser}}};
|
||||
worker_processes auto;
|
||||
error_log /var/log/nginx/error.log notice;
|
||||
pid /var/run/nginx.pid;
|
||||
@@ -38,5 +38,5 @@ http {
|
||||
# Virtual Host Configs
|
||||
##
|
||||
include /etc/nginx/conf.d/*.conf;
|
||||
include {{townpath}}/*/*/nginx/*.conf;
|
||||
include {{{townpath}}}/*/*/nginx/*.conf;
|
||||
}
|
||||
|
@@ -1,19 +1,19 @@
|
||||
erver {
|
||||
server_name {{website}}.{{tribe}};
|
||||
server {
|
||||
server_name {{{website}}}.{{{tribeId}}};
|
||||
add_header 'Access-Control-Allow-Origin' '*' always;
|
||||
add_header 'Access-Control-Allow-Credentials' 'true' always;
|
||||
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
|
||||
add_header 'Access-Control-Allow-Headers' '*' always;
|
||||
# usefull to debug nginx conf 3 next line:
|
||||
access_log {{townpath}}/{{tribe}}/logs/nginx/{{tribe}}_{{website}}.access.log main;
|
||||
error_log {{townpath}}/{{tribe}}/logs/nginx/{{tribe}}_{{website}}.error.log debug;
|
||||
access_log {{{townpath}}}/{{{tribeId}}}/logs/nginx/{{{tribeId}}}_{{{website}}}.access.log main;
|
||||
error_log {{{townpath}}}/{{{tribeId}}}/logs/nginx/{{{tribeId}}}_{{{website}}}.error.log debug;
|
||||
add_header xdebug "testmsg debug: $uri - $request - liste args: $args - url:$arg_url - alias:$arg_alias " always;
|
||||
|
||||
set $trackme 0;
|
||||
if ( $uri ~ ^/trk/ ){
|
||||
set $trackme 1;
|
||||
}
|
||||
access_log {{townpath}}/{{tribe}}/logs/nginx/{{tribe}}_{{website}}.trk.log tracker if=$trackme ;
|
||||
access_log {{{townpath}}}/{{{tribeId}}}/logs/nginx/{{{tribeId}}}_{{{website}}}.trk.log tracker if=$trackme ;
|
||||
location ~* /trk/ {
|
||||
if ( $uri ~ ^/trk/redirect ){
|
||||
return 301 $arg_url;
|
||||
@@ -21,43 +21,31 @@ location ~* /trk/ {
|
||||
rewrite ^/trk/(.*)$ /$1;
|
||||
}
|
||||
location /adminapi/Checkjson.js {
|
||||
alias {{townpath}}/adminapi/apxtri/models/Checkjson.js;
|
||||
alias {{{townpath}}}/adminapi/apxtri/models/Checkjson.js;
|
||||
}
|
||||
location ~* /adminapi/objects/tplstrings/ {
|
||||
rewrite /adminapi/objects/tplstrings/(.*$) /$1 break;
|
||||
root {{townpath}}/adminapi/objects/tplstrings/;
|
||||
location /setup.sh {
|
||||
alias {{{townpath}}}/adminapi/apxtri/setup/setup.sh;
|
||||
}
|
||||
location ~* /adminapi/schema/ {
|
||||
rewrite /adminapi/schema/(.*$) /$1 break;
|
||||
root {{townpath}}/adminapi/schema/;
|
||||
}
|
||||
location ~* /{{tribe}}/objects/tplstrings/ {
|
||||
rewrite /{{tribe}}/objects/tplstrings/(.*$) /$1 break;
|
||||
root {{townpath}}/{{tribe}}/objects/tplstrings/;
|
||||
}
|
||||
location ~* /{{tribe}}/schema/ {
|
||||
rewrite /{{tribe}}/schema/(.*$) /$1 break;
|
||||
root {{townpath}}/{{tribe}}/schema/;
|
||||
location ~ ^/.*/setup.*\.tar\.gz$ {
|
||||
rewrite /(.*$)/(.*$) /$1/backups/$1 break;
|
||||
root /home/phil/apxtowns/testwall-ants/;
|
||||
}
|
||||
location ~* /objectimg/.*/img/ {
|
||||
rewrite /objectimg/(.*) /$1 break;
|
||||
root {{townpath}}/{{tribe}}/objects/;
|
||||
root {{{townpath}}}/{{{tribeId}}}/objects/;
|
||||
}
|
||||
|
||||
location /cdn/ {
|
||||
expires 1y;
|
||||
add_header Cache-Control "public";
|
||||
rewrite /cdn/(.*$) /$1 break;
|
||||
root {{townpath}}/{{tribe}}/objects/wwws/cdn/;
|
||||
root {{{townpath}}}/{{{tribeId}}}/objects/wwws/cdn/;
|
||||
}
|
||||
|
||||
location /api/ {
|
||||
rewrite /api/(.*$) /$1 break;
|
||||
proxy_pass http://localhost:3020;
|
||||
proxy_redirect off;
|
||||
include proxy_params;
|
||||
}
|
||||
|
||||
location /socket/ {
|
||||
proxy_pass http://127.0.0.1:3030;
|
||||
proxy_http_version 1.1;
|
||||
@@ -66,33 +54,24 @@ location /socket/ {
|
||||
proxy_set_header Host $host;
|
||||
proxy_cache_bypass $http_upgrade;
|
||||
}
|
||||
|
||||
location /apxwebapp/ {
|
||||
rewrite /apxwebapp/(.*$) /$1 break;
|
||||
root /media/phil/usbfarm/apxtowns/apxwebapp;
|
||||
index index.html index_fr.html index_en.html;
|
||||
}
|
||||
location /apidoc/ {
|
||||
root {{townpath}}/{{tribe}}/objects/wwws/apidoc/;
|
||||
root {{{townpath}}}/{{{tribeId}}}/objects/wwws/apidoc/;
|
||||
index index.html;
|
||||
}
|
||||
location /appbuilder/{
|
||||
root {{townpath}}/ndda/objects/wwws/;
|
||||
}
|
||||
location /src/ {
|
||||
rewrite /src/(.*$) /$1 break;
|
||||
root {{townpath}}/{{tribe}}/objects/wwws/{{website}}/src/;
|
||||
index index.html index_fr.html;
|
||||
rewrite /src/(.*$) /$1 break;
|
||||
root {{{townpath}}}/{{{tribeId}}}/objects/wwws/{{{website}}}/src/;
|
||||
index index.html index_fr.html index_en.html;
|
||||
}
|
||||
location / {
|
||||
root {{townpath}}/{{tribe}}/objects/wwws/{{website}}/dist/;
|
||||
index index.html index_fr.html;
|
||||
root {{{townpath}}}/{{{tribeId}}}/objects/wwws/{{{website}}}/dist/;
|
||||
index index.html index_fr.html index_en.html;
|
||||
}
|
||||
error_page 404 /404.html;
|
||||
# redirect server error pages to the static page /50x.html
|
||||
#
|
||||
error_page 500 502 503 504 /50x.html;
|
||||
location = /50x.html {
|
||||
root /usr/local/nginx/html;
|
||||
root /usr/local/nginx/html;
|
||||
}
|
||||
}
|
63
apxtri/setup/setup.sh
Executable file
63
apxtri/setup/setup.sh
Executable file
@@ -0,0 +1,63 @@
|
||||
#!/bin/bash
|
||||
# Installation process from an existing backup to set up a new
|
||||
# See README.md for full process
|
||||
#
|
||||
# Create in apxtowns a town-nations
|
||||
# wget {any instance url}/setup.sh
|
||||
# chmode +x setup.sh
|
||||
# ./setup.sh mode tribe url
|
||||
# Example:
|
||||
# To set up a new towns with tribe adminapi from the git repo
|
||||
# To be use as a dev plateforme for apxtri
|
||||
# To sync only data in existing install check in /obejcts/rsync.sh
|
||||
# .setup.sh adminapi https://testwall-ants.ndda.fr https://gitea.ndda.fr/apxtri/adminapi
|
||||
#
|
||||
# Make a copy (so must manage versioning by running the same command to update
|
||||
# carefull it erase the data object with the one it gets)
|
||||
# To be use for production purpose
|
||||
# .setup.sh adminapi https://testwall-ants.ndda.fr
|
||||
#
|
||||
# Create a new instance of smatchit from an existing production env
|
||||
# .setup.sh smatchit https://testwall-ants.ndda.fr
|
||||
#
|
||||
# Create a dev en from git repo
|
||||
# .setup.sh smatchit https://testwall-ants.ndda.fr https://gitea.ndda.fr/smatchit/smatchit
|
||||
|
||||
tribe=$1 # name of the tribe to install
|
||||
url=$2 # url to get the data from
|
||||
gitrepo=$3 # url to get apxtri code from a git repo (empty if must come from a backup or the url)
|
||||
|
||||
# get
|
||||
wget "${url}/${tribe}/setup.objects.tar.gz"
|
||||
if [[ $? -eq 0 ]]; then
|
||||
echo "Check the url:$url seemas not answer"
|
||||
urlko=1
|
||||
fi
|
||||
if [[ "$urlok" -eq 1 || -z "$tribe" ]]; then
|
||||
echo "Command must be setup.sh adminapi https://testwall-ants.ndda.fr https://gitea.ndda.fr/apxtri/adminapi"
|
||||
else
|
||||
if [ -z "$gitrepo" ]; then
|
||||
wget "${url}/${tribe}/setup.apxtri.tar.gz"
|
||||
tar -xzvf setup.apxtri.tar.gz -C . -p && rm setup.apxtri.tar.gz
|
||||
wget "${url}/${tribe}/setup.schema.tar.gz"
|
||||
tar -xzvf setup.schema.tar.gz -C . -p && rm setup.schema.tar.gz
|
||||
wget "${url}/${tribe}/setup.nginx.tar.gz"
|
||||
tar -xzvf setup.nginx.tar.gz -C . -p && rm setup.nginx.tar.gz
|
||||
echo "please change your dns accordingly with ${tribe}/nginx/ conf file"
|
||||
else
|
||||
git clone "$gitrepo"
|
||||
fi
|
||||
tar -xzvf setup.objects.tar.gz -C . -p && rm setup.objects.tar.gz
|
||||
mkdir -p "${tribe}/objects/persons"
|
||||
mkdir -p "${tribe}/objects/persons/itm"
|
||||
mkdir -p "${tribe}/objects/persons/idx"
|
||||
mkdir -p "${tribe}/tmp"
|
||||
mkdir -p "${tribe}/logs"
|
||||
mkdir -p "${tribe}/logs/nginx"
|
||||
mkdir -p "${tribe}/backups"
|
||||
sudo sed -i '/127.0.0.1 adminapx.adminapi/c\127.0.0.1 adminapx.adminapi\n' /etc/hosts
|
||||
cd "$tribe"
|
||||
yarn install
|
||||
cd ../adminapi
|
||||
yarn dev
|
||||
fi
|
Reference in New Issue
Block a user