.gitlab-ci.yml 7.34 KB
Newer Older
Andrew Newdigate's avatar
Andrew Newdigate committed
1 2 3
stages:
  - docker_images
  - build_unit_test
Andrew Newdigate's avatar
Andrew Newdigate committed
4
  - pre_deploy
Andrew Newdigate's avatar
Andrew Newdigate committed
5 6
  - deploy

Andrew Newdigate's avatar
Andrew Newdigate committed
7
.node_job: &node_job
Andrew Newdigate's avatar
Andrew Newdigate committed
8 9
  image: registry.gitlab.com/gitlab-org/gitter/webapp
  before_script:
10 11
    - node --version
    - npm --version
Andrew Newdigate's avatar
Andrew Newdigate committed
12 13 14 15
    - npm config set prefer-offline true
    - npm config set cache /npm_cache
    - mv /app/node_modules ./node_modules
    - npm install
16 17 18 19 20 21 22
  artifacts:
    expire_in: 31d
    when: always
    paths:
      - /npm_cache/
      - npm_cache/

Andrew Newdigate's avatar
Andrew Newdigate committed
23 24 25 26
validate:
  <<: *node_job
  stage: build_unit_test
  script:
Eric Eastwood's avatar
Eric Eastwood committed
27
    - "echo 'TODO: Skip validation for now because we have new eslint failures'"
28
    - make validate
29 30 31 32
    # TODO: This should be part of `make validate` -> `gulpfile-linter`
    # but the prettier API doesn't easily allow glob checking and I want
    # to re-use the scripts that GitLab has, https://gitlab.com/gitlab-org/gitlab-ce/issues/57010
    - npm run prettier -- --check "**/*.js"
Eric Eastwood's avatar
Eric Eastwood committed
33

34 35 36 37
test:
  <<: *node_job
  variables:
    BLUEBIRD_DEBUG: 1
38
    NEO4J_AUTH: none
39 40 41 42 43
  stage: build_unit_test
  services:
    - registry.gitlab.com/gitlab-org/gitter/webapp/mongo:latest
    - registry.gitlab.com/gitlab-org/gitter/webapp/elasticsearch:latest
    - redis:3.0
44
    - neo4j:2.3
45 46
  script:
    - make ci-test
Andrew Newdigate's avatar
Andrew Newdigate committed
47

Andrew Newdigate's avatar
Andrew Newdigate committed
48 49 50
package:
  <<: *node_job
  stage: build_unit_test
Andrew Newdigate's avatar
Andrew Newdigate committed
51
  script:
Eric Eastwood's avatar
Eric Eastwood committed
52
    # While testing the deploment, you can use cached artifacts instead of packaging every time which is slow
53 54
    #- (apt-get update && apt-get install unzip && curl -Ls https://gitlab.com/gitlab-org/gitter/webapp/-/jobs/60049410/artifacts/download -o previous-artifacts.zip && unzip previous-artifacts.zip) || (make package)
    - make package
Andrew Newdigate's avatar
Andrew Newdigate committed
55 56
  artifacts:
    paths:
57 58 59 60 61
      - output/app.tar.gz
      - output/assets.tar.gz
      - output/app/ASSET_TAG
      - output/app/GIT_COMMIT
      - output/app/VERSION
Andrew Newdigate's avatar
Andrew Newdigate committed
62
    expire_in: 1 week
Andrew Newdigate's avatar
Andrew Newdigate committed
63

64 65 66 67
mobile-asset-build:
  <<: *node_job
  stage: build_unit_test
  only:
68
    - master
69
  script:
70
    - npm run task-js
71 72 73 74 75 76 77
    - npm run build-android-assets
    - npm run build-ios-assets
  artifacts:
    paths:
      - output/android/www
      - output/ios/www

78
.distribute_job: &distribute_job
Andrew Newdigate's avatar
Andrew Newdigate committed
79 80 81
  image: registry.gitlab.com/gitlab-org/gitter/webapp/deploy-build-image:latest
  stage: pre_deploy
  dependencies:
82
    - package
Andrew Newdigate's avatar
Andrew Newdigate committed
83 84 85
  script:
    - make upload-to-s3

86 87 88
distribute_beta:
  <<: *distribute_job
  only:
89
    - develop
90 91 92 93 94 95 96 97
  variables:
    DIST_S3_URL: s3://gitter-deployments/gitter-webapp/beta

distribute_beta_staging:
  <<: *distribute_job
  variables:
    DIST_S3_URL: s3://gitter-deployments/gitter-webapp/beta-staging

