Newer
Older
#
# This file is a part of the CaosDB Project.
#
# Copyright (C) 2018 Research Group Biomedical Physics,
# Max-Planck-Institute for Dynamics and Self-Organization Göttingen
# Copyright (C) 2019 Henrik tom Wörden
# Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# this is the image where cpplib repo is present (artifact from pipeline in
# caosdb-cpplib)
CI_CPPLIB_TESTENV_IMAGE_TAG: $CI_REGISTRY/caosdb/src/caosdb-cpplib/testenv:$CI_COMMIT_REF_NAME
CI_REGISTRY_IMAGE_CPPLIB: $CI_CPPLIB_TESTENV_IMAGE_TAG
# this is the image where all the docker containers (server, mysql and test
# suite) are started
CI_REGISTRY_IMAGE_BASE: $CI_REGISTRY/caosdb/src/caosdb-pyinttest/base:latest
CPPINTTEST_TESTENV_IMAGE_SUFFIX: $CI_COMMIT_REF_NAME
CPPINTTEST_REPO_PATH: caosdb/src/caosdb-cppinttest
CPPINTTEST_TESTENV_IMAGE_TAG: $CPPINTTEST_REPO_PATH/testenv:$CPPINTTEST_IMAGE_SUFFIX
# this is the image where the cpplib is installed and where the testsuite runs
CPPINTTEST_REGISTRY_IMAGE: $CI_REGISTRY/$CPPINTTEST_TESTENV_IMAGE_TAG
# this is the name of the image in the /image-cache/ directory
TRIGGERED_BY_REF: $CI_COMMIT_REF_NAME
TRIGGERED_BY_HASH: $CI_COMMIT_SHORT_SHA
# This is the caosdb-deploy branch which build the images for caosdb-server and caosdb-mysql
# TODO change to dev after merge of f-grpc to dev
DEPLOY_REF: f-grpc
timeout: 1 minutes
needs: []
script:
- echo "Pipeline triggered by $TRIGGERED_BY_REPO@$TRIGGERED_BY_REF ($TRIGGERED_BY_HASH)"
- echo "$CPPLIB_TESTENV_IMAGE_TAG"
- echo "$CI_REGISTRY_IMAGE_CPPLIB"
- echo "$CI_REGISTRY_IMAGE_BASE"
- echo "$CPPINTTEST_TESTENV_IMAGE_SUFFIX"
- echo "$CPPINTTEST_REPO_PATH"
- echo "$CPPINTTEST_TESTENV_IMAGE_TAG"
- echo "$CPPINTTEST_REGISTRY_IMAGE"
- echo "$CPPINTTEST_IMAGE_CACHE"
# Build a docker image in which tests for this repository can run
build-testenv:
tags: [cached-dind]
image: docker:20.10.6
stage: setup
timeout: 2h
needs: []
script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
## Determine the cppinttest branch...
# ... use an f-branch if posible...
- if echo "$CI_COMMIT_REF_NAME" | grep -c "^f-" ; then
CPPINT_REF=$CI_COMMIT_REF_NAME ;
# ... or use main if possible...
- if [[ "$CI_COMMIT_REF_NAME" == "main" ]] ; then
CPPINT_REF=main ;
fi
# ... and fall-back to dev
- CPPINT_REF=${CPPINT_REF:-dev}
#build testenv image
- docker pull $CI_REGISTRY_IMAGE_CPPLIB || true # remove??? docker build --pull???
--cache-from $CPPINTTEST_REGISTRY_IMAGE
--tag $CPPINTTEST_REGISTRY_IMAGE .
- docker push $CPPINTTEST_REGISTRY_IMAGE
- docker save $CPPINTTEST_REGISTRY_IMAGE > /image-cache/${CPPINTTEST_IMAGE_CACHE}
# build integration tests
build-test:
image: $CPPINTTEST_REGISTRY_IMAGE
- cmake -D CMAKE_PREFIX_PATH=/usr/local/lib/libcaosdb-${CPPLIB_VERSION} ..
- build/
expire_in: 1 week
test:
tags: [docker]
services:
- docker:20.10.3-dind
variables:
# This is a workaround for the gitlab-runner health check mechanism when
# using docker-dind service. The runner will otherwise guess the port
# wrong and the health check will timeout.
SERVICE_PORT_2376_TCP_PORT: 2375
stage: test
image: $CI_REGISTRY_IMAGE_BASE
needs:
- job: build-test
artifacts: true
script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- if [[ "$CAOSDB_TAG" == "" ]]; then
if echo "$F_BRANCH" | grep -c "^f-" ; then
CAOSDB_TAG=${DEPLOY_REF}_F_${F_BRANCH}-latest;
if ! docker pull $CI_REGISTRY/caosdb/src/caosdb-deploy:$CAOSDB_TAG ; then
echo "Load deploy images with tag $CAOSDB_TAG ... error. Try another:" ;
docker pull $CI_REGISTRY/caosdb/src/caosdb-deploy:$CAOSDB_TAG ;
echo "Load deploy images with tag $CAOSDB_TAG ... success"
docker pull $CI_REGISTRY/caosdb/src/caosdb-deploy:$CAOSDB_TAG ;
echo "Load deploy images with tag $CAOSDB_TAG ... success"
docker pull $CI_REGISTRY/caosdb/src/caosdb-deploy:$CAOSDB_TAG ;
echo "Load deploy images with tag $CAOSDB_TAG ... success"
fi
- docker load < /image-cache/${CPPINTTEST_IMAGE_CACHE} || true
- docker pull $CPPINTTEST_REGISTRY_IMAGE
- docker load < /image-cache/mariadb.tar || true
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
- cd .docker
# here the server and the mysql backend docker are being started
- CAOSDB_TAG=$CAOSDB_TAG docker-compose up -d
# the pyinttest docker writes the return value of the tests into the
# file result
- /bin/sh ./run.sh
# collect log files
- cd ..
- docker logs docker_caosdb-server_1 &> ../caosdb_log.txt
- docker logs docker_sqldb_1 &> ../mariadb_log.txt
# shut down
- docker-compose -f .docker/docker-compose.yml down
# collect results
- rc=`cat .docker/result`
# renew mariadb image in the cache (why? to renew the timestamp???)
- echo mariadb:$(docker image ls mariadb | grep mariadb | awk '{print $2}')
- docker save mariadb:$(docker image ls mariadb | grep mariadb | awk '{print $2}') > /image-cache/mariadb.tar || true
# exit with fail when errors exist
- exit $rc
timeout: 3h
artifacts:
paths:
- caosdb_log.txt
- mariadb_log.txt
- .docker/hash_*
expire_in: 1 week