.gitlab-ci.yml 5.89 KB
Newer Older
Tom Käsler's avatar
Tom Käsler committed
1 2
variables:
  MIRROR_REPO: git@github.com:thm-projects/arsnova-flashcards.git
3
  NODE_ENV: production
4 5
  BUILD_DIR: build
  BUNDLE_DIR: "$BUILD_DIR/bundle"
6
  REVIEW_SETTINGS: settings_review.json
7
  DB_TEST_DUMP: tests/testDatabaseDump/meteor
Nico Müller's avatar
Nico Müller committed
8

Tom Käsler's avatar
Tom Käsler committed
9 10 11
stages:
  - test
  - build
12
  - chimptest
Tom Käsler's avatar
Tom Käsler committed
13 14 15
  - review
  - deploy

Tom Käsler's avatar
Tom Käsler committed
16 17 18 19 20 21 22 23
jshint:
  stage: test
  tags:
    - nodejs
  dependencies: []
  script:
    - echo "{}" > package.json
    - npm install jshint@^2.9.0
Curtis Adam's avatar
Curtis Adam committed
24
    - node_modules/jshint/bin/jshint --config .jshintrc ./client/head.js ./server/ ./imports/ ./i18n ./tests
Tom Käsler's avatar
Tom Käsler committed
25 26 27 28 29 30 31 32

jscs:
  stage: test
  tags:
    - nodejs
  dependencies: []
  script:
    - npm install jscs
Curtis Adam's avatar
Curtis Adam committed
33
    - node_modules/jscs/bin/jscs --config .jscsrc ./client/head.js ./server/ ./imports/ ./i18n ./tests
Tom Käsler's avatar
Tom Käsler committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59

sonar:
  stage: test
  only:
    - master
    - staging
  tags:
    - gradle
  allow_failure: true
  dependencies: []
  script:
    - gradle sonarqube

jsdoc:
  stage: build
  only:
    - staging
  tags:
    - nodejs
  dependencies: []
  script:
    - npm install
    - jsdoc -c documentation/conf.json -t ./node_modules/ink-docstrap/template -d build/jsdoc -r
  artifacts:
    paths:
      - "$BUILD_DIR/jsdoc/"
Tom Käsler's avatar
Tom Käsler committed
60

Tom Käsler's avatar
Tom Käsler committed
61 62 63 64
build:
  stage: build
  tags:
    - meteor
65
  image: local-nodejs-meteor:8_1.8
Tom Käsler's avatar
Tom Käsler committed
66 67 68 69 70 71 72 73 74 75 76 77 78
  dependencies: []
  script:
    - test -d package-metadata && rm -rf /opt/meteor/package-metadata && mv package-metadata /opt/meteor/
    - npm install
    - meteor build --allow-superuser --server-only --directory "$BUILD_DIR"
    - mv /opt/meteor/package-metadata "$CI_PROJECT_DIR/"
  cache:
    paths:
      - package-metadata
      - .meteor/local
  artifacts:
    paths:
      - "$BUNDLE_DIR"
Tom Käsler's avatar
Tom Käsler committed
79

80 81 82 83
chimp:
  stage: chimptest
  only:
    - /^v[0-9]+/
Curtis Adam's avatar
Curtis Adam committed
84
    - /^[[:digit:]]+?(?=-)/
85 86 87 88
  tags:
    - nodejs
  allow_failure: true
  services:
Curtis Adam's avatar
Curtis Adam committed
89
    - mongo:latest
90 91 92 93 94 95 96 97 98 99
  dependencies:
    - build
  variables:
    PORT: "3000"
    ROOT_URL: "http://localhost:$PORT"
    MONGO_HOST: mongo
    MONGO_PORT: "27017"
    MONGO_DB: meteor-test
    MONGO_URL: "mongodb://$MONGO_HOST:$MONGO_PORT/$MONGO_DB"
  script:
100
    - export METEOR_SETTINGS="$(cat settings_debug.json)"
101 102 103 104 105 106 107
    - mongo --quiet --eval "version();" --host "$MONGO_HOST"
    - cd "$BUNDLE_DIR/programs/server" && npm install
    - cd -
    - node "$BUNDLE_DIR/main.js" &
    - sleep 15
    - ./tests/runTests.sh

Tom Käsler's avatar
Tom Käsler committed
108 109 110
review:
  stage: review
  script:
111 112 113 114
    # Extract ID by using all digits in branch name till "-" is found
    - REVIEW_ID=$(echo $CI_BUILD_REF_NAME | cut -f1 -d '-')
    # Set a variable that points to the app directory
    - METEOR_HOME=/srv/review-apps/$REVIEW_ID
115
    # Make app directory
Tom Käsler's avatar
Tom Käsler committed
116
    - mkdir -p $METEOR_HOME/app
117
    # Copy meteor settings into app directory
118
    - cp $REVIEW_SETTINGS $METEOR_HOME/meteor-settings.json
119
    # Copy the build app (--delete deletes all previous versions of the app)
Tom Käsler's avatar
Tom Käsler committed
120
    - rsync -aqv --delete "$BUNDLE_DIR/"* $METEOR_HOME/app
121
    # Make directory for mongo db test data dump
122
    - mkdir -p $METEOR_HOME/app/dbdump
123
    # Copy mongo db test data
Tom Käsler's avatar
Tom Käsler committed
124
    - rsync -aqv --delete "$DB_TEST_DUMP/"* $METEOR_HOME/dbdump
125
    # Call script to setup everything
Tom Käsler's avatar
Tom Käsler committed
126
    # First parameter is a unique port, second is used to generate the subdomain and the third points to the dbdump directory
