diff --git a/.github/workflows/development.yml b/.github/workflows/development.yml index 4eb92d1b84..5503f5dc04 100644 --- a/.github/workflows/development.yml +++ b/.github/workflows/development.yml @@ -21,10 +21,8 @@ jobs: - name: prepare to push to Digital Ocean run: mkdir -p ~/.ssh && echo "${{ secrets.DO_PRIVATE_KEY }}" | tr -d '\r' > ~/.ssh/id_rsa && chmod 600 ~/.ssh/id_rsa && eval "$(ssh-agent -s)" && ssh-add ~/.ssh/id_rsa && ssh-keyscan -H 157.245.121.175 >> ~/.ssh/known_hosts - name: push to Digital Ocean - run: rsync -4 lunieapi.tgz root@157.245.121.175:~/ && rsync -4 pm2metrics.pl root@157.245.121.175:~/ && rsync -4 docker-compose.yml root@157.245.121.175:~/ && rsync -4 Caddyfile root@157.245.121.175:~/ + run: rsync -4 lunieapi.tgz root@157.245.121.175:~/ && rsync -4 docker-compose.yml root@157.245.121.175:~/ && rsync -4 Caddyfile root@157.245.121.175:~/ - name: Installing Docker Compose run: ssh root@157.245.121.175 "sudo curl -L \"https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)\" -o /usr/local/bin/docker-compose; sudo chmod +x /usr/local/bin/docker-compose" - name: Run on Digital Ocean run: ssh root@157.245.121.175 "docker image prune -a -f; docker load < lunieapi.tgz;export HASURA_URL="https://staging-db.lunie.io/v1/graphql"; export HASURA_ADMIN_KEY="${{ secrets.LUNIE_STAGING_DB_KEY }}"; export SENTRY_DSN="${{ secrets.SENTRY_DSN }}"; docker stack deploy -c docker-compose.yml lunieapi; docker service update --image lunieapi:latest --force lunieapi_lunieapi" - - name: Setting up cron job for pm2 metrics export - run: ssh root@157.245.121.175 "mkdir /logs -p; touch /logs/show; line='*/1 * * * * docker exec lunieapi pm2 show 0 > /logs/show; perl /root/pm2metrics.pl'; crontab -l | grep -q 'lunieapi pm2' && true || (crontab -l; echo "$line" ) | crontab -" diff --git a/.github/workflows/production.yml b/.github/workflows/production.yml index 9f63240190..cffe91eb6d 100644 --- a/.github/workflows/production.yml +++ b/.github/workflows/production.yml @@ -21,10 +21,8 @@ jobs: - name: prepare to push to Digital Ocean run: mkdir -p ~/.ssh && echo "${{ secrets.DO_PRIVATE_KEY }}" | tr -d '\r' > ~/.ssh/id_rsa && chmod 600 ~/.ssh/id_rsa && eval "$(ssh-agent -s)" && ssh-add ~/.ssh/id_rsa && ssh-keyscan -H 167.71.107.214 >> ~/.ssh/known_hosts - name: push to Digital Ocean - run: rsync -4 lunieapi.tgz root@167.71.107.214:~/ && rsync -4 pm2metrics.pl root@167.71.107.214:~/ && rsync -4 docker-compose.prod.yml root@167.71.107.214:~/docker-compose.yml && rsync -4 Caddyfile.prod root@167.71.107.214:~/Caddyfile + run: rsync -4 lunieapi.tgz root@167.71.107.214:~/ && && rsync -4 docker-compose.yml root@167.71.107.214:~/docker-compose.yml && rsync -4 Caddyfile.prod root@167.71.107.214:~/Caddyfile - name: Installing Docker Compose run: ssh root@167.71.107.214 "sudo curl -L \"https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)\" -o /usr/local/bin/docker-compose; sudo chmod +x /usr/local/bin/docker-compose" - name: Run on Digital Ocean run: ssh root@167.71.107.214 "docker image prune -a -f; docker load < lunieapi.tgz;export HASURA_URL="https://production-db.lunie.io/v1/graphql"; export HASURA_ADMIN_KEY="${{ secrets.LUNIE_PRODUCTION_DB_KEY }}"; export SENTRY_DSN="${{ secrets.SENTRY_DSN_PRODUCTION }}"; export FIGMENT_COSMOS_HUB_API_KEY="${{ secrets.FIGMENT_COSMOS_HUB_API_KEY }}"; export FIGMENT_GAIA_13007_API_KEY="${{ secrets.FIGMENT_GAIA_13007_API_KEY }}"; docker stack deploy -c docker-compose.yml lunieapi; docker service update --image lunieapi:latest --force lunieapi_lunieapi" - - name: Setting up cron job for pm2 metrics export - run: ssh root@167.71.107.214 "mkdir /logs -p; touch /logs/show; line='*/1 * * * * docker exec lunieapi pm2 show 0 > /logs/show; perl /root/pm2metrics.pl'; crontab -l | grep -q 'lunieapi pm2' && true || (crontab -l; echo "$line" ) | crontab -" diff --git a/Dockerfile b/Dockerfile index fbbab8a23f..97a692665b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM keymetrics/pm2:latest-alpine +FROM node:lts-alpine3.11 WORKDIR /var/www/server @@ -18,12 +18,10 @@ COPY config.js . COPY secrets.js . -COPY pm2.json . - COPY index.js . RUN npm install -CMD [ "pm2-runtime", "start", "pm2.json", "--format"] +CMD npm run start EXPOSE 4200 \ No newline at end of file diff --git a/changes/fabo_remove-pm2 b/changes/fabo_remove-pm2 new file mode 100644 index 0000000000..0ab6bbbaa8 --- /dev/null +++ b/changes/fabo_remove-pm2 @@ -0,0 +1 @@ +[Changed] [#669](https://github.com/cosmos/lunie/pull/669) Remove pm2 @faboweb \ No newline at end of file diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml deleted file mode 100644 index 8a598f3fdb..0000000000 --- a/docker-compose.prod.yml +++ /dev/null @@ -1,89 +0,0 @@ -version: '3.6' - -secrets: - PORT: - external: true - -services: - lunieapi: - image: lunieapi:latest - container_name: lunieapi - restart: on-failure - secrets: - - PORT - volumes: - - /logs:/var/www/server/logs - - ./pushCredentials.json:/var/www/server/pushCredentials.json - networks: - - general - logging: - driver: loki - options: - loki-url: "http://admin:${LOKI_PASSWORD}@monitoring.lunie.io:3100/loki/api/v1/push" - deploy: - replicas: 1 - environment: - - HASURA_URL=$HASURA_URL - - HASURA_ADMIN_KEY=$HASURA_ADMIN_KEY - - SENTRY_DSN=$SENTRY_DSN - - NODE_ENV=production - - ENABLE_CACHE=true - - REDIS_URL=http://redis:6379 - - PUBLIC_VAPID_KEY=BJwy1mP8njRNKyo2uPfjnB73tq6_HHXYnozMPaafCSBpdmoxe9RLYjC2DvRpDfUWoxY3c0-7R3ki9exKJ6cfe5k - - PRIVATE_VAPID_KEY=$PRIVATE_VAPID_KEY - - PUSH_NOTIFICATIONS_DATABASE_URL=https://lunie-push-notifications.firebaseio.com - - PUSH_NOTIFICATIONS_FRONTEND_URL=https://app.lunie.io - - EMONEY_EXCHANGE_API_RATES_ENDPOINT=https://api.exchangeratesapi.io/latest? - - EMONEY_API_MAINNET=https://api.e-money.com/v1/ - - EMONEY_API_TESTNET=https://beta-api.e-money.com/v1/ - node-exporter: - image: prom/node-exporter - container_name: node_exporter - volumes: - - /proc:/host/proc:ro - - /sys:/host/sys:ro - - /root/textfile_collector:/var/www - - /:/rootfs:ro - command: - - --path.procfs=/host/proc - - --path.sysfs=/host/sys - - --collector.textfile.directory=/var/www - - --collector.filesystem.ignored-mount-points - - ^/(sys|proc|dev|host|etc|rootfs/var/lib/docker/containers|rootfs/var/lib/docker/overlay2|rootfs/run/docker/netns|rootfs/var/lib/docker/aufs)($$|/) - restart: always - networks: - - general - deploy: - mode: global - caddy: - image: abiosoft/caddy:0.11.0 - depends_on: - - "lunieapi" - restart: on-failure - container_name: caddy - networks: - - general - deploy: - replicas: 1 - ports: - - "80:80" - - "443:443" - - "9100:9100" - volumes: - - ./Caddyfile:/etc/Caddyfile - - ./caddy_certs:/root/.caddy - redis: - image: redis - container_name: redis - command: ["redis-server", "--appendonly", "yes"] - hostname: redis - networks: - - general - volumes: - - ./redis_data:/data -volumes: - caddy_certs: - redis_data: -networks: - general: - diff --git a/package.json b/package.json index 72338d0b85..3ae8b10dd9 100644 --- a/package.json +++ b/package.json @@ -66,4 +66,4 @@ "resolutions": { "minimist": "1.2.2" } -} +} \ No newline at end of file diff --git a/pm2.json b/pm2.json deleted file mode 100644 index 4169b9c3ea..0000000000 --- a/pm2.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "lunietest", - "script": "npm", - "instances": "1", - "args": ["run", "start"], - "error_file": "/var/www/server/logs/error.log", - "combine_logs": true, - "time": true -} diff --git a/pm2metrics.pl b/pm2metrics.pl deleted file mode 100644 index faa1982f8f..0000000000 --- a/pm2metrics.pl +++ /dev/null @@ -1,61 +0,0 @@ -#!/usr/bin/perl -my $filename = "/root/textfile_collector/pm2errors.prom"; -my $logfile = "/logs/show"; -my $parameters = 0; -sub trim { my $s = shift; $s =~ s/^\s+|\s+$//g; return $s }; - -open(my $fh, '<', $logfile); -open(my $fw, '>', $filename); -# fetching log file -while (my $row = <$fh>) { - chomp $row; - if($parameters && index($row, '─────') == -1){ - my @params = split("│", $row); - my $pname = lc trim(@params[1]); - $pname =~ s/ /_/ig; - my $pvalue = trim(@params[2]); - # special parsing for uptime and status - if($pname eq 'uptime'){ - my $pvalue_digit = $pvalue; - $pvalue_digit =~ s/[^0-9]//g; - #print($pvalue); - if(index($pvalue, 'h') != -1){ - $pvalue = $pvalue_digit * 60; - } - if(index($pvalue, 'd') != -1){ - $pvalue = $pvalue_digit * 60 * 24; - } - if(index($pvalue, 'm') != -1){ - $pvalue = $pvalue_digit; - } - if(index($pvalue, 's') != -1){ - $pvalue = $pvalue_digit / 60; - } - } - if($pname eq 'status'){ - if($pvalue eq 'online'){ - $pvalue = 1; - }else{ - $pvalue = 0; - } - } - #print($pvalue =~ qr/^[0-9\.]+$/); - my $dotscount = () = $pvalue =~ /\./g; - # only numerical values goes to metrics - if($pname && $pvalue =~ qr/^[0-9\.]+$/ && $dotscount < 2){ - print $fw 'pm2_'.$pname . ' ' . $pvalue ."\n"; - } - - } - if(index($row, '────') != -1){ - if($paremeters){ - $parameters = 0; - }else{ - $parameters = 1; - } - } - -} -close $fw; -close $fh; -exit 0;