.gitlab-ci.yml 4.46 KB
Newer Older
1
2
3
4
5
6
7
---
stages:
  - test
  - build
  - staging
  - production

8

9
image: urgi/docker-browsers:latest
10

11

12
13
14
15
16
# Disable the Gradle daemon for Continuous Integration servers as correctness
# is usually a priority over speed in CI environments. Using a fresh
# runtime for each build is more reliable since the runtime is completely
# isolated from any previous builds.
variables:
17
  GRADLE_OPTS: "-Dorg.gradle.daemon=false"
18
  GRADLE_USER_HOME: $CI_PROJECT_DIR/.gradle
19
  APP_NAME: faidare
20
  JAR_PATH: "backend/build/libs/${APP_NAME}.jar"
21

22

23
24
25
26
# Gradle cache for all jobs
cache:
  key: "$CI_COMMIT_REF_NAME"
  paths:
27
28
29
    - ".gradle"
    - "frontend/.gradle/"
    - "frontend/node_modules/"
30

31

32
33
# TESTS

34

35
36
37
38
lint:
  stage: test
  script: "./gradlew lint"

39

40
test-frontend:
41
  stage: test
42
  script: "./gradlew :frontend:test --parallel"
43
44
45
  artifacts:
    reports:
      junit:
46
        - "./frontend/karma-junit-tests-report/TEST*.xml"
47

48

49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
test-backend:
  stage: test
  script: "./gradlew :backend:test --parallel"
  services:
    # even if that would be ideal
    # we can't just launch the service with just elasticsearch:6.3.1
    # because we need to pass some variables, but they are passed to _all_ containers
    # so they fail the start of other docker images like urgi/docker-browsers
    # the only solution is to override the entrypoint of the service and pass the arguments manually
    - name: docker.elastic.co/elasticsearch/elasticsearch:6.5.4
      alias: elasticsearch
      # discovery.type=single-node
      # single-node is necessary to start in development mode
      # so there will be no bootstrap checks that would fail on CI
      # especially the error regarding
      # `max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]`
65
      command: ["bin/elasticsearch", "-Ediscovery.type=single-node"]
66
67
68
69
70
  artifacts:
    reports:
      junit:
        - "./backend/build/test-results/test/TEST-*.xml"

71

72
73
# BUILD

74

75
76
77
78
79
80
81
82
83
84
build:
  stage: build
  script:
    - ./gradlew assemble
  artifacts:
    paths:
      - "$JAR_PATH"
    expire_in: 1 week
  only:
    changes:
85
      - .gitlab-ci.yml
86
87
88
      - backend/src/**/*
      - frontend/**/*

89

90
91
# DEPLOY

92

93
94
95
96
97
98
99
100
101
102
.deploy-to-vm: &deploy_to_vm
  # Hidden job which serves as template for executed jobs below.
  # See https://docs.gitlab.com/ee/ci/yaml/#anchors
  retry: 2
  ## SSH initialization
  before_script:
    - eval $(ssh-agent -s)
    - ssh-add <(echo "${SSH_PRIVATE_KEY}")
    - ssh -o StrictHostKeyChecking=no root@${SERVER_IP} 'echo "Successfully connected on $(hostname)"'
  script:
103
    # Copy jar
104
    - scp ./$JAR_PATH root@${SERVER_IP}:/opt/bootapp/${APP_NAME}-${ENV}.jar
105
    # Restarting service with the updated jar and the according Spring profiles enabled
106
    - ssh root@${SERVER_IP} "systemctl restart bootapp@${APP_NAME}-${ENV}"
107
    - eval $(ssh-agent -k)
108
    - echo "Deploy done. Application should be available at http://${SERVER_IP}:${APP_PORT}/${CONTEXT_PATH}"
109
110


111
112
deploy-to-staging:
  stage: staging
113
  variables:
114
115
116
    ENV: staging
    APP_PORT: ${STAGING_GPDS_PORT}
    CONTEXT_PATH: ${STAGING_GPDS_CONTEXT_PATH}
117
118
119
120
  <<: *deploy_to_vm
  only:
    refs:
      - master
121
122
123
124
    changes:
      - .gitlab-ci.yml
      - backend/src/**/*
      - frontend/**/*
125
126
127
128
129
130
131
132
133


deploy-to-beta:
  stage: staging
  variables:
    ENV: beta
    APP_PORT: ${BETA_GPDS_PORT}
    CONTEXT_PATH: ${BETA_GPDS_CONTEXT_PATH}
  <<: *deploy_to_vm
134
135
136
  except:
    refs:
      - master
137
138
139
  only:
    refs:
      - branches
140
141
142
143
144
    changes:
      - .gitlab-ci.yml
      - backend/src/**/*
      - frontend/**/*
  when: manual
145
146
147
  allow_failure: false


148
deploy-to-int:
149
150
  stage: production
  variables:
151
152
153
    ENV: int
    APP_PORT: ${INT_GPDS_PORT}
    CONTEXT_PATH: ${INT_GPDS_CONTEXT_PATH}
154
155
156
157
  <<: *deploy_to_vm
  only:
    refs:
      - master
158
159
160
161
    changes:
      - .gitlab-ci.yml
      - backend/src/**/*
      - frontend/**/*
162
163
164
165
  when: manual
  allow_failure: false


166
deploy-to-prod-public:
167
168
  stage: production
  variables:
169
170
171
    ENV: prod-public
    APP_PORT: ${PROD_PUBLIC_GPDS_PORT}
    CONTEXT_PATH: ${PROD_PUBLIC_GPDS_CONTEXT_PATH}
172
173
174
175
  <<: *deploy_to_vm
  only:
    refs:
      - master
176
177
178
179
    changes:
      - .gitlab-ci.yml
      - backend/src/**/*
      - frontend/**/*
180
181
182
183
  when: manual
  allow_failure: false


184
deploy-to-prod-private:
185
  stage: production
186
  variables:
187
188
189
    ENV: prod-private
    APP_PORT: ${PROD_PRIVATE_GPDS_PORT}
    CONTEXT_PATH: ${PROD_PRIVATE_GPDS_CONTEXT_PATH}
190
191
192
193
  <<: *deploy_to_vm
  only:
    refs:
      - master
194
195
196
197
    changes:
      - .gitlab-ci.yml
      - backend/src/**/*
      - frontend/**/*
198
199
  when: manual
  allow_failure: false