.gitlab-ci.yml 4.24 KB
Newer Older
Sam Galson's avatar
Sam Galson committed
1 2 3 4 5
variables:
  IMAGE_ORG: pubsweet
  IMAGE_NAME: pubsweet
  BASE_DOMAIN: gateway.ps.semioticsquares.com
  CONFIGURATION_REPOSITORY: https://gitlab.coko.foundation/pubsweet/deployment-config.git
6

Sam Galson's avatar
Sam Galson committed
7 8 9 10 11 12 13 14 15 16
stages:
  - build
  - test
  - review
  - staging
  - production
  - demo

build:
  image: docker:latest
17
  stage: build
Jure's avatar
Jure committed
18 19
  except:
    - tags
Sam Galson's avatar
Sam Galson committed
20
  script:
21
    - docker version
Jure's avatar
Jure committed
22
    - docker build -t $IMAGE_ORG/$IMAGE_NAME:$CI_COMMIT_SHA .
23 24 25 26
    - if [ -z "$DOCKERHUB_USERNAME" ] || [ -z "$DOCKERHUB_PASSWORD" ]; then echo "Not pushing" && exit 0; fi
    - docker login -u $DOCKERHUB_USERNAME -p $DOCKERHUB_PASSWORD
    - echo "Ignore warning! Cannot perform an interactive login from a non TTY device"
    - docker push $IMAGE_ORG/$IMAGE_NAME:$CI_COMMIT_SHA
27

28
lint:style:
Sam Galson's avatar
Sam Galson committed
29 30
  image: $IMAGE_ORG/$IMAGE_NAME:$CI_COMMIT_SHA
  stage: test
Jure's avatar
Jure committed
31 32
  except:
    - tags
Sam Galson's avatar
Sam Galson committed
33 34
  variables:
    GIT_STRATEGY: none
Jure's avatar
Jure committed
35
  script:
Sam Galson's avatar
Sam Galson committed
36
    - cd ${HOME}
Jure's avatar
Jure committed
37
    - npm run lint:style
38

39
lint:js:
Sam Galson's avatar
Sam Galson committed
40 41
  image: $IMAGE_ORG/$IMAGE_NAME:$CI_COMMIT_SHA
  stage: test
Jure's avatar
Jure committed
42 43
  except:
    - tags
Sam Galson's avatar
Sam Galson committed
44 45
  variables:
    GIT_STRATEGY: none
Jure's avatar
Jure committed
46
  script:
Sam Galson's avatar
Sam Galson committed
47
    - cd ${HOME}
Jure's avatar
Jure committed
48
    - npm run lint:js
49

50 51 52
lint:json:
  image: $IMAGE_ORG/$IMAGE_NAME:$CI_COMMIT_SHA
  stage: test
Jure's avatar
Jure committed
53 54
  except:
    - tags
55 56 57 58 59 60
  variables:
    GIT_STRATEGY: none
  script:
    - cd ${HOME}
    - npm run lint:json
  
61 62 63
lint:commits:
   image: $IMAGE_ORG/$IMAGE_NAME:$CI_COMMIT_SHA
   stage: test
Jure's avatar
Jure committed
64 65
   except:
     - tags
66
   script:
Jure's avatar
Jure committed
67 68
     - cp -r .git ${HOME}/ && cd ${HOME}
     - yarn commitlint --from=origin/master --to=$CI_COMMIT_SHA
69

70
test:
Sam Galson's avatar
Sam Galson committed
71 72 73
  image: $IMAGE_ORG/$IMAGE_NAME:$CI_COMMIT_SHA
  stage: test
  variables:
Tamlyn Rhodes's avatar
Tamlyn Rhodes committed
74
    # don't clone repo as image already has it
Sam Galson's avatar
Sam Galson committed
75
    GIT_STRATEGY: none
Tamlyn Rhodes's avatar
Tamlyn Rhodes committed
76 77 78 79 80 81 82 83 84
    # setup data for postgres image
    POSTGRES_USER: test
    POSTGRES_PASSWORD: pw
    # connection details for tests
    PGUSER: test
    PGPASSWORD: pw
    NODE_ENV: test
  services:
    - postgres
Jure's avatar
Jure committed
85 86
  except:
    - tags
Jure's avatar
Jure committed
87
  script:
Sam Galson's avatar
Sam Galson committed
88
    - cd ${HOME}
Tamlyn Rhodes's avatar
Tamlyn Rhodes committed
89 90
    # specify host here else it confuses the linked postgres image
    - PGHOST=postgres npm run test
