.gitlab-ci.yml 7.02 KB
Newer Older
Matija Obreza's avatar
Matija Obreza committed
1
variables:
Matija Obreza's avatar
Matija Obreza committed
2
  GENESYS_VERSION:        "2.0"
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
    - MAVEN_OPTS="${MAVEN_OPTS} -Dorg.slf4j.simpleLogger.defaultLogLevel=warn" mvn compile test -B
21

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

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

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

Matija Obreza's avatar
Matija Obreza committed
50
51

.docker_image_template:   &docker_image
52
  image:                  docker:${DOCKER_VERSION}
Matija Obreza's avatar
Matija Obreza committed
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
  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
71
        export IMAGE_TAG="${GENESYS_VERSION}";
Matija Obreza's avatar
Matija Obreza committed
72
      else
73
        export IMAGE_TAG="${GENESYS_VERSION}-${CI_COMMIT_REF_SLUG}";
Matija Obreza's avatar
Matija Obreza committed
74
      fi
75
76
    - "echo The image tag: ${IMAGE_TAG}"
    - ${DOCKER_CMD} build -t ${CI_REGISTRY_IMAGE}:${IMAGE_TAG} .
Matija Obreza's avatar
Matija Obreza committed
77
    - ${DOCKER_CMD} login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
78
    - ${DOCKER_CMD} push ${CI_REGISTRY_IMAGE}:${IMAGE_TAG}
Matija Obreza's avatar
Matija Obreza committed
79
80
    - ${DOCKER_CMD} logout $CI_REGISTRY

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

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


deploy for review:
  stage:                  deploy
106
  image:                  docker:${DOCKER_VERSION}
107
108
109
  except:
    - master
    - production
110
  # when:                 manual
Matija Obreza's avatar
Matija Obreza committed
111
  allow_failure:          false
Matija Obreza's avatar
Matija Obreza committed
112
  environment:
Matija Obreza's avatar
Matija Obreza committed
113
114
115
    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
116
117
118
119
120
121
122
123
124
125
126
127
128
  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
129
    - if [ "${CI_COMMIT_REF_SLUG}" = "master" ] ; then
130
        export IMAGE_TAG="${GENESYS_VERSION}";
131
      else
132
        export IMAGE_TAG="${GENESYS_VERSION}-${CI_COMMIT_REF_SLUG}";
133
      fi
134
    - 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
135
136
    - envsubst < docker/review-compose-template.yml > review-composed.yml
    - cat review-composed.yml
137
    - ${DOCKER_CMD} stack rm genesys-${CI_COMMIT_REF_SLUG}-review || true
138
    - ${DOCKER_CMD} stack deploy -c review-composed.yml genesys-${CI_COMMIT_REF_SLUG}-review
Matija Obreza's avatar
Matija Obreza committed
139
140

remove review instance:
Matija Obreza's avatar
Matija Obreza committed
141
  stage:                  deploy
142
  image:                  docker:${DOCKER_VERSION}
143
144
145
  except:
    - master
    - production
Matija Obreza's avatar
Matija Obreza committed
146
  when:                   manual
Matija Obreza's avatar
Matija Obreza committed
147
  variables:
Matija Obreza's avatar
Matija Obreza committed
148
    GIT_STRATEGY:         none
Matija Obreza's avatar
Matija Obreza committed
149
  environment:
Matija Obreza's avatar
Matija Obreza committed
150
151
    name:                 review/$CI_COMMIT_REF_SLUG
    action:               stop
Matija Obreza's avatar
Matija Obreza committed
152
  script:
153
    - echo Removing review https\://${CI_COMMIT_REF_SLUG}.review.genesys\-pgr.org
Matija Obreza's avatar
Matija Obreza committed
154
155
156
157
158
159
160
161
162
163
164
    # 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
165
    - ${DOCKER_CMD} stack rm genesys-${CI_COMMIT_REF_SLUG}-review || true
Matija Obreza's avatar
Matija Obreza committed
166
167

deploy on staging server:
Matija Obreza's avatar
Matija Obreza committed
168
  stage:                  deploy
169
  image:                  docker:${DOCKER_VERSION}
170
171
  only:
    - master
Matija Obreza's avatar
Matija Obreza committed
172
  variables:
Matija Obreza's avatar
Matija Obreza committed
173
    GIT_STRATEGY:         none
Matija Obreza's avatar
Matija Obreza committed
174
  script:
175
176
177
178
179
180
181
182
183
184
185
186
    - 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
187
    - ${DOCKER_CMD} service update --image ${CI_REGISTRY_IMAGE}:${GENESYS_VERSION} sandbox_server
Matija Obreza's avatar
Matija Obreza committed
188
  environment:
Matija Obreza's avatar
Matija Obreza committed
189
190
    name:                 sandbox
    url:                  https://sandbox.genesys-pgr.org
Matija Obreza's avatar
Matija Obreza committed
191
192

deploy to production:
Matija Obreza's avatar
Matija Obreza committed
193
194
  stage:                  deploy
  image:                  docker:latest
195
196
  only:
    - production
Matija Obreza's avatar
Matija Obreza committed
197
  when:                   manual
Matija Obreza's avatar
Matija Obreza committed
198
  variables:
Matija Obreza's avatar
Matija Obreza committed
199
    GIT_STRATEGY:         none
Matija Obreza's avatar
Matija Obreza committed
200
201
  script:
    - echo "Deploy to production server"
202
203
204
205
206
207
208
209
210
211
212
    # 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
213
    - ${DOCKER_CMD} service update --image ${CI_REGISTRY_IMAGE}:${GENESYS_VERSION}-production genesys_server
214
    - sleep 180
215
    - ${DOCKER_CMD} service update --image ${CI_REGISTRY_IMAGE}:${GENESYS_VERSION}-production genesys_standby
Matija Obreza's avatar
Matija Obreza committed
216
  environment:
Matija Obreza's avatar
Matija Obreza committed
217
218
    name:                 production
    url:                  https://www.genesys-pgr.org