.gitlab-ci.yml 1.74 KB
Newer Older
Eric Eastwood's avatar
Eric Eastwood committed
1 2 3 4 5 6 7 8 9 10 11
image: node:boron

cache:
  paths:
  - node_modules/

stages:
  - build
  - test
  - deploy

12 13 14
before_script:
  - node --version
  - npm --version
15 16 17 18
  # See https://docs.gitlab.com/ee/ci/ssh_keys/README.html
  # -----------------------------------------------------------
  # Install ssh-agent if not already installed, it is required by Docker.
  # (change apt-get to yum if you use a CentOS-based image)
Eric Eastwood's avatar
Eric Eastwood committed
19
  - 'which ssh-agent || (apt-get update -y && apt-get install openssh-client -y)'
20 21 22 23 24 25 26 27 28 29
  # Run ssh-agent (inside the build environment)
  - eval $(ssh-agent -s)
  # Add the SSH key stored in SSH_PRIVATE_KEY variable to the agent store
  - ssh-add <(echo "$SSH_PRIVATE_KEY")
  # For Docker builds disable host key checking. Be aware that by adding that
  # you are suspectible to man-in-the-middle attacks.
  # WARNING: Use this only with the Docker executor, if you use it with shell
  # you will overwrite your user's SSH config.
  - mkdir -p ~/.ssh
  - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
Eric Eastwood's avatar
Eric Eastwood committed
30 31
  # Install rsync
  # --------
Eric Eastwood's avatar
Eric Eastwood committed
32
  - 'which rsync || (apt-get update -y && apt-get install rsync -y)'
33

Eric Eastwood's avatar
Eric Eastwood committed
34 35 36 37 38 39 40 41 42

build:
  stage: build
  script:
    - npm install
  artifacts:
    paths:
      - node_modules/
  tags:
43 44
    - docker
    - shared
Eric Eastwood's avatar
Eric Eastwood committed
45 46 47 48


test:
  stage: test
Eric Eastwood's avatar
Eric Eastwood committed
49 50
  script:
    - npm run lint
Eric Eastwood's avatar
Eric Eastwood committed
51
  tags:
52 53
    - docker
    - shared
Eric Eastwood's avatar
Eric Eastwood committed
54 55 56 57 58


deploy:
  stage: deploy
  script:
59 60
    # Exclude `data` to save the file store between deploys
    - rsync -r --delete-after --exclude 'data' --quiet ./ $SSH_USER@$DEPLOY_HOST::apilab/
61
    - ssh $SSH_USER@$DEPLOY_HOST '. ~/.bashrc && . ~/.nvm/nvm.sh && nvm use stable && pm2 restart apilab'
62 63 64 65 66
  environment:
    name: production
    url: https://apilab.gitlab.org
  only:
    - master
Eric Eastwood's avatar
Eric Eastwood committed
67
  tags:
68 69
    - docker
    - shared