.gitlab-ci.yml 7.14 KB
Newer Older
Matija Obreza's avatar
Matija Obreza committed
1
variables:
Matija Obreza's avatar
Matija Obreza committed
2
  GENESYS_VERSION:        "2.1"
3
4
  DOCKER_HOST:            genesys1.swarm.genesys-pgr.org
  DOCKER_VERSION:         latest
Matija Obreza's avatar
Matija Obreza committed
5

Matija Obreza's avatar
Matija Obreza committed
6
stages:
7
  - compile
Matija Obreza's avatar
Matija Obreza committed
8
9
10
  - package
  - dockerize
  - deploy
Matija Obreza's avatar
Matija Obreza committed
11

12
compile and test:
Matija Obreza's avatar
Matija Obreza committed
13
  stage:                  compile
14
  image:                  dockerhub.croptrust.org/docker/custom/maven-with-compass:latest
Matija Obreza's avatar
Matija Obreza committed
15
16
  except:
    - master
17
    - production
Matija Obreza's avatar
Matija Obreza committed
18
    - tags
19
  script:
Matija Obreza's avatar
Matija Obreza committed
20
21
    - echo "CI_COMMIT_REF_SLUG  ${CI_COMMIT_REF_SLUG}"
    - echo "CI_ENVIRONMENT_SLUG ${CI_ENVIRONMENT_SLUG}"
22
    - MAVEN_OPTS="${MAVEN_OPTS} -Dorg.slf4j.simpleLogger.defaultLogLevel=warn" mvn compile test -B -U
23

Matija Obreza's avatar
Matija Obreza committed
24
.package_template:        &maven_package
25
  image:                  dockerhub.croptrust.org/docker/custom/maven-with-compass:latest
26
  script:
27
    - MAVEN_OPTS="${MAVEN_OPTS} -Dorg.slf4j.simpleLogger.defaultLogLevel=warn" mvn package -B -U
28
  artifacts:
Matija Obreza's avatar
Matija Obreza committed
29
30
    name:                 "${CI_PROJECT_NAME}-${CI_COMMIT_REF_NAME}"
    expire_in:            1 day
