.gitlab-ci.yml 5.7 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 24 25 26 27 28 29 30 31 32 33 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
jshint:
  stage: test
  tags:
    - nodejs
  dependencies: []
  script:
    - echo "{}" > package.json
    - npm install jshint@^2.9.0
    - node_modules/jshint/bin/jshint --config .jshintrc ./client/ ./server/ ./imports/ ./i18n ./tests

jscs:
  stage: test
  tags:
    - nodejs
  dependencies: []
  script:
    - npm install jscs
    - node_modules/jscs/bin/jscs --config .jscsrc ./{client,imports,i18n,server,tests}/

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 84 85 86 87 88
chimp:
  stage: chimptest
  only:
    - staging
    - /^v[0-9]+/
  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
    # Generate port by using all digits in branch name till "-" is found
112
    - METEOR_PORT=$(echo $CI_BUILD_REF_NAME | cut -f1 -d '-')0
113
    # Set a variable that points to the appo directory
Tom Käsler's avatar
Tom Käsler committed
114
    - METEOR_HOME=/srv/review-apps/$METEOR_PORT
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 $METEOR_PORT $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 139 140 141 142
    - master
  tags:
    - cards-review

stop_review:
  stage: review
  script:
143
    - METEOR_PORT=$(echo $CI_BUILD_REF_NAME | cut -f1 -d '-')0
Tom Käsler's avatar
Tom Käsler committed
144 145 146 147 148
    - METEOR_HOME=/srv/review-apps/$METEOR_PORT
    - cd $METEOR_HOME
    - ./appctl.sh stop
    - cd /srv/review-apps
    - rm -rf $METEOR_HOME
Tom Käsler's avatar
Tom Käsler committed
149 150 151 152 153 154
  variables:
    GIT_STRATEGY: none
  when: manual
  environment:
    name: review/$CI_BUILD_REF_NAME
    action: stop
Tom Käsler's avatar
Tom Käsler committed
155
  only:
156
    - /^[[:digit:]]+?(?=-)/
Tom Käsler's avatar
Tom Käsler committed
157 158 159
  except:
    - staging
    - master
Tom Käsler's avatar
Tom Käsler committed
160 161 162
  tags:
    - cards-review

Tom Käsler's avatar
Tom Käsler committed
163 164 165 166 167
deploy_staging:
  stage: deploy
  only:
    - staging
  tags:
Tom Käsler's avatar
Tom Käsler committed
168
    - rsync
Tom Käsler's avatar
Tom Käsler committed
169 170 171 172 173 174 175 176
  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")
177 178
    - rsync -rltgoDqv --delete -e "ssh" "build/bundle/"* "$NEW_STAGING_SSH_URL"
    - rsync -rltgoDqv --delete -e "ssh" "build/jsdoc" "$NEW_STAGING_SSH_URL"
179
    - ssh $NEW_STAGING_SSH 'touch /home/meteor/deploy.touch'
Tom Käsler's avatar
Tom Käsler committed
180 181 182 183 184 185 186
  environment: staging

deploy_production:
  stage: deploy
  only:
    - master
  tags:
Tom Käsler's avatar
Tom Käsler committed
187
    - rsync
Tom Käsler's avatar
Tom Käsler committed
188 189 190 191 192 193 194
  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")
195
    - rsync -rltgoDqv --delete -e "ssh" "$BUNDLE_DIR/"* "$NEW_PRODUCTION_SSH_URL"
196
    - ssh $NEW_PRODUCTION_SSH 'touch /home/meteor/deploy.touch'
Tom Käsler's avatar
Tom Käsler committed
197 198
  environment: production

Tom Käsler's avatar
Tom Käsler committed
199 200 201
deploy_linux:
  stage: deploy
  only:
202
    - master
Tom Käsler's avatar
Tom Käsler committed
203 204 205 206 207 208 209 210 211 212 213 214 215 216
  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
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
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