.gitlab-ci.yml 3.72 KB
Newer Older
1
variables:
2
  PRODUCT_VERSION:        "1.1"
3
4
5
6
7
8
9
10
11
12
13
  DOCKER_HOST:            "genesys1.swarm.genesys-pgr.org"

stages:
  - compile
  - dockerize
  - deploy

run tests in branches:
  stage:                  compile
  image:                  maven:3-jdk-8
  script:
14
    - MAVEN_OPTS="${MAVEN_OPTS} -Dorg.slf4j.simpleLogger.defaultLogLevel=warn" mvn test -B -U
15
16
  except:
    - master
Matija Obreza's avatar
Matija Obreza committed
17
    - /^validator\-web\-/
18
19
20
21
22

build:
  stage:                  compile
  image:                  maven:3-jdk-8
  script:
23
    - MAVEN_OPTS="${MAVEN_OPTS} -Dorg.slf4j.simpleLogger.defaultLogLevel=warn" mvn package -B -U
24
25
  only:
    - master
Matija Obreza's avatar
Matija Obreza committed
26
    - /^validator\-web\-/
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
  artifacts:
    name:                 "${CI_PROJECT_NAME}-${CI_COMMIT_REF_NAME}"
    expire_in:            1 day
    paths:
      - target/validator-web*.war


.docker_image_template:   &docker_image
  image:                  docker:latest
  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"
    # Actions
    - cp target/*.war docker
    - cd docker
Matija Obreza's avatar
Matija Obreza committed
51
    - ${DOCKER_CMD} build -t ${CI_REGISTRY_IMAGE}:${PRODUCT_VERSION}-${CI_COMMIT_REF_SLUG} .
52
    - ${DOCKER_CMD} login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
Matija Obreza's avatar
Matija Obreza committed
53
    - ${DOCKER_CMD} push ${CI_REGISTRY_IMAGE}:${PRODUCT_VERSION}-${CI_COMMIT_REF_SLUG}
54
55
56
57
58
59
60
61
62
    - ${DOCKER_CMD} logout $CI_REGISTRY

dockerize web app:
  <<:                     *docker_image
  stage:                  dockerize
  dependencies:
    - build
  only:
    - master
Matija Obreza's avatar
Matija Obreza committed
63
    - /^validator\-web\-/
64

Matija Obreza's avatar
Matija Obreza committed
65
deploy on sandbox:
66
67
68
69
  stage:                  deploy
  image:                  docker:latest
  only:
    - master
Matija Obreza's avatar
Matija Obreza committed
70
    - /^validator\-web\-/
71
72
  variables:
    GIT_STRATEGY:         none
Matija Obreza's avatar
Matija Obreza committed
73
74
75
76
77
78
79
80
81
82
83
  before_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
84
85
  script:
    - echo Deploying to server
Matija Obreza's avatar
Matija Obreza committed
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
    # Actions
    - ${DOCKER_CMD} service update --image ${CI_REGISTRY_IMAGE}:${PRODUCT_VERSION}-${CI_COMMIT_REF_SLUG} validator_sandbox
  environment:
    name:                 sandbox
    url:                  https://sandbox.genesys-pgr.org/validator/


deploy on production:
  stage:                  deploy
  image:                  docker:latest
  only:
    - /^validator\-web\-/
  when:                   manual
  variables:
    GIT_STRATEGY:         none
  before_script:
102
103
104
105
106
107
108
109
110
111
    # 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
Matija Obreza's avatar
Matija Obreza committed
112
113
  script:
    - echo Deploying to production
114
    # Actions
Matija Obreza's avatar
Matija Obreza committed
115
    - ${DOCKER_CMD} service update --image ${CI_REGISTRY_IMAGE}:${PRODUCT_VERSION}-${CI_COMMIT_REF_SLUG} validator_production
116
  environment:
Matija Obreza's avatar
Matija Obreza committed
117
    name:                 production
118
    url:                  https://validator.genesys-pgr.org/