.gitlab-ci.yml 8.16 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
5 6 7 8 9 10 11 12 13 14 15 16 17
  # This will suppress any download for dependencies and plugins or upload messages which would clutter the console log.
  # `showDateTime` will show the passed time in milliseconds. You need to specify `--batch-mode` to make this work.
  MAVEN_OPTS: "-Dhttps.protocols=TLSv1.2 -Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN -Dorg.slf4j.simpleLogger.showDateTime=true -Djava.awt.headless=true"
  # As of Maven 3.3.0 instead of this you may define these options in `.mvn/maven.config` so the same config is used
  # when running from the command line.
  # `installAtEnd` and `deployAtEnd` are only effective with recent version of the corresponding plugins.
  MAVEN_CLI_OPTS: "--batch-mode --errors --fail-at-end --show-version -DinstallAtEnd=true -DdeployAtEnd=true"

# Cache downloaded dependencies and plugins between builds.
# To keep cache across branches add 'key: "$CI_JOB_NAME"'
cache:
  paths:
    - .m2/repository
Matija Obreza's avatar
Matija Obreza committed
18

Matija Obreza's avatar
Matija Obreza committed
19
stages:
20
  # - compile
Matija Obreza's avatar
Matija Obreza committed
21 22 23
  - package
  - dockerize
  - deploy
Matija Obreza's avatar
Matija Obreza committed
24

25 26 27 28 29 30 31 32 33 34
# 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}"
35
#     - mvn compile test -B -U
36

Matija Obreza's avatar
Matija Obreza committed
37
.package_template:        &maven_package
38
  image:                  dockerhub.croptrust.org/docker/custom/maven-with-compass:latest
39
  script:
40
    - mvn package -B -U
41
  artifacts:
Matija Obreza's avatar
Matija Obreza committed
42 43
    name:                 "${CI_PROJECT_NAME}-${CI_COMMIT_REF_NAME}"
    expire_in:            1 day
44 45 46
    paths:
      - target/*.war

Matija Obreza's avatar
Matija Obreza committed
47 48 49 50 51 52
package genesys:
  <<:                     *maven_package
  stage:                  package
  only:
    - master
    - tags
53 54

package genesys branch:
Matija Obreza's avatar
Matija Obreza committed
55 56
  <<:                     *maven_package
  stage:                  package
57
  # when:                   manual
Matija Obreza's avatar
Matija Obreza committed
58
  allow_failure:          false
Matija Obreza's avatar
Matija Obreza committed
59 60 61
  except:
    - master
    - tags
Matija Obreza's avatar
Matija Obreza committed
62

Matija Obreza's avatar
Matija Obreza committed
63 64

.docker_image_template:   &docker_image
65
  image:                  docker:${DOCKER_VERSION}
Matija Obreza's avatar
Matija Obreza committed
66
  before_script:
67
    # Configuration
Matija Obreza's avatar
Matija Obreza committed
68 69 70 71 72 73 74 75 76
    - 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"
77
  script:
Matija Obreza's avatar
Matija Obreza committed
78 79 80 81
    # Actions
    - cp target/*.war docker
    - cd docker
    - if [ "${CI_COMMIT_REF_SLUG}" = "master" ] ; then
82
        export IMAGE_TAG="${GENESYS_VERSION}";
Matija Obreza's avatar
Matija Obreza committed
83
      else
84
        export IMAGE_TAG="${GENESYS_VERSION}-${CI_COMMIT_REF_SLUG}";
Matija Obreza's avatar
Matija Obreza committed
85
      fi
86 87
    - "echo The image tag: ${IMAGE_TAG}"
    - ${DOCKER_CMD} build -t ${CI_REGISTRY_IMAGE}:${IMAGE_TAG} .
Matija Obreza's avatar
Matija Obreza committed
88
    - ${DOCKER_CMD} login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
89
    - ${DOCKER_CMD} push ${CI_REGISTRY_IMAGE}:${IMAGE_TAG}
Matija Obreza's avatar
Matija Obreza committed
90 91
    - ${DOCKER_CMD} logout $CI_REGISTRY

Matija Obreza's avatar
Matija Obreza committed
92 93 94 95 96 97 98 99 100 101 102 103
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
104
  dependencies:
Matija Obreza's avatar
Matija Obreza committed
105
    - package genesys branch
106
  # when:                 manual
Matija Obreza's avatar
Matija Obreza committed
107
  allow_failure:          false
Matija Obreza's avatar
Matija Obreza committed
108 109 110 111 112
  except:
    - master
    - tags


113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
# 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
148

149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
# 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
175 176

deploy on staging server:
Matija Obreza's avatar
Matija Obreza committed
177
  stage:                  deploy
178
  image:                  docker:${DOCKER_VERSION}
179 180
  only:
    - master
Matija Obreza's avatar
Matija Obreza committed
181
  variables:
Matija Obreza's avatar
Matija Obreza committed
182
    GIT_STRATEGY:         none
Matija Obreza's avatar
Matija Obreza committed
183
  script:
184 185 186 187 188 189 190 191 192 193 194 195
    - 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
196
    - ${DOCKER_CMD} service update --image ${CI_REGISTRY_IMAGE}:${GENESYS_VERSION} sandbox_server
Matija Obreza's avatar
Matija Obreza committed
197
  environment:
Matija Obreza's avatar
Matija Obreza committed
198 199
    name:                 sandbox
    url:                  https://sandbox.genesys-pgr.org
Matija Obreza's avatar
Matija Obreza committed
200 201

deploy to production:
Matija Obreza's avatar
Matija Obreza committed
202 203
  stage:                  deploy
  image:                  docker:latest
204
  only:
205
    - /^production-.*/
Matija Obreza's avatar
Matija Obreza committed
206
  when:                   manual
Matija Obreza's avatar
Matija Obreza committed
207
  variables:
Matija Obreza's avatar
Matija Obreza committed
208
    GIT_STRATEGY:         none
Matija Obreza's avatar
Matija Obreza committed
209 210
  script:
    - echo "Deploy to production server"
211 212 213 214 215 216 217 218 219 220 221
    # 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
222
    - ${DOCKER_CMD} service update --image ${CI_REGISTRY_IMAGE}:${GENESYS_VERSION}-${CI_COMMIT_REF_SLUG} genesys_server
223
    - sleep 180
224
    - ${DOCKER_CMD} service update --image ${CI_REGISTRY_IMAGE}:${GENESYS_VERSION}-${CI_COMMIT_REF_SLUG} genesys_standby
225 226 227 228
    # Restart the server to sync with standby
    - sleep 120
    - docker service scale genesys_server=0
    - docker service scale genesys_server=1
Matija Obreza's avatar
Matija Obreza committed
229
  environment:
Matija Obreza's avatar
Matija Obreza committed
230 231
    name:                 production
    url:                  https://www.genesys-pgr.org