127
    - /srv/review-apps/review-app-setup.sh $REVIEW_ID $CI_PIPELINE_ID $METEOR_HOME/dbdump
Tom Käsler's avatar
Tom Käsler committed
128 129
  environment:
    name: review/$CI_BUILD_REF_NAME
130
    url: http://$CI_PIPELINE_ID.review.arsnova.cards/
Tom Käsler's avatar
Tom Käsler committed
131 132
    on_stop: stop_review
  only:
133
    - /^[[:digit:]]+?(?=-)/
Tom Käsler's avatar
Tom Käsler committed
134
  except:
135
    - staging
Tom Käsler's avatar
Tom Käsler committed
136 137 138
    - master
  tags:
    - cards-review
Curtis Adam's avatar
Curtis Adam committed
139
  allow_failure: true
Tom Käsler's avatar
Tom Käsler committed
140 141 142 143

stop_review:
  stage: review
  script:
144 145 146 147
    # Extract ID by using all digits in branch name till "-" is found
    - REVIEW_ID=$(echo $CI_BUILD_REF_NAME | cut -f1 -d '-')
    # Set a variable that points to the app directory
    - METEOR_HOME=/srv/review-apps/$REVIEW_ID
Tom Käsler's avatar
Tom Käsler committed
148 149 150 151
    - cd $METEOR_HOME
    - ./appctl.sh stop
    - cd /srv/review-apps
    - rm -rf $METEOR_HOME
Tom Käsler's avatar
Tom Käsler committed
152 153 154 155 156 157
  variables:
    GIT_STRATEGY: none
  when: manual
  environment:
    name: review/$CI_BUILD_REF_NAME
    action: stop
Tom Käsler's avatar
Tom Käsler committed
158
  only:
159
    - /^[[:digit:]]+?(?=-)/
Tom Käsler's avatar
Tom Käsler committed
160 161 162
  except:
    - staging
    - master
Tom Käsler's avatar
Tom Käsler committed
163 164
  tags:
    - cards-review
Curtis Adam's avatar
Curtis Adam committed
165
  allow_failure: true
Tom Käsler's avatar
Tom Käsler committed
166

Tom Käsler's avatar
Tom Käsler committed
167 168 169 170 171
deploy_staging:
  stage: deploy
  only:
    - staging
  tags:
Tom Käsler's avatar
Tom Käsler committed
172
    - rsync
Tom Käsler's avatar
Tom Käsler committed
173 174 175 176 177 178 179 180
  dependencies:
    - build
    - jsdoc
  script:
    - chmod -R a+rX,ug+w "build"
    - eval $(ssh-agent -s)
    - mkdir ~/.ssh && echo "$NEW_STAGING_SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
    - ssh-add <(echo "$NEW_STAGING_SSH_PRIVATE_KEY")
181 182
    - rsync -rltgoDqv --delete -e "ssh" "build/bundle/"* "$NEW_STAGING_SSH_URL"
    - rsync -rltgoDqv --delete -e "ssh" "build/jsdoc" "$NEW_STAGING_SSH_URL"
183
    - ssh $NEW_STAGING_SSH 'touch /home/meteor/deploy.touch'
Tom Käsler's avatar
Tom Käsler committed
184 185 186 187 188 189 190
  environment: staging

deploy_production:
  stage: deploy
  only:
    - master
  tags:
Tom Käsler's avatar
Tom Käsler committed
191
    - rsync
Tom Käsler's avatar
Tom Käsler committed
192 193 194 195 196 197 198
  dependencies:
    - build
  script:
    - chmod -R a+rX,ug+w "build"
    - eval $(ssh-agent -s)
    - mkdir ~/.ssh && echo "$NEW_PRODUCTION_SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
    - ssh-add <(echo "$NEW_PRODUCTION_SSH_PRIVATE_KEY")
199
    - rsync -rltgoDqv --delete -e "ssh" "$BUNDLE_DIR/"* "$NEW_PRODUCTION_SSH_URL"
200
    - ssh $NEW_PRODUCTION_SSH 'touch /home/meteor/deploy.touch'
Tom Käsler's avatar
Tom Käsler committed
201 202
  environment: production

Tom Käsler's avatar
Tom Käsler committed
203 204 205
deploy_linux:
  stage: deploy
  only:
206
    - master
Tom Käsler's avatar
Tom Käsler committed
207 208 209 210 211 212 213 214 215 216 217 218 219 220
  tags:
    - rsync
  dependencies:
    - build
  script:
    - chmod -R a+rX,ug+w "build"
    - eval $(ssh-agent -s)
    - mkdir ~/.ssh
    - ssh-keyscan "$LINUX_URL" >> ~/.ssh/known_hosts
    - ssh-add <(echo "$LINUX_PRIVATE_KEY")
    - rsync -rltgoDqv --delete -e "ssh" "$BUNDLE_DIR/"* "$LINUX_SSH_URL"
    - ssh $LINUX_SSH 'touch /home/meteor/deploy.touch'
  environment: production

Tom Käsler's avatar
Tom Käsler committed
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
sync_mirror:
  stage: deploy
  tags:
    - git
  when: always
  allow_failure: true
  dependencies: []
  script:
    - eval $(ssh-agent -s)
    - mkdir ~/.ssh && echo "$SYNC_SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
    - ssh-add <(echo "$SYNC_SSH_PRIVATE_KEY")
    - git clone --bare "$CI_REPOSITORY_URL" mirror.git
    - cd mirror.git
    - git push --mirror "$MIRROR_REPO"
  environment: GitHub