98 99 100
distribute_staging:
  <<: *distribute_job
  only:
101
    - /^release\/.*$/
102 103 104 105 106 107 108 109 110 111
  variables:
    DIST_S3_URL: s3://gitter-deployments/gitter-webapp/staging

distribute_prod:
  <<: *distribute_job
  only:
    - tags
  variables:
    DIST_S3_URL: s3://gitter-deployments/gitter-webapp/prod

Andrew Newdigate's avatar
Andrew Newdigate committed
112 113
containerize:
  stage: deploy
Andrew Newdigate's avatar
Andrew Newdigate committed
114
  image: docker:latest
Andrew Newdigate's avatar
Andrew Newdigate committed
115 116
  dependencies:
    - package
117 118 119
  allow_failure: true
  variables:
    DOCKER_DRIVER: overlay
Andrew Newdigate's avatar
Andrew Newdigate committed
120
  services:
121
    - docker:dind
Andrew Newdigate's avatar
Andrew Newdigate committed
122
  script:
123
    - ls -la output
Andrew Newdigate's avatar
Andrew Newdigate committed
124
    - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN registry.gitlab.com
Andrew Newdigate's avatar
Andrew Newdigate committed
125 126
    - docker build -t registry.gitlab.com/gitlab-org/gitter/webapp/app:$CI_COMMIT_REF_SLUG -f Dockerfile-app-base .
    - docker push registry.gitlab.com/gitlab-org/gitter/webapp/app:$CI_COMMIT_REF_SLUG
Andrew Newdigate's avatar
Andrew Newdigate committed
127 128
  tags:
    - docker
Andrew Newdigate's avatar
Andrew Newdigate committed
129

130 131 132 133
deploy-build-image:
  stage: docker_images
  image: docker:latest
  services:
134 135 136 137 138
    - docker:dind
  only:
    - schedules
  variables:
    DOCKER_DRIVER: overlay
139 140 141 142
  script:
    - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN registry.gitlab.com
    - docker build -t registry.gitlab.com/gitlab-org/gitter/webapp/deploy-build-image:latest scripts/docker/deploy-build-image/
    - docker push registry.gitlab.com/gitlab-org/gitter/webapp/deploy-build-image:latest
Andrew Newdigate's avatar
Andrew Newdigate committed
143 144
  tags:
    - docker
145

Andrew Newdigate's avatar
Andrew Newdigate committed
146
.deploy_job: &deploy_job
147
  stage: deploy
Andrew Newdigate's avatar
Andrew Newdigate committed
148
  image: registry.gitlab.com/gitlab-org/gitter/webapp/deploy-build-image:latest
149 150
  variables:
    GIT_STRATEGY: none
Andrew Newdigate's avatar
Andrew Newdigate committed
151 152 153 154 155
  before_script:
    # run ssh-agent
    - eval $(ssh-agent -s)
    # add ssh key stored in SSH_PRIVATE_KEY variable to the agent store
    - ssh-add <(echo "$DEPLOY_KEY_ANSIBLE_REPO")
Eric Eastwood's avatar
Eric Eastwood committed
156
    - ssh-add <(echo "$INTERNAL_GITTER_NETWORK_SSH_KEY")
Andrew Newdigate's avatar
Andrew Newdigate committed
157 158
    - mkdir -p ~/.ssh
    - echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
159
    # Make the infra tools available (like Ansible)
Eric Eastwood's avatar
Eric Eastwood committed
160 161 162
    - git clone git@gitlab.com:gl-infra/gitter-infrastructure.git
    - ANSIBLE_DIR=$(cd gitter-infrastructure/ansible && pwd) && echo $ANSIBLE_DIR
    - mkdir -p /root && echo "$ANSIBLE_VAULT_PASS" > /root/.vault_pass
163 164
  tags:
    - internal # This has to be within the Gitter network
Eric Eastwood's avatar
Eric Eastwood committed
165

166
deploy_beta: &deploy_beta
Andrew Newdigate's avatar
Andrew Newdigate committed
167
  <<: *deploy_job
168 169 170
  dependencies:
    - distribute_beta
  only:
171
    - develop
Andrew Newdigate's avatar
Andrew Newdigate committed
172
  script:
173
    - cd $ANSIBLE_DIR && ansible-playbook -i beta --vault-password-file "/root/.vault_pass" playbooks/gitter/webapp-deploy.yml
Andrew Newdigate's avatar
Andrew Newdigate committed
174 175 176 177
  environment:
    name: beta
    url: https://beta.gitter.im

