From 6f07f7f9906c293c3953b7dafae1a286c8e3ac3e Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Sun, 8 Dec 2019 12:31:32 +0100 Subject: [PATCH 1/8] Back autoheal & health-check --- Dockerfile | 2 +- Jenkinsfile | 22 +++++++++++++--------- back/process.yml | 6 ++++++ docker-compose.yml | 4 +++- front/nginx.conf | 15 --------------- loopback/common/models/vn-model.js | 2 +- 6 files changed, 24 insertions(+), 27 deletions(-) create mode 100644 back/process.yml diff --git a/Dockerfile b/Dockerfile index 79831cf06..65c2aa0b1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -33,4 +33,4 @@ COPY \ README.md \ ./ -CMD ["pm2-docker", "./loopback/server/server.js"] +CMD ["pm2-runtime", "./back/process.yml"] diff --git a/Jenkinsfile b/Jenkinsfile index 81fb1c965..a462973ce 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -6,13 +6,15 @@ pipeline { disableConcurrentBuilds() } environment { - PROJECT_NAME = 'salix' - REGISTRY = 'registry.verdnatura.es' - DOCKER_HOST_1 = 'vch1.verdnatura.es' - DOCKER_HOST_2 = 'vch2.verdnatura.es' - PORT_MASTER = '5002' - PORT_TEST = '5001' - TAG = "${env.BRANCH_NAME}" + PROJECT_NAME = 'salix' + REGISTRY = 'registry.verdnatura.es' + DOCKER_HOST_1 = 'vch1.verdnatura.es' + DOCKER_HOST_2 = 'vch2.verdnatura.es' + PORT_MASTER_FRONT = '5002' + PORT_MASTER_BACK = '3001-3005' + PORT_TEST_FRONT = '5001' + PORT_TEST_BACK = '4001-4005' + TAG = "${env.BRANCH_NAME}" } stages { stage('Checkout') { @@ -31,10 +33,12 @@ pipeline { switch (env.BRANCH_NAME) { case 'master': - env.PORT = PORT_MASTER + env.PORT_FRONT = PORT_MASTER_FRONT + env.PORT_BACK = PORT_MASTER_BACK break case 'test': - env.PORT = PORT_TEST + env.PORT_FRONT = PORT_TEST_FRONT + env.PORT_BACK = PORT_TEST_BACK break } switch (env.BRANCH_NAME) { diff --git a/back/process.yml b/back/process.yml new file mode 100644 index 000000000..3e9f3ef19 --- /dev/null +++ b/back/process.yml @@ -0,0 +1,6 @@ +apps: + - script: ./loopback/server/server.js + name: salix-back + cron_restart: 0 */2 * * * + instances: 1 + max_restarts: 10 diff --git a/docker-compose.yml b/docker-compose.yml index 7fcf95a79..cd08ac0e1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,13 +7,15 @@ services: context: . dockerfile: front/Dockerfile ports: - - ${PORT}:80 + - ${PORT_FRONT}:80 links: - back back: image: registry.verdnatura.es/salix-back:${TAG} restart: unless-stopped build: . + ports: + - ${PORT_BACK}:3000 environment: - NODE_ENV volumes: diff --git a/front/nginx.conf b/front/nginx.conf index bbba60ab2..64f9436f3 100644 --- a/front/nginx.conf +++ b/front/nginx.conf @@ -1,16 +1,4 @@ -set_real_ip_from 0.0.0.0/0; -real_ip_header X-Forwarded-For; -log_format upstreamlog - '[$time_local] $remote_addr -> $proxy_host:$upstream_addr ' - '"$request" $status $body_bytes_sent ' - '"$http_referer" "$http_user_agent"'; -access_log /var/log/nginx/access.log upstreamlog; - -upstream back { - server back_1:3000; - server back_2:3000; -} server { listen 80 default_server; listen [::]:80 default_server; @@ -24,9 +12,6 @@ server { location @notfound { return 302 /; } - location ~ ^(/[a-zA-Z0-9_-]+)?/(?api(/.*)?)$ { - proxy_pass http://back/$path$is_args$args; - } location / { autoindex on; } diff --git a/loopback/common/models/vn-model.js b/loopback/common/models/vn-model.js index d03d52ae8..0191967b1 100644 --- a/loopback/common/models/vn-model.js +++ b/loopback/common/models/vn-model.js @@ -20,7 +20,7 @@ module.exports = function(Self) { this.beginTransaction = function(options, cb) { options = options || {}; if (!options.timeout) - options.timeout = 30000; + options.timeout = 120000; return orgBeginTransaction.call(this, options, cb); }; }); From 72bca19f49252661aa7a4e9a8dff92a8396ef497 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Sun, 8 Dec 2019 13:48:57 +0100 Subject: [PATCH 2/8] Autorestart --- back/process.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/back/process.yml b/back/process.yml index 3e9f3ef19..f9a170332 100644 --- a/back/process.yml +++ b/back/process.yml @@ -1,6 +1,6 @@ apps: - script: ./loopback/server/server.js name: salix-back - cron_restart: 0 */2 * * * + cron_restart: */1 * * * * instances: 1 max_restarts: 10 From fb8bb0c8bc0ffacc925bfe75a012bbaab25fa9a2 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Sun, 8 Dec 2019 13:52:58 +0100 Subject: [PATCH 3/8] process.yml fixes --- back/process.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/back/process.yml b/back/process.yml index f9a170332..dc125c9e0 100644 --- a/back/process.yml +++ b/back/process.yml @@ -1,6 +1,6 @@ apps: - script: ./loopback/server/server.js name: salix-back - cron_restart: */1 * * * * + cron_restart: '*/1 * * * *' instances: 1 max_restarts: 10 From 68417e00ac29626fca425913bc96a4ac77744c8d Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Sun, 8 Dec 2019 13:54:20 +0100 Subject: [PATCH 4/8] Autorestart checked & enabled every 15 minuts --- back/process.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/back/process.yml b/back/process.yml index dc125c9e0..7f5d029f0 100644 --- a/back/process.yml +++ b/back/process.yml @@ -1,6 +1,6 @@ apps: - script: ./loopback/server/server.js name: salix-back - cron_restart: '*/1 * * * *' + cron_restart: '*/15 * * * *' instances: 1 max_restarts: 10 From b10fb4433bc4e8351978e62774486f1168be8475 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Sun, 8 Dec 2019 14:02:05 +0100 Subject: [PATCH 5/8] Back restarted every 30 minuts --- back/process.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/back/process.yml b/back/process.yml index 7f5d029f0..c35876898 100644 --- a/back/process.yml +++ b/back/process.yml @@ -1,6 +1,6 @@ apps: - script: ./loopback/server/server.js name: salix-back - cron_restart: '*/15 * * * *' + cron_restart: '*/30 * * * *' instances: 1 max_restarts: 10 From 1f50030301b66407385623be1ebc6205d3edbdaf Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Sun, 8 Dec 2019 14:16:01 +0100 Subject: [PATCH 6/8] Back port range fixes --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index a462973ce..0aaba1e93 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -11,9 +11,9 @@ pipeline { DOCKER_HOST_1 = 'vch1.verdnatura.es' DOCKER_HOST_2 = 'vch2.verdnatura.es' PORT_MASTER_FRONT = '5002' - PORT_MASTER_BACK = '3001-3005' + PORT_MASTER_BACK = '3001-3002' PORT_TEST_FRONT = '5001' - PORT_TEST_BACK = '4001-4005' + PORT_TEST_BACK = '4001-4002' TAG = "${env.BRANCH_NAME}" } stages { From 7fbefce3a6000e9dccafc63096d7f00af3e56ac2 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Mon, 9 Dec 2019 11:36:20 +0100 Subject: [PATCH 7/8] Back restart rescheduled --- back/process.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/back/process.yml b/back/process.yml index c35876898..edf66a8c1 100644 --- a/back/process.yml +++ b/back/process.yml @@ -1,6 +1,6 @@ apps: - script: ./loopback/server/server.js name: salix-back - cron_restart: '*/30 * * * *' + cron_restart: '0 4 * * *' instances: 1 max_restarts: 10 From 1b32c13c7f6be3f11ae0ff07ffc9cf59cbbc3796 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Wed, 11 Dec 2019 16:30:45 +0100 Subject: [PATCH 8/8] Disabled back restart, added back healthcheck --- Dockerfile | 4 +++- back/process.yml | 3 +-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 65c2aa0b1..f2cbeeff9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,6 @@ RUN apt-get update \ && apt-get install -y --no-install-recommends \ nodejs \ && apt-get purge -y --auto-remove \ - curl \ gnupg2 \ && rm -rf /var/lib/apt/lists/* \ && npm -g install pm2 @@ -34,3 +33,6 @@ COPY \ ./ CMD ["pm2-runtime", "./back/process.yml"] + +HEALTHCHECK --interval=1m --timeout=10s \ + CMD curl -f http://localhost:3000/api/Applications/status || exit 1 diff --git a/back/process.yml b/back/process.yml index edf66a8c1..3062091b4 100644 --- a/back/process.yml +++ b/back/process.yml @@ -1,6 +1,5 @@ apps: - script: ./loopback/server/server.js name: salix-back - cron_restart: '0 4 * * *' instances: 1 - max_restarts: 10 + max_restarts: 5