.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

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

jsdoc:
  stage: build
  only:
    - staging
Curtis Adam's avatar
Curtis Adam committed
51
    - /^[[:digit:]]+?-/
Tom Käsler's avatar
Tom Käsler committed
52 53 54 55 56 57 58 59 60
  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
61

Tom Käsler's avatar
Tom Käsler committed
62 63 64 65
build:
  stage: build
  tags:
    - meteor
66
  image: local-nodejs-meteor:8_1.8
Tom Käsler's avatar
Tom Käsler committed
67 68 69 70 71 72 73 74 75 76 77 78 79
  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
80

81 82
chimp:
  stage: chimptest
Curtis Adam's avatar
Curtis Adam committed
83 84
  only:
    - /^v[0-9]+/
85
    - /^[[:digit:]]+?-/
86 87 88 89
  tags:
    - nodejs
  allow_failure: true
  services:
Curtis Adam's avatar
Curtis Adam committed
90
    - mongo:latest
91 92 93 94 95 96 97 98 99 100
  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:
101
    - export METEOR_SETTINGS="$(cat settings_review.json)"
102 103 104 105 106 107 108
    - 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
109 110 111
review:
  stage: review
  script:
112 113 114 115
    # 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
116
    # Make app directory
Tom Käsler's avatar
Tom Käsler committed
117
    - mkdir -p $METEOR_HOME/app
118
    # Copy meteor settings into app directory
119
    - cp $REVIEW_SETTINGS $METEOR_HOME/meteor-settings.json
120
    # Copy the build app (--delete deletes all previous versions of the app)
Tom Käsler's avatar
Tom Käsler committed
121
    - rsync -aqv --delete "$BUNDLE_DIR/"* $METEOR_HOME/app
122
    # Make directory for mongo db test data dump
123
    - mkdir -p $METEOR_HOME/app/dbdump
124
    # Copy mongo db test data
Tom Käsler's avatar
Tom Käsler committed
125
    - rsync -aqv --delete "$DB_TEST_DUMP/"* $METEOR_HOME/dbdump
126
    # Call script to setup everything
Tom Käsler's avatar
Tom Käsler committed
127
    # First parameter is a unique port, second is used to generate the subdomain and the third points to the dbdump directory
128
    - /srv/review-apps/review-app-setup.sh $REVIEW_ID $CI_PIPELINE_ID $METEOR_HOME/dbdump
Tom Käsler's avatar
Tom Käsler committed
129 130
  environment:
    name: review/$CI_BUILD_REF_NAME
131
    url: http://$CI_PIPELINE_ID.review.arsnova.cards/
Tom Käsler's avatar
Tom Käsler committed
132 133
    on_stop: stop_review
  only:
134
    - /^[[:digit:]]+?-/
Tom Käsler's avatar
Tom Käsler committed
135
  except:
136
    - staging
Tom Käsler's avatar
Tom Käsler committed
137 138 139
    - master
  tags:
    - cards-review
Curtis Adam's avatar
Curtis Adam committed
140
  allow_failure: true
Tom Käsler's avatar
Tom Käsler committed
141 142 143 144

stop_review:
  stage: review
  script:
145 146 147 148
    # 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
149 150 151 152
    - cd $METEOR_HOME
    - ./appctl.sh stop
    - cd /srv/review-apps
    - rm -rf $METEOR_HOME
Tom Käsler's avatar
Tom Käsler committed
153 154 155 156 157 158
  variables:
    GIT_STRATEGY: none
  when: manual
  environment:
    name: review/$CI_BUILD_REF_NAME
    action: stop
Tom Käsler's avatar
Tom Käsler committed
159
  only:
160
    - /^[[:digit:]]+?-/
Tom Käsler's avatar
Tom Käsler committed
161 162 163
  except:
    - staging
    - master
Tom Käsler's avatar
Tom Käsler committed
164 165
  tags:
    - cards-review
Curtis Adam's avatar
Curtis Adam committed
166
  allow_failure: true
Tom Käsler's avatar
Tom Käsler committed
167

Tom Käsler's avatar
Tom Käsler committed
168 169
deploy_staging:
  stage: deploy
170
  when: manual
Tom Käsler's avatar
Tom Käsler committed
171
  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