.gitlab-ci.yml 7.08 KB
Newer Older
Matija Obreza's avatar
Matija Obreza committed
1
variables:
Matija Obreza's avatar
Matija Obreza committed
2
  GENESYS_VERSION:        "2.3"
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 13 14 15 16 17 18 19 20 21 22
# compile and test:
#   stage:                  compile
#   image:                  dockerhub.croptrust.org/docker/custom/maven-with-compass:latest
#   except:
#     - master
#     - production
#     - tags
#   script:
#     - echo "CI_COMMIT_REF_SLUG  ${CI_COMMIT_REF_SLUG}"
#     - echo "CI_ENVIRONMENT_SLUG ${CI_ENVIRONMENT_SLUG}"
#     - 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
  <<:                     *maven_package
  stage:                  package
45
  # 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
  before_script:
56
    # Configuration
Matija Obreza's avatar
Matija Obreza committed
57 58 59 60 61 62 63 64 65
    - echo Building docker image ${CI_REGISTRY_IMAGE} on ${DOCKER_HOST}
    - echo Registry ${CI_REGISTRY} user=${CI_REGISTRY_USER} ${CI_REGISTRY_PASSWORD}
    - 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"
66
  script:
Matija Obreza's avatar
Matija Obreza committed
67 68 69 70
    # 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:
113 114
    name:                 genesys/${CI_COMMIT_REF_SLUG}
    url:                  https://${CI_ENVIRONMENT_SLUG}.review.genesys-pgr.org
Matija Obreza's avatar
Matija Obreza committed
115
    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_ENVIRONMENT_SLUG}.review.genesys\-pgr.org
Matija Obreza's avatar
Matija Obreza committed
135
    - envsubst < docker/review-compose-template.yml > review-composed.yml
136
    # - cat review-composed.yml
137 138
    - ${DOCKER_CMD} stack rm ${CI_ENVIRONMENT_SLUG} || true
    - ${DOCKER_CMD} stack deploy -c review-composed.yml ${CI_ENVIRONMENT_SLUG}
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:
150
    name:                 genesys/${CI_COMMIT_REF_SLUG}
Matija Obreza's avatar
Matija Obreza committed
151
    action:               stop
Matija Obreza's avatar
Matija Obreza committed
152
  script:
153
    - echo Removing review https\://${CI_ENVIRONMENT_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 ${CI_ENVIRONMENT_SLUG} || 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