.gitlab-ci.yml 7.17 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 39
package genesys:
  <<:                     *maven_package
  stage:                  package
  only:
    - master
    - tags
40 41

package genesys branch:
Matija Obreza's avatar
Matija Obreza committed
42 43
  <<:                     *maven_package
  stage:                  package
44
  # when:                   manual
Matija Obreza's avatar
Matija Obreza committed
45
  allow_failure:          false
Matija Obreza's avatar
Matija Obreza committed
46 47 48
  except:
    - master
    - 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
  before_script:
54
    # Configuration
Matija Obreza's avatar
Matija Obreza committed
55 56 57 58 59 60 61 62 63
    - 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"
64
  script:
Matija Obreza's avatar
Matija Obreza committed
65 66 67 68
    # Actions
    - cp target/*.war docker
    - cd docker
    - if [ "${CI_COMMIT_REF_SLUG}" = "master" ] ; then
69
        export IMAGE_TAG="${GENESYS_VERSION}";
Matija Obreza's avatar
Matija Obreza committed
70
      else
71
        export IMAGE_TAG="${GENESYS_VERSION}-${CI_COMMIT_REF_SLUG}";
Matija Obreza's avatar
Matija Obreza committed
72
      fi
73 74
    - "echo The image tag: ${IMAGE_TAG}"
    - ${DOCKER_CMD} build -t ${CI_REGISTRY_IMAGE}:${IMAGE_TAG} .
Matija Obreza's avatar
Matija Obreza committed
75
    - ${DOCKER_CMD} login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
76
    - ${DOCKER_CMD} push ${CI_REGISTRY_IMAGE}:${IMAGE_TAG}
Matija Obreza's avatar
Matija Obreza committed
77 78
    - ${DOCKER_CMD} logout $CI_REGISTRY

Matija Obreza's avatar
Matija Obreza committed
79 80 81 82 83 84 85 86 87 88 89 90
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
91
  dependencies:
Matija Obreza's avatar
Matija Obreza committed
92
    - package genesys branch
93
  # when:                 manual
Matija Obreza's avatar
Matija Obreza committed
94
  allow_failure:          false
Matija Obreza's avatar
Matija Obreza committed
95 96 97 98 99
  except:
    - master
    - tags


100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
# deploy for review:
#   stage:                  deploy
#   image:                  docker:${DOCKER_VERSION}
#   except:
#     - master
#     - /^production-.*/
#   # when:                 manual
#   allow_failure:          false
#   environment:
#     name:                 genesys/${CI_COMMIT_REF_SLUG}
#     url:                  https://${CI_ENVIRONMENT_SLUG}.review.genesys-pgr.org
#     on_stop:              remove review instance
#   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
#     - if [ "${CI_COMMIT_REF_SLUG}" = "master" ] ; then
#         export IMAGE_TAG="${GENESYS_VERSION}";
#       else
#         export IMAGE_TAG="${GENESYS_VERSION}-${CI_COMMIT_REF_SLUG}";
#       fi
#     - echo Deploying ${CI_REGISTRY_IMAGE}:${IMAGE_TAG} for review as https\://${CI_ENVIRONMENT_SLUG}.review.genesys\-pgr.org
#     - envsubst < docker/review-compose-template.yml > review-composed.yml
#     # - cat review-composed.yml
#     - ${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
135

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

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

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