Guest User

Untitled

a guest
Oct 19th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.27 KB | None | 0 0
  1. image: node:latest
  2.  
  3. stages:
  4. - build
  5. - test
  6. - deploy
  7.  
  8. cache:
  9. paths:
  10. - node_modules/
  11. - .next/
  12.  
  13. install_dependencies:
  14. stage: build
  15. script:
  16. - npm install
  17. - npm run build
  18. artifacts:
  19. paths:
  20. - node_modules/
  21. - .next/
  22.  
  23. test-build:
  24. stage: test
  25. script:
  26. - npm run test
  27.  
  28. deploy_production:
  29. stage: deploy
  30. only:
  31. - master
  32. before_script:
  33. - "which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )"
  34. - mkdir -p ~/.ssh
  35. - eval $(ssh-agent -s)
  36. - '[[ -f /.dockerenv ]] && echo -e "Host *ntStrictHostKeyChecking nonn" > ~/.ssh/config'
  37. - ssh-add <(echo "$SSH_PRIVATE_KEY")
  38. - apt-get update -y
  39. - apt-get -y install rsync
  40. script:
  41. - ssh -p22 dev@example.com "mkdir -p /var/www/example.com/index_tmp"
  42. - rsync -rav -e ssh --exclude='.git/' --exclude='.gitlab-ci.yml' --delete-excluded ./ dev@example.com:/var/www/example.com/index_tmp
  43. - ssh -p22 dev@example.com "mv /var/www/example.com/index /var/www/example.com/index_old && mv /var/www/example.com/index_tmp /var/www/example.com/index"
  44. - ssh -p22 dev@example.com "rm -rf /var/www/example.com/index_old"
  45. - ssh -p22 dev@example.com "pm2 restart landing-page"
  46.  
  47. [... rsync output ...]
  48. sent 193,022,347 bytes received 550,996 bytes 9,003,411.30 bytes/sec
  49. total size is 191,108,661 speedup is 0.99
  50. $ ssh -p22 dev@example.com "mv /var/www/example.com/index /var/www/example.com/index_old && mv /var/www/example.com/index_tmp /var/www/example.com/index"
  51. $ ssh -p22 dev@example.com "rm -rf /var/www/example.com/index_old"
  52. $ ssh -p22 dev@example.com "pm2 restart landing-page"
  53. bash: pm2: command not found
  54. ERROR: Job failed: exit code 1
  55.  
  56. dev@example.com:~$ pm2 restart landing-page
  57. Use --update-env to update environment variables
  58. [PM2] Applying action restartProcessId on app [landing-page](ids: 0)
  59. [PM2] [landing-page](0) ✓
  60. ┌──────────────┬────┬─────────┬──────┬───────┬────────┬─────────┬────────┬─────┬──────────┬──────┬──────────┐
  61. │ App name │ id │ version │ mode │ pid │ status │ restart │ uptime │ cpu │ mem │ user │ watching │
  62. ├──────────────┼────┼─────────┼──────┼───────┼────────┼─────────┼────────┼─────┼──────────┼──────┼──────────┤
  63. │ landing-page │ 0 │ 0.33.11 │ fork │ 18174 │ online │ 2 │ 0s │ 0% │ 7.6 MB │ dev │ disabled │
  64. └──────────────┴────┴─────────┴──────┴───────┴────────┴─────────┴────────┴─────┴──────────┴──────┴──────────┘
  65. Use `pm2 show <id|name>` to get more details about an app
  66.  
  67. whereis pm2
  68. # Output something like /usr/bin/pm2
  69.  
  70. script:
  71. - ...
  72. - ssh -p22 dev@example.com "/usr/bin/pm2 restart landing-page"
Add Comment
Please, Sign In to add comment