.gitlab-ci.yml 6.28 KB
Newer Older
Matija Obreza's avatar
Matija Obreza committed
1
2
3
4
include:
  # https://docs.gitlab.com/ce/ci/yaml/README.html#workflowrules-templates
  - template: 'Workflows/Branch-Pipelines.gitlab-ci.yml'

5
variables:
6
  VERSION:                "2021.10"
7
8
9
10
  DOCKER_HOST:            "genesys1.swarm.genesys-pgr.org"
  DOCKER_VERSION:         latest
  # 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.
Matija Obreza's avatar
Matija Obreza committed
11
  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"
12
13
14
  # 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.
15
  # MAVEN_CLI_OPTS: "--batch-mode --errors --fail-at-end --show-version -DinstallAtEnd=true -DdeployAtEnd=true"
Matija Obreza's avatar
Matija Obreza committed
16
  MAVEN_CLI_OPTS: "--batch-mode --errors --show-version"
17
18
19
20
21
22
23
24

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

stages:
25
  - test
26
27
  - package
  - dockerize
28
  - tag
29
  - deploy
30

31

32
run tests:
33
34
  stage:         test
  image:         maven:3-openjdk-11
35
  script:
36
    # First do coverage testing
Matija Obreza's avatar
Matija Obreza committed
37
    - mvn $MAVEN_CLI_OPTS --activate-profiles quality clean verify -U
38
    - cat coverage/target/site/jacoco-aggregate/index.html | grep -o 'Total[^%]*%'
39
  coverage: '/Total.*?([0-9]{1,3})%/'
40
41
42
43
  artifacts:
    name:                 "${CI_PROJECT_NAME}-${CI_COMMIT_REF_NAME}"
    expire_in:            1 day
    paths:
44
      - coverage/target/site/jacoco-aggregate
45
    reports:
46
47
48
49
      junit:
        - commons/target/surefire-reports/TEST-*.xml
        - server/target/surefire-reports/TEST-*.xml
        # - client/target/surefire-reports/TEST-*.xml
50
51

package server:
52
53
54
55
56
57
  stage: package
  image:                  maven:3-openjdk-11
  dependencies:
    - run tests
  script:
    # Then package the clean app
Matija Obreza's avatar
Matija Obreza committed
58
    - mvn $MAVEN_CLI_OPTS -Ppackage clean package
59
60
61
62
  artifacts:
    name:                 "${CI_PROJECT_NAME}-${CI_COMMIT_REF_NAME}"
    expire_in:            1 day
    paths:
63
64
65
66
      # - commons/target/*.jar
      - server/target/*.war
      # - client/target/*.jar
      
67

68
69
70
pages:
  stage: deploy
  dependencies:
Matija Obreza's avatar
Matija Obreza committed
71
    - run tests
72
73
  rules:
    - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
74
75
  script:
   - mkdir public
76
   - mv coverage/target/site/jacoco-aggregate/* public
77
78
79
80
  artifacts:
    expire_in: 1 days
    paths:
      - public
Matija Obreza's avatar
Matija Obreza committed
81

82

Matija Obreza's avatar
Matija Obreza committed
83
.docker_setup: &docker_setup
84
85
86
87
88
89
90
  image:                  docker:${DOCKER_VERSION}
  before_script:
    - 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_CERT_PATH=${TLS_PATH}
91
92
93
94
95
96
97
98
99
    - if [ "${CI_COMMIT_REF_SLUG}" = "${CI_DEFAULT_BRANCH}" ] ; then
        export IMAGE_TAG="${VERSION}-edge";
      else
        if echo "${CI_COMMIT_TAG}" | grep -Eq 'v\d+.*'; then
          export IMAGE_TAG=${CI_COMMIT_TAG:1};
        else
          export IMAGE_TAG="${VERSION}-${CI_COMMIT_REF_SLUG}";
        fi
      fi
100
    - DOCKER_CMD="docker --tlsverify=false"
Matija Obreza's avatar
Matija Obreza committed
101

102

103
dockerize server:
Matija Obreza's avatar
Matija Obreza committed
104
  <<:                     *docker_setup
105
106
107
108
109
110
111
112
113
  stage:                  dockerize
  dependencies:
    - package server
  rules:
    - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
    - if: '$CI_COMMIT_TAG'
    - if: '$CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH'
      when: manual
      allow_failure: true
114
115
  script:
    # Actions
116
    - cd server
Matija Obreza's avatar
Matija Obreza committed
117
    - echo Building docker image ${CI_REGISTRY_IMAGE} on ${DOCKER_HOST}
118
119
    - cp target/*.war docker
    - cd docker
Matija Obreza's avatar
Matija Obreza committed
120
    - "echo Building image: ${CI_REGISTRY_IMAGE}:${IMAGE_TAG}"
121
    - DOCKER_BUILDKIT=1 ${DOCKER_CMD} build --target=jetty --progress=plain -t ${CI_REGISTRY_IMAGE}:${IMAGE_TAG} .
122
123
124
125
    - ${DOCKER_CMD} login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
    - ${DOCKER_CMD} push ${CI_REGISTRY_IMAGE}:${IMAGE_TAG}
    - ${DOCKER_CMD} logout $CI_REGISTRY

Matija Obreza's avatar
Matija Obreza committed
126
tag latest image:
127
  stage:                  tag
Matija Obreza's avatar
Matija Obreza committed
128
  image:                  docker:${DOCKER_VERSION}
Matija Obreza's avatar
Matija Obreza committed
129
130
  dependencies:
    - dockerize server
Matija Obreza's avatar
Matija Obreza committed
131
132
  rules:
    - if: '$CI_COMMIT_TAG =~ /^v\d+.*/'