31
32
33
    paths:
      - target/*.war

Matija Obreza's avatar
Matija Obreza committed
34
35
36
37
38
package genesys:
  <<:                     *maven_package
  stage:                  package
  only:
    - master
39
    - production
Matija Obreza's avatar
Matija Obreza committed
40
    - tags
41
42

package genesys branch:
Matija Obreza's avatar
Matija Obreza committed
43
44
45
  <<:                     *maven_package
  stage:                  package
  when:                   manual
Matija Obreza's avatar
Matija Obreza committed
46
  allow_failure:          false
Matija Obreza's avatar
Matija Obreza committed
47
48
  except:
    - master
49
    - production
Matija Obreza's avatar
Matija Obreza committed
50
    - tags
Matija Obreza's avatar
Matija Obreza committed
51

Matija Obreza's avatar
Matija Obreza committed
52
53

.docker_image_template:   &docker_image
54
  image:                  docker:${DOCKER_VERSION}
Matija Obreza's avatar
Matija Obreza committed
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
  before_script:
    - echo Building docker image ${CI_REGISTRY_IMAGE} on ${DOCKER_HOST}
    - echo Registry ${CI_REGISTRY} user=${CI_REGISTRY_USER} ${CI_REGISTRY_PASSWORD}
  script:
    # Configuration
    - TLS_PATH=~/.docker/${DOCKER_HOST}/certs && mkdir -p ${TLS_PATH}
    - echo "${DOCKER_TLS_CA}" > ${TLS_PATH}/ca.pem
    - echo "${DOCKER_TLS_KEY}" > ${TLS_PATH}/key.pem
    - echo "${DOCKER_TLS_CERT}" > ${TLS_PATH}/cert.pem
    - export DOCKER_TLS_VERIFY=1
    - export DOCKER_CERT_PATH=${TLS_PATH}
    - DOCKER_CMD="docker --tlsverify=false"
#    - ls -la ${DOCKER_CERT_PATH}
#    - set | grep DOCKER
    # Actions
    - cp target/*.war docker
    - cd docker
    - if [ "${CI_COMMIT_REF_SLUG}" = "master" ] ; then
73
        export IMAGE_TAG="${GENESYS_VERSION}";
Matija Obreza's avatar
Matija Obreza committed
74
      else
75
        export IMAGE_TAG="${GENESYS_VERSION}-${CI_COMMIT_REF_SLUG}";
Matija Obreza's avatar
Matija Obreza committed
76
      fi
77
78
    - "echo The image tag: ${IMAGE_TAG}"
    - ${DOCKER_CMD} build -t ${CI_REGISTRY_IMAGE}:${IMAGE_TAG} .
Matija Obreza's avatar
Matija Obreza committed
79
    - ${DOCKER_CMD} login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
80
    - ${DOCKER_CMD} push ${CI_REGISTRY_IMAGE}:${IMAGE_TAG}
Matija Obreza's avatar
Matija Obreza committed
81
82
    - ${DOCKER_CMD} logout $CI_REGISTRY

Matija Obreza's avatar
Matija Obreza committed
83
84
85
86
87
88
89
dockerize genesys:
  <<:                     *docker_image
  stage:                  dockerize
  dependencies:
    - package genesys
  only:
    - master
90
    - production
Matija Obreza's avatar
Matija Obreza committed
91
92
93
94
95
    - tags

dockerize genesys branch:
  <<:                     *docker_image
  stage:                  dockerize
Matija Obreza's avatar
Matija Obreza committed
96
  dependencies:
Matija Obreza's avatar
Matija Obreza committed
97
    - package genesys branch
98
  # when:                 manual
Matija Obreza's avatar
Matija Obreza committed
99
  allow_failure:          false
Matija Obreza's avatar
Matija Obreza committed
100
101
  except:
    - master
102
    - production
Matija Obreza's avatar
Matija Obreza committed
103
104
105
106
107
    - tags


deploy for review:
  stage:                  deploy
108
  image:                  docker:${DOCKER_VERSION}
109
110
111
  except:
    - master
    - production
112
  # when:                 manual
Matija Obreza's avatar
Matija Obreza committed
113
  allow_failure:          false
Matija Obreza's avatar
Matija Obreza committed
114
  environment:
Matija Obreza's avatar
Matija Obreza committed
115
116
117
    name:                 review/$CI_COMMIT_REF_SLUG
    url:                  https://${CI_COMMIT_REF_SLUG}.review.genesys-pgr.org
    on_stop:              remove review instance
Matija Obreza's avatar
Matija Obreza committed
118
119
120
121
122
123
124
125
126
127
128
129
130
  script:
    # Address the swarm
    - export DOCKER_HOST=swarm.genesys-pgr.org
    # Configuration
    - TLS_PATH=~/.docker/${DOCKER_HOST}/certs && mkdir -p ${TLS_PATH}
    - echo "${DOCKER_TLS_CA}" > ${TLS_PATH}/ca.pem
    - echo "${DOCKER_TLS_KEY}" > ${TLS_PATH}/key.pem
    - echo "${DOCKER_TLS_CERT}" > ${TLS_PATH}/cert.pem
    - export DOCKER_TLS_VERIFY=1
    - export DOCKER_CERT_PATH=${TLS_PATH}
    - DOCKER_CMD=docker
    # Actions
    - apk add --no-cache gettext
131
    - if [ "${CI_COMMIT_REF_SLUG}" = "master" ] ; then
132
        export IMAGE_TAG="${GENESYS_VERSION}";
133
      else
134
        export IMAGE_TAG="${GENESYS_VERSION}-${CI_COMMIT_REF_SLUG}";
135
      fi
136
    - echo Deploying ${CI_REGISTRY_IMAGE}:${IMAGE_TAG} for review as https\://${CI_COMMIT_REF_SLUG}.review.genesys\-pgr.org
Matija Obreza's avatar
Matija Obreza committed
137
138
    - envsubst < docker/review-compose-template.yml > review-composed.yml
    - cat review-composed.yml
139
    - ${DOCKER_CMD} stack rm genesys-${CI_COMMIT_REF_SLUG}-review || true
140
    - ${DOCKER_CMD} stack deploy -c review-composed.yml genesys-${CI_COMMIT_REF_SLUG}-review
Matija Obreza's avatar
Matija Obreza committed
141
142

remove review instance:
Matija Obreza's avatar
Matija Obreza committed
143
  stage:                  deploy
144
  image:                  docker:${DOCKER_VERSION}
145
146
147
  except:
    - master
    - production
Matija Obreza's avatar
Matija Obreza committed
148
  when:                   manual
Matija Obreza's avatar
Matija Obreza committed
149
  variables:
Matija Obreza's avatar
Matija Obreza committed
150
    GIT_STRATEGY:         none
Matija Obreza's avatar
Matija Obreza committed
151
  environment:
Matija Obreza's avatar
Matija Obreza committed
152
153
    name:                 review/$CI_COMMIT_REF_SLUG
    action:               stop
Matija Obreza's avatar
Matija Obreza committed
154
  script:
155
    - echo Removing review https\://${CI_COMMIT_REF_SLUG}.review.genesys\-pgr.org
Matija Obreza's avatar
Matija Obreza committed
156
157
158
159
160
161
162
163
164
165
166
    # Address the swarm
    - export DOCKER_HOST=swarm.genesys-pgr.org
    # Configuration
    - TLS_PATH=~/.docker/${DOCKER_HOST}/certs && mkdir -p ${TLS_PATH}
    - echo "${DOCKER_TLS_CA}" > ${TLS_PATH}/ca.pem
    - echo "${DOCKER_TLS_KEY}" > ${TLS_PATH}/key.pem
    - echo "${DOCKER_TLS_CERT}" > ${TLS_PATH}/cert.pem
    - export DOCKER_TLS_VERIFY=1
    - export DOCKER_CERT_PATH=${TLS_PATH}
    - DOCKER_CMD=docker
    # Actions
167
    - ${DOCKER_CMD} stack rm genesys-${CI_COMMIT_REF_SLUG}-review || true
Matija Obreza's avatar
Matija Obreza committed
168
169

deploy on staging server:
Matija Obreza's avatar
Matija Obreza committed
170
  stage:                  deploy
171
  image:                  docker:${DOCKER_VERSION}
172
173
  only:
    - master
Matija Obreza's avatar
Matija Obreza committed
174
  variables:
Matija Obreza's avatar
Matija Obreza committed
175
    GIT_STRATEGY:         none
Matija Obreza's avatar
Matija Obreza committed
176
  script:
177
178
179
180
181
182
183
184
185
186
187
188
    - echo Deploying to staging server
    # Address the swarm
    - export DOCKER_HOST=swarm.genesys-pgr.org
    # Configuration
    - TLS_PATH=~/.docker/${DOCKER_HOST}/certs && mkdir -p ${TLS_PATH}
    - echo "${DOCKER_TLS_CA}" > ${TLS_PATH}/ca.pem
    - echo "${DOCKER_TLS_KEY}" > ${TLS_PATH}/key.pem
    - echo "${DOCKER_TLS_CERT}" > ${TLS_PATH}/cert.pem
    - export DOCKER_TLS_VERIFY=1
    - export DOCKER_CERT_PATH=${TLS_PATH}
    - DOCKER_CMD=docker
    # Actions
189
    - ${DOCKER_CMD} service update --image ${CI_REGISTRY_IMAGE}:${GENESYS_VERSION} sandbox_server
Matija Obreza's avatar
Matija Obreza committed
190
  environment:
Matija Obreza's avatar
Matija Obreza committed
191
192
    name:                 sandbox
    url:                  https://sandbox.genesys-pgr.org
Matija Obreza's avatar
Matija Obreza committed
193
194

deploy to production:
Matija Obreza's avatar
Matija Obreza committed
195
196
  stage:                  deploy
  image:                  docker:latest
197
198
  only:
    - production
Matija Obreza's avatar
Matija Obreza committed
199
  when:                   manual
Matija Obreza's avatar
Matija Obreza committed
200
  variables:
Matija Obreza's avatar
Matija Obreza committed
201
    GIT_STRATEGY:         none
Matija Obreza's avatar
Matija Obreza committed
202
203
  script:
    - echo "Deploy to production server"
204
205
206
207
208
209
210
211
212
213
214
    # Address the swarm
    - export DOCKER_HOST=swarm.genesys-pgr.org
    # Configuration
    - TLS_PATH=~/.docker/${DOCKER_HOST}/certs && mkdir -p ${TLS_PATH}
    - echo "${DOCKER_TLS_CA}" > ${TLS_PATH}/ca.pem
    - echo "${DOCKER_TLS_KEY}" > ${TLS_PATH}/key.pem
    - echo "${DOCKER_TLS_CERT}" > ${TLS_PATH}/cert.pem
    - export DOCKER_TLS_VERIFY=1
    - export DOCKER_CERT_PATH=${TLS_PATH}
    - DOCKER_CMD=docker
    # Actions
215
    - ${DOCKER_CMD} service update --image ${CI_REGISTRY_IMAGE}:${GENESYS_VERSION}-production genesys_server
216
    - sleep 180
217
    - ${DOCKER_CMD} service update --image ${CI_REGISTRY_IMAGE}:${GENESYS_VERSION}-production genesys_standby
Matija Obreza's avatar
Matija Obreza committed
218
  environment:
Matija Obreza's avatar
Matija Obreza committed
219
220
    name:                 production
    url:                  https://www.genesys-pgr.org