Skip to content
Snippets Groups Projects
.gitlab-ci.yml 4.39 KiB
Newer Older
Henrik tom Woerden's avatar
Henrik tom Woerden committed
#
# 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) 2020 Indiscale GmbH <info@indiscale.com>
# Copyright (C) 2020 Daniel Hornung <d.hornung@indiscale.com>
Henrik tom Woerden's avatar
Henrik tom Woerden committed
#
# 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/>.

variables:
   CI_REGISTRY_IMAGE: $CI_REGISTRY/caosdb/src/caosdb-advanced-user-tools/testenv:latest
   CI_REGISTRY_IMAGE_BASE: $CI_REGISTRY/caosdb/src/caosdb-advanced-user-tools/base:latest
Henrik tom Woerden's avatar
Henrik tom Woerden committed


stages: 
  - setup
Henrik tom Wörden's avatar
Henrik tom Wörden committed
  - cert
Henrik tom Woerden's avatar
Henrik tom Woerden committed
  - style
  - unittest
  - integrationtest
Henrik tom Woerden's avatar
Henrik tom Woerden committed

test:
Henrik tom Wörden's avatar
Henrik tom Wörden committed
  tags: [docker]
  services:
    - docker:20.10.5-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: integrationtest
  image: $CI_REGISTRY_IMAGE_BASE
Henrik tom Woerden's avatar
Henrik tom Woerden committed
  script:
      - if [[ "$CAOSDB_TAG" == "" ]]; then
            CAOSDB_TAG=dev;
Henrik tom Woerden's avatar
Henrik tom Woerden committed
        fi
      - echo $CAOSDB_TAG
      - time docker load < /image-cache/caosdb-advanced-testenv.tar || true
      - time docker load < /image-cache/mariadb.tar || true
Henrik tom Wörden's avatar
Henrik tom Wörden committed
      - time docker load < /image-cache/caosdb-dev.tar || true
Henrik tom Wörden's avatar
Henrik tom Wörden committed
      - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
Henrik tom Woerden's avatar
Henrik tom Woerden committed
      - EXEPATH=`pwd` CAOSDB_TAG=$CAOSDB_TAG docker-compose 
        -f .docker/docker-compose.yml up -d
      - cd .docker 
      - cd .. 
      - docker logs docker-caosdb-server-1 &> caosdb_log.txt
      - docker logs docker-sqldb-1 &> mariadb_log.txt
Henrik tom Woerden's avatar
Henrik tom Woerden committed
      - docker-compose -f .docker/docker-compose.yml down
Henrik tom Wörden's avatar
Henrik tom Wörden committed
      - rc=`cat .docker/result`  
Henrik tom Woerden's avatar
Henrik tom Woerden committed
      - exit $rc
Henrik tom Wörden's avatar
Henrik tom Wörden committed
  dependencies: [cert]
  needs: [cert]
  artifacts:
    paths:
      - caosdb_log.txt
      - mariadb_log.txt
    when: on_failure
    expire_in: 1 week
Henrik tom Woerden's avatar
Henrik tom Woerden committed

build-testenv:
  tags: [cached-dind]
  image: docker:18.09
Henrik tom Woerden's avatar
Henrik tom Woerden committed
  stage: setup
Henrik tom Wörden's avatar
Henrik tom Wörden committed
  # Hint: do not use only here; the image needs always to be build since it 
  # contains the repo code
  #only:
Henrik tom Woerden's avatar
Henrik tom Woerden committed
  script: 
Henrik tom Wörden's avatar
Henrik tom Wörden committed
      - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
Henrik tom Woerden's avatar
Henrik tom Woerden committed
        # use here general latest or specific branch latest...
      - docker build 
        --file .docker/Dockerfile
        -t $CI_REGISTRY_IMAGE .
      - docker push $CI_REGISTRY_IMAGE
      - docker save $CI_REGISTRY_IMAGE > /image-cache/caosdb-advanced-testenv.tar
      - cd .docker-base
      - docker build 
        -t $CI_REGISTRY_IMAGE_BASE .
      - docker push $CI_REGISTRY_IMAGE_BASE
Henrik tom Wörden's avatar
Henrik tom Wörden committed
cert:
Henrik tom Wörden's avatar
Henrik tom Wörden committed
  tags: [docker]
Henrik tom Wörden's avatar
Henrik tom Wörden committed
  stage: cert
  image: $CI_REGISTRY_IMAGE
  needs: [build-testenv]
Henrik tom Wörden's avatar
Henrik tom Wörden committed
  artifacts:
    paths:
      - .docker/cert/
    expire_in: 1 week
  script:
      - cd .docker
      - CAOSHOSTNAME=caosdb-server ./cert.sh
Henrik tom Woerden's avatar
Henrik tom Woerden committed
style:
  tags: [docker]
Henrik tom Woerden's avatar
Henrik tom Woerden committed
  stage: style
  image: $CI_REGISTRY_IMAGE
  needs: [build-testenv]
Henrik tom Woerden's avatar
Henrik tom Woerden committed
  script:
Henrik tom Woerden's avatar
Henrik tom Woerden committed
  allow_failure: true
linting:
  tags: [docker]
  stage: style
  image: $CI_REGISTRY_IMAGE
  needs: [build-testenv]
Henrik tom Woerden's avatar
Henrik tom Woerden committed
  script:
Henrik tom Woerden's avatar
Henrik tom Woerden committed
  allow_failure: true

unittest:
  tags: [docker]
  stage: unittest
  image: $CI_REGISTRY_IMAGE
  needs: [build-testenv]
Henrik tom Wörden's avatar
Henrik tom Wörden committed
      - python3 -c "import caosdb; print('CaosDB Version:', caosdb.__version__)"

# Build the sphinx documentation and make it ready for deployment by Gitlab Pages
# Special job for serving a static website. See https://docs.gitlab.com/ee/ci/yaml/README.html#pages
pages_prepare: &pages_prepare
  tags: [docker]
  image: $CI_REGISTRY_IMAGE
  stage: deploy
  script:
    - echo "Deploying"
    - make doc
    - cp -r build/doc/html public
  artifacts:
    paths:
      - public
pages:
  <<: *pages_prepare
  only:
    refs:
      # version tags: v0.1.1
      - /^v(\d+\.\d+\.\d+)$/