.gitlab-ci.yml 3.54 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
Sam Galson's avatar
Sam Galson committed
18
  script:
19
    - docker version
Jure's avatar
Jure committed
20
    - docker build -t $IMAGE_ORG/$IMAGE_NAME:$CI_COMMIT_SHA .
21 22 23 24
    - 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
25

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

35
lint:js:
Sam Galson's avatar
Sam Galson committed
36 37 38 39
  image: $IMAGE_ORG/$IMAGE_NAME:$CI_COMMIT_SHA
  stage: test
  variables:
    GIT_STRATEGY: none
Jure's avatar
Jure committed
40
  script:
Sam Galson's avatar
Sam Galson committed
41
    - cd ${HOME}
Jure's avatar
Jure committed
42
    - npm run lint:js
43

44 45 46 47
lint:commits:
   image: $IMAGE_ORG/$IMAGE_NAME:$CI_COMMIT_SHA
   stage: test
   script:
Jure's avatar
Jure committed
48 49
     - cp -r .git ${HOME}/ && cd ${HOME}
     - yarn commitlint --from=origin/master --to=$CI_COMMIT_SHA
50

51
test:
Sam Galson's avatar
Sam Galson committed
52 53 54 55
  image: $IMAGE_ORG/$IMAGE_NAME:$CI_COMMIT_SHA
  stage: test
  variables:
    GIT_STRATEGY: none
Jure's avatar
Jure committed
56
  script:
Sam Galson's avatar
Sam Galson committed
57
    - cd ${HOME}
Sam Galson's avatar
Sam Galson committed
58
    - NODE_ENV=test npm run test
Jure's avatar
Jure committed
59

60 61 62 63 64 65 66 67 68 69
# 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
70 71
  only:
  - master
72

Sam Galson's avatar
Sam Galson committed
73 74 75 76 77
# -----------------------------------------------
# ui --------------------------------------------
# -----------------------------------------------

review:ui:
78
  image: pubsweet/deployer:latest
Sam Galson's avatar
Sam Galson committed
79 80 81 82 83 84
  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
85
    url: "http://${CI_ENVIRONMENT_SLUG}.${BASE_DOMAIN}"
Sam Galson's avatar
Sam Galson committed
86 87 88 89 90 91 92 93
    on_stop: stop_review:ui
  except:
  - master
  script:
    - source deploy.sh
    - create_deployment

stop_review:ui:
94
  image: pubsweet/deployer:latest
Sam Galson's avatar
Sam Galson committed
95 96
  stage: review
  variables:
97
    PACKAGE_NAME: ui
Sam Galson's avatar
Sam Galson committed
98 99 100 101 102 103 104 105 106
    GIT_STRATEGY: none
  environment:
    name: $PACKAGE_NAME/review/$CI_COMMIT_REF_NAME
    action: stop
  when: manual
  except:
  - master
  script:
    - source deploy.sh
107
    - delete_deployment
Jure's avatar
Jure committed
108

Sam Galson's avatar
Sam Galson committed
109
staging:ui:
110
  image: pubsweet/deployer:latest
Sam Galson's avatar
Sam Galson committed
111 112 113 114 115 116 117 118 119 120 121 122 123
  stage: staging
  variables:
    PACKAGE_NAME: ui
  environment:
    name: $PACKAGE_NAME/staging
    url: "https://${CI_ENVIRONMENT_SLUG}.${BASE_DOMAIN}"
  only:
  - master
  script:
    - source deploy.sh
    - create_deployment

production:ui:
124
  image: pubsweet/deployer:latest
Sam Galson's avatar
Sam Galson committed
125 126 127 128 129 130 131 132 133 134 135 136 137 138
  stage: production
  variables:
    PACKAGE_NAME: ui
  environment:
    name: $PACKAGE_NAME/production
    url: "https://${CI_ENVIRONMENT_SLUG}.${BASE_DOMAIN}"
  when: manual
  only:
  - master
  script:
    - source deploy.sh
    - create_deployment

demo:ui:
139
  image: pubsweet/deployer:latest
Sam Galson's avatar
Sam Galson committed
140 141 142 143 144 145 146 147 148 149
  stage: demo
  variables:
    PACKAGE_NAME: ui
  environment:
    name: $PACKAGE_NAME/demo
    url: "https://${CI_ENVIRONMENT_SLUG}.${BASE_DOMAIN}"
  when: manual
  script:
    - source deploy.sh
    - create_deployment