Jure's avatar
Jure committed
91

92 93 94 95 96 97 98 99 100 101
# if tests pass we will push latest, labelled with current commit hash
push:latest:
  image: docker:latest
  stage: staging
  script:
    - if [ -z "$DOCKERHUB_USERNAME" ] || [ -z "$DOCKERHUB_PASSWORD" ]; then echo "Not pushing" && exit 0; fi
    - docker login -u $DOCKERHUB_USERNAME -p $DOCKERHUB_PASSWORD
    - echo "Ignore warning! Cannot perform an interactive login from a non TTY device"
    - docker build -t $IMAGE_ORG/$IMAGE_NAME:latest --label COMMIT_SHA=$CI_COMMIT_SHA .
    - docker push $IMAGE_ORG/$IMAGE_NAME:latest
Sam Galson's avatar
Sam Galson committed
102
  only:
Jure's avatar
Jure committed
103 104 105
    - master
  except:
    - tags
106

Sam Galson's avatar
Sam Galson committed
107 108 109 110 111
# -----------------------------------------------
# ui --------------------------------------------
# -----------------------------------------------

review:ui:
112
  image: pubsweet/deployer:latest
Sam Galson's avatar
Sam Galson committed
113 114 115 116 117 118
  stage: review
  variables:
    PACKAGE_NAME: ui
  environment:
    name: $PACKAGE_NAME/review/$CI_COMMIT_REF_NAME
    # !! kube-lego will fail if domain > 63 chars
Sam Galson's avatar
Sam Galson committed
119
    url: "http://${CI_ENVIRONMENT_SLUG}.${BASE_DOMAIN}"
Sam Galson's avatar
Sam Galson committed
120 121
    on_stop: stop_review:ui
  except:
122 123
    - master
    - tags
Sam Galson's avatar
Sam Galson committed
124 125 126 127 128
  script:
    - source deploy.sh
    - create_deployment

stop_review:ui:
129
  image: pubsweet/deployer:latest
Sam Galson's avatar
Sam Galson committed
130 131
  stage: review
  variables:
132
    PACKAGE_NAME: ui
Sam Galson's avatar
Sam Galson committed
133 134 135 136 137 138
    GIT_STRATEGY: none
  environment:
    name: $PACKAGE_NAME/review/$CI_COMMIT_REF_NAME
    action: stop
  when: manual
  except:
Jure's avatar
Jure committed
139 140
    - master
    - tags
Sam Galson's avatar
Sam Galson committed
141 142
  script:
    - source deploy.sh
143
    - delete_deployment
Jure's avatar
Jure committed
144

Sam Galson's avatar
Sam Galson committed
145
staging:ui:
146
  image: pubsweet/deployer:latest
Sam Galson's avatar
Sam Galson committed
147 148 149 150 151 152 153
  stage: staging
  variables:
    PACKAGE_NAME: ui
  environment:
    name: $PACKAGE_NAME/staging
    url: "https://${CI_ENVIRONMENT_SLUG}.${BASE_DOMAIN}"
  only:
Jure's avatar
Jure committed
154 155 156
    - master
  except:
    - tags
Sam Galson's avatar
Sam Galson committed
157 158 159 160 161
  script:
    - source deploy.sh
    - create_deployment

production:ui:
162
  image: pubsweet/deployer:latest
Sam Galson's avatar
Sam Galson committed
163 164 165 166 167 168 169 170
  stage: production
  variables:
    PACKAGE_NAME: ui
  environment:
    name: $PACKAGE_NAME/production
    url: "https://${CI_ENVIRONMENT_SLUG}.${BASE_DOMAIN}"
  when: manual
  only:
Jure's avatar
Jure committed
171 172 173
    - master
  except:
    - tags
Sam Galson's avatar
Sam Galson committed
174 175 176 177 178
  script:
    - source deploy.sh
    - create_deployment

demo:ui:
179
  image: pubsweet/deployer:latest
Sam Galson's avatar
Sam Galson committed
180 181 182 183 184 185 186
  stage: demo
  variables:
    PACKAGE_NAME: ui
  environment:
    name: $PACKAGE_NAME/demo
    url: "https://${CI_ENVIRONMENT_SLUG}.${BASE_DOMAIN}"
  when: manual
Jure's avatar
Jure committed
187 188
  except:
    - tags
Sam Galson's avatar
Sam Galson committed
189 190 191
  script:
    - source deploy.sh
    - create_deployment