Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- image: node:10.5.0
- stages:
- - build
- - test
- - deploy
- cache:
- key: ${CI_COMMIT_REF_SLUG}
- paths:
- - node_modules/
- - frontend/node_modules/
- - frontend/dist/
- - backend/node_modules/
- variables:
- POSTGRES_HOST: postgres
- POSTGRES_DB: givii-ci
- POSTGRES_USER: postgres
- POSTGRES_PASSWORD: ""
- build_staging:
- stage: build
- script:
- - npm i -g yarn
- - yarn install
- - yarn workspace backend install
- - yarn workspace frontend install
- - yarn run build:frontend --mode staging
- only:
- - staging
- build_production:
- stage: build
- script:
- - npm i -g yarn
- - yarn install
- - yarn workspace backend install
- - yarn workspace frontend install
- - yarn run build:frontend
- only:
- - master
- test:
- stage: test
- services:
- - postgres:latest
- script:
- # Run tests
- - yarn run test:backend
- only:
- - master
- - staging
- deploy_staging:
- stage: deploy
- script:
- # Check for ssh-agent + rsync and install if not present
- - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
- - 'which rsync || ( apt-get update -y && apt-get install rsync -y )'
- - eval $(ssh-agent -s)
- # Inject the remote's private key
- - echo "$STAGING_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
- - mkdir -p ~/.ssh
- - chmod 700 ~/.ssh
- # Append keyscan output into known hosts
- - ssh-keyscan $STAGING_IP >> ~/.ssh/known_hosts
- - chmod 644 ~/.ssh/known_hosts
- - rsync -auz --exclude=".*" $CI_PROJECT_DIR $STAGING_USER@$STAGING_IP:~
- # Non interactive ssh gracefully reloads server
- - ssh $STAGING_USER@$STAGING_IP '. /etc/profile; cd ~/givii-web/backend && knex migrate:latest && pm2 reload all'
- only:
- # Trigger deployments only from staging branch
- - staging
- deploy_production:
- stage: deploy
- script:
- # Check for ssh-agent + rsync and install if not present
- - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
- - 'which rsync || ( apt-get update -y && apt-get install rsync -y )'
- - eval $(ssh-agent -s)
- # Inject the remote's private key
- - echo "$PRODUCTION_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
- - mkdir -p ~/.ssh
- - chmod 700 ~/.ssh
- # Append keyscan output into known hosts
- - ssh-keyscan $PRODUCTION_IP >> ~/.ssh/known_hosts
- - chmod 644 ~/.ssh/known_hosts
- - rsync -auz --exclude=".*" $CI_PROJECT_DIR $PRODUCTION_USER@$PRODUCTION_IP:~
- # Non interactive ssh gracefully reloads server
- - ssh $PRODUCTION_USER@$PRODUCTION_IP '. /etc/profile; cd ~/givii-web/backend && knex migrate:latest && pm2 reload all'
- only:
- # Trigger deployments only from master branch
- - master
Add Comment
Please, Sign In to add comment