133
134
      when: manual
      allow_failure: true
135
  <<:                     *docker_setup
Matija Obreza's avatar
Matija Obreza committed
136
  script:
137
    - "echo Tagging: ${CI_REGISTRY_IMAGE}:${IMAGE_TAG} as ${CI_REGISTRY_IMAGE}:latest"
Matija Obreza's avatar
Matija Obreza committed
138
    - ${DOCKER_CMD} login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
139
140
    - ${DOCKER_CMD} pull ${CI_REGISTRY_IMAGE}:${IMAGE_TAG}
    - ${DOCKER_CMD} tag ${CI_REGISTRY_IMAGE}:${IMAGE_TAG} ${CI_REGISTRY_IMAGE}:latest
Matija Obreza's avatar
Matija Obreza committed
141
142
    - ${DOCKER_CMD} push ${CI_REGISTRY_IMAGE}:latest
    - ${DOCKER_CMD} logout $CI_REGISTRY
143
144
145
146

tag edge image:
  stage:                  tag
  image:                  docker:${DOCKER_VERSION}
Matija Obreza's avatar
Matija Obreza committed
147
148
  dependencies:
    - dockerize server
149
150
  rules:
    - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
Matija Obreza's avatar
Matija Obreza committed
151
      when: on_success
152
153
154
      allow_failure: true
  <<:                     *docker_setup
  script:
155
156
    # IMAGE_TAG is VERSION-edge for main branch
    - "echo Tagging: ${CI_REGISTRY_IMAGE}:${IMAGE_TAG} as ${CI_REGISTRY_IMAGE}:edge"
157
    - ${DOCKER_CMD} login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
158
159
    - ${DOCKER_CMD} pull ${CI_REGISTRY_IMAGE}:${IMAGE_TAG}
    - ${DOCKER_CMD} tag ${CI_REGISTRY_IMAGE}:${IMAGE_TAG} ${CI_REGISTRY_IMAGE}:edge
160
161
    - ${DOCKER_CMD} push ${CI_REGISTRY_IMAGE}:edge
    - ${DOCKER_CMD} logout $CI_REGISTRY
162
163
164
165
166
167
168
169
170
171
172


deploy to demo.api.genebanks.org:
  stage:                  deploy
  <<:                     *docker_setup
  variables:
    GIT_STRATEGY:         none
  dependencies:
    - tag edge image
  rules:
    - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
Matija Obreza's avatar
Matija Obreza committed
173
      when: on_success
174
175
176
177
178
179
180
181
182
183
      allow_failure: true
  script:
    # Address the swarm
    - export DOCKER_HOST=swarm.genesys-pgr.org
    # Actions
    - echo "Deploying ${CI_REGISTRY_IMAGE}:edge to https://demo.api.genebanks.org"
    - ${DOCKER_CMD} service update --image ${CI_REGISTRY_IMAGE}:edge ggce-demo_api
  environment:
    name:                 GG-CE API Demo
    url:                  https://demo.api.genebanks.org