178 179 180 181 182
deploy_beta_manual:
  <<: *deploy_beta
  when: manual

deploy_beta_staging: &deploy_beta_staging
Andrew Newdigate's avatar
Andrew Newdigate committed
183
  <<: *deploy_job
184 185
  dependencies:
    - distribute_beta_staging
186 187
  only:
    - /^feature\/.*$/
Andrew Newdigate's avatar
Andrew Newdigate committed
188
  script:
189
    - cd $ANSIBLE_DIR && ansible-playbook -i beta --vault-password-file "/root/.vault_pass" playbooks/gitter/webapp-staging-deploy.yml
Andrew Newdigate's avatar
Andrew Newdigate committed
190
  environment:
Andrew Newdigate's avatar
Andrew Newdigate committed
191 192
    name: beta_staging
    url: https://beta.gitter.im?gitter_next=true
Andrew Newdigate's avatar
Andrew Newdigate committed
193

194 195 196
deploy_beta_staging_manual:
  <<: *deploy_beta_staging
  when: manual
197 198
  only:
    - /.*/
199 200 201 202 203 204

deploy_staging: &deploy_staging
  <<: *deploy_job
  dependencies:
    - distribute_staging
  only:
205
    - /^release\/.*$/
206
  script:
207
    - cd $ANSIBLE_DIR && ansible-playbook -i prod --vault-password-file "/root/.vault_pass" playbooks/gitter/webapp-staging-deploy.yml
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
  environment:
    name: staging
    url: https://gitter.im?gitter_next=true

deploy_staging_manual:
  <<: *deploy_staging
  when: manual

deploy_prod_manual: &deploy_prod
  <<: *deploy_job
  dependencies:
    - distribute_prod
  only:
    - tags
  # Production is only manual
  when: manual
  script:
225
    - cd $ANSIBLE_DIR && ansible-playbook -i prod --vault-password-file "/root/.vault_pass" playbooks/gitter/webapp-deploy.yml
226 227 228 229
  environment:
    name: prod
    url: https://gitter.im

Andrew Newdigate's avatar
Andrew Newdigate committed
230
docker-base:
231
  image: docker:latest
Andrew Newdigate's avatar
Andrew Newdigate committed
232 233
  stage: docker_images
  only:
234 235 236
    - schedules
  variables:
    DOCKER_DRIVER: overlay
Andrew Newdigate's avatar
Andrew Newdigate committed
237
  services:
238
    - docker:dind
Andrew Newdigate's avatar
Andrew Newdigate committed
239 240 241 242
  script:
    - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN registry.gitlab.com
    - docker build -t registry.gitlab.com/gitlab-org/gitter/webapp:latest .
    - docker push registry.gitlab.com/gitlab-org/gitter/webapp:latest
Andrew Newdigate's avatar
Andrew Newdigate committed
243 244
  tags:
    - docker
Andrew Newdigate's avatar
Andrew Newdigate committed
245 246 247 248

mongo-base:
  stage: docker_images
  image: docker:latest
249 250 251 252
  only:
    - schedules
  variables:
    DOCKER_DRIVER: overlay
Andrew Newdigate's avatar
Andrew Newdigate committed
253
  services:
254
    - docker:dind
Andrew Newdigate's avatar
Andrew Newdigate committed
255 256 257 258
  script:
    - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN registry.gitlab.com
    - docker build -t registry.gitlab.com/gitlab-org/gitter/webapp/mongo:latest scripts/docker/mongo-image/
    - docker push registry.gitlab.com/gitlab-org/gitter/webapp/mongo:latest
Andrew Newdigate's avatar
Andrew Newdigate committed
259 260
  tags:
    - docker
Andrew Newdigate's avatar
Andrew Newdigate committed
261 262 263 264

elasticsearch-base:
  stage: docker_images
  image: docker:latest
265 266 267 268
  only:
    - schedules
  variables:
    DOCKER_DRIVER: overlay
Andrew Newdigate's avatar
Andrew Newdigate committed
269
  services:
270
    - docker:dind
Andrew Newdigate's avatar
Andrew Newdigate committed
271 272 273 274
  script:
    - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN registry.gitlab.com
    - docker build -t registry.gitlab.com/gitlab-org/gitter/webapp/elasticsearch:latest scripts/docker/elasticsearch-image/
    - docker push registry.gitlab.com/gitlab-org/gitter/webapp/elasticsearch:latest
Andrew Newdigate's avatar
Andrew Newdigate committed
275 276
  tags:
    - docker