Guest User

Untitled

a guest
Nov 7th, 2018
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. image: node:10.5.0
  2.  
  3. stages:
  4. - build
  5. - test
  6. - deploy
  7.  
  8. cache:
  9. key: ${CI_COMMIT_REF_SLUG}
  10. paths:
  11. - node_modules/
  12. - frontend/node_modules/
  13. - frontend/dist/
  14. - backend/node_modules/
  15.  
  16. variables:
  17. POSTGRES_HOST: postgres
  18. POSTGRES_DB: givii-ci
  19. POSTGRES_USER: postgres
  20. POSTGRES_PASSWORD: ""
  21.  
  22. build_staging:
  23. stage: build
  24. script:
  25. - npm i -g yarn
  26. - yarn install
  27. - yarn workspace backend install
  28. - yarn workspace frontend install
  29. - yarn run build:frontend --mode staging
  30. only:
  31. - staging
  32.  
  33. build_production:
  34. stage: build
  35. script:
  36. - npm i -g yarn
  37. - yarn install
  38. - yarn workspace backend install
  39. - yarn workspace frontend install
  40. - yarn run build:frontend
  41. only:
  42. - master
  43.  
  44. test:
  45. stage: test
  46. services:
  47. - postgres:latest
  48. script:
  49. # Run tests
  50. - yarn run test:backend
  51. only:
  52. - master
  53. - staging
  54.  
  55. deploy_staging:
  56. stage: deploy
  57. script:
  58. # Check for ssh-agent + rsync and install if not present
  59. - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
  60. - 'which rsync || ( apt-get update -y && apt-get install rsync -y )'
  61. - eval $(ssh-agent -s)
  62. # Inject the remote's private key
  63. - echo "$STAGING_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
  64. - mkdir -p ~/.ssh
  65. - chmod 700 ~/.ssh
  66. # Append keyscan output into known hosts
  67. - ssh-keyscan $STAGING_IP >> ~/.ssh/known_hosts
  68. - chmod 644 ~/.ssh/known_hosts
  69. - rsync -auz --exclude=".*" $CI_PROJECT_DIR $STAGING_USER@$STAGING_IP:~
  70. # Non interactive ssh gracefully reloads server
  71. - ssh $STAGING_USER@$STAGING_IP '. /etc/profile; cd ~/givii-web/backend && knex migrate:latest && pm2 reload all'
  72. only:
  73. # Trigger deployments only from staging branch
  74. - staging
  75.  
  76. deploy_production:
  77. stage: deploy
  78. script:
  79. # Check for ssh-agent + rsync and install if not present
  80. - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
  81. - 'which rsync || ( apt-get update -y && apt-get install rsync -y )'
  82. - eval $(ssh-agent -s)
  83. # Inject the remote's private key
  84. - echo "$PRODUCTION_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
  85. - mkdir -p ~/.ssh
  86. - chmod 700 ~/.ssh
  87. # Append keyscan output into known hosts
  88. - ssh-keyscan $PRODUCTION_IP >> ~/.ssh/known_hosts
  89. - chmod 644 ~/.ssh/known_hosts
  90. - rsync -auz --exclude=".*" $CI_PROJECT_DIR $PRODUCTION_USER@$PRODUCTION_IP:~
  91. # Non interactive ssh gracefully reloads server
  92. - ssh $PRODUCTION_USER@$PRODUCTION_IP '. /etc/profile; cd ~/givii-web/backend && knex migrate:latest && pm2 reload all'
  93. only:
  94. # Trigger deployments only from master branch
  95. - master
Add Comment
Please, Sign In to add comment