.gitlab-ci.yml 6.68 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
16
  except:
    - master
    - tags
17
  script:
Matija Obreza's avatar
Matija Obreza committed
18
    - MAVEN_OPTS="${MAVEN_OPTS} -Dorg.slf4j.simpleLogger.defaultLogLevel=warn" mvn compile test -B
19

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

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

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

Matija Obreza's avatar
Matija Obreza committed
46
47
48

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

Matija Obreza's avatar
Matija Obreza committed
77
78
79
80
81
82
83
84
85
86
87
88
dockerize genesys:
  <<:                     *docker_image
  stage:                  dockerize
  dependencies:
    - package genesys
  only:
    - master
    - tags

dockerize genesys branch:
  <<:                     *docker_image
  stage:                  dockerize
Matija Obreza's avatar
Matija Obreza committed
89
  dependencies:
Matija Obreza's avatar
Matija Obreza committed
90
91
    - package genesys branch
  when:                   manual
Matija Obreza's avatar
Matija Obreza committed
92
  allow_failure:          false
Matija Obreza's avatar
Matija Obreza committed
93
94
95
96
97
98
99
100
101
  except:
    - master
    - tags


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

remove review instance:
Matija Obreza's avatar
Matija Obreza committed
131
132
133
  stage:                  deploy
  image:                  docker:latest
  when:                   manual
Matija Obreza's avatar
Matija Obreza committed
134
  variables:
Matija Obreza's avatar
Matija Obreza committed
135
    GIT_STRATEGY:         none
Matija Obreza's avatar
Matija Obreza committed
136
  environment:
Matija Obreza's avatar
Matija Obreza committed
137
138
    name:                 review/$CI_COMMIT_REF_SLUG
    action:               stop
Matija Obreza's avatar
Matija Obreza committed
139
  script:
140
    - echo Removing review https\://${CI_COMMIT_REF_SLUG}.review.genesys\-pgr.org
Matija Obreza's avatar
Matija Obreza committed
141
142
143
144
145
146
147
148
149
150
151
    # 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
152
    - ${DOCKER_CMD} stack rm genesys-${CI_COMMIT_REF_SLUG}-review
Matija Obreza's avatar
Matija Obreza committed
153
154

deploy on staging server:
Matija Obreza's avatar
Matija Obreza committed
155
156
  stage:                  deploy
  image:                  docker:latest
157
158
  only:
    - master
Matija Obreza's avatar
Matija Obreza committed
159
  variables:
Matija Obreza's avatar
Matija Obreza committed
160
    GIT_STRATEGY:         none
Matija Obreza's avatar
Matija Obreza committed
161
  script:
162
163
164
165
166
167
168
169
170
171
172
173
    - 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
174
    - ${DOCKER_CMD} service update --image ${CI_REGISTRY_IMAGE}:${GENESYS_VERSION} sandbox_server
Matija Obreza's avatar
Matija Obreza committed
175
  environment:
Matija Obreza's avatar
Matija Obreza committed
176
177
    name:                 sandbox
    url:                  https://sandbox.genesys-pgr.org
Matija Obreza's avatar
Matija Obreza committed
178
179

deploy to production:
Matija Obreza's avatar
Matija Obreza committed
180
181
182
  stage:                  deploy
  image:                  docker:latest
  when:                   manual
Matija Obreza's avatar
Matija Obreza committed
183
  variables:
Matija Obreza's avatar
Matija Obreza committed
184
    GIT_STRATEGY:         none
Matija Obreza's avatar
Matija Obreza committed
185
186
  script:
    - echo "Deploy to production server"
187
188
189
190
191
192
193
194
195
196
197
198
199
200
    # 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
    - ${DOCKER_CMD} service update --image ${CI_REGISTRY_IMAGE}:${GENESYS_VERSION} genesys_server
    - sleep 90
    - ${DOCKER_CMD} service update --image ${CI_REGISTRY_IMAGE}:${GENESYS_VERSION} genesys_standby
Matija Obreza's avatar
Matija Obreza committed
201
202
203
  only:
    - master
  environment:
Matija Obreza's avatar
Matija Obreza committed
204
205
    name:                 production
    url:                  https://www.genesys-pgr.org