.gitlab-ci.yml 5.71 KB
Newer Older
Matija Obreza's avatar
Matija Obreza committed
1
2
3
variables:
  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
12
13
14
15
16
compile and test:
  stage:           compile
  image:           dockerhub.genesys-pgr.org/maven-with-compass:3-jdk-8
  script:
    - MAVEN_OPTS="${MAVEN_OPTS} -Dorg.slf4j.simpleLogger.defaultLogLevel=warn" mvn compile test -B -DskipTests=true

Matija Obreza's avatar
Matija Obreza committed
17
18
19
package genesys:
  stage:           package
  image:           dockerhub.genesys-pgr.org/maven-with-compass:3-jdk-8
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
  dependencies:
    - compile and test
  only:
    - master
    - staging
    - tags
  except:
    - branches
  script:
    - MAVEN_OPTS="${MAVEN_OPTS} -Dorg.slf4j.simpleLogger.defaultLogLevel=warn" mvn package -B -DskipTests=true
  artifacts:
    name:          "${CI_PROJECT_NAME}-${CI_COMMIT_REF_NAME}"
    expire_in:     1 day
    paths:
      - target/*.war


package genesys branch:
  stage:           package
  image:           dockerhub.genesys-pgr.org/maven-with-compass:3-jdk-8
  when:            manual
  dependencies:
    - compile and test
Matija Obreza's avatar
Matija Obreza committed
43
44
  script:
    - MAVEN_OPTS="${MAVEN_OPTS} -Dorg.slf4j.simpleLogger.defaultLogLevel=warn" mvn package -B -DskipTests=true
Matija Obreza's avatar
Matija Obreza committed
45
  artifacts:
Matija Obreza's avatar
Matija Obreza committed
46
47
    name:          "${CI_PROJECT_NAME}-${CI_COMMIT_REF_NAME}"
    expire_in:     1 day
Matija Obreza's avatar
Matija Obreza committed
48
    paths:
Matija Obreza's avatar
Matija Obreza committed
49
50
51
52
53
      - target/*.war

docker image:
  stage:           dockerize
  image:           docker:latest
54
  when:            manual
Matija Obreza's avatar
Matija Obreza committed
55
  dependencies:
56
57
    - compile and test
    - package genesys branch
Matija Obreza's avatar
Matija Obreza committed
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
  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
76
        export IMAGE_TAG="${GENESYS_VERSION}";
Matija Obreza's avatar
Matija Obreza committed
77
      else
78
        export IMAGE_TAG="${GENESYS_VERSION}-${CI_COMMIT_REF_SLUG}";
Matija Obreza's avatar
Matija Obreza committed
79
      fi
80
81
    - "echo The image tag: ${IMAGE_TAG}"
    - ${DOCKER_CMD} build -t ${CI_REGISTRY_IMAGE}:${IMAGE_TAG} .
Matija Obreza's avatar
Matija Obreza committed
82
    - ${DOCKER_CMD} login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
83
    - ${DOCKER_CMD} push ${CI_REGISTRY_IMAGE}:${IMAGE_TAG}
Matija Obreza's avatar
Matija Obreza committed
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
    - ${DOCKER_CMD} logout $CI_REGISTRY

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

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

deploy on staging server:
  stage:           deploy
  image:           docker:latest
  variables:
    GIT_STRATEGY:  none
  script:
149
150
151
152
153
154
155
156
157
158
159
160
161
    - 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
    # - ${DOCKER_CMD} stack rm genesys-${CI_COMMIT_REF_SLUG}-review
Matija Obreza's avatar
Matija Obreza committed
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
  only:
    - staging
  environment:
    name:          sandbox
    url:           https://sandbox.genesys-pgr.org

deploy to production:
  stage:           deploy
  image:           docker:latest
  when:            manual
  variables:
    GIT_STRATEGY:  none
  script:
    - echo "Deploy to production server"
  only:
    - master
  environment:
    name:          production
    url:           https://www.genesys-pgr.org