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

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

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

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

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

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

Matija Obreza's avatar
Matija Obreza committed
49
50
51

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

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

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


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

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

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

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