Skip to content
.gitlab-ci.yml 9.73 KiB
Newer Older
image: python:3-bullseye
Patrik Dufresne's avatar
Patrik Dufresne committed
stages:
  - test
  - package
  - doc
  - test-package
  - sonar
  - publish
  - deploy
  image: python:3.10-bullseye
  variables:
    TOXENV: $CI_JOB_NAME
  before_script:
Patrik Dufresne's avatar
Patrik Dufresne committed
    - apt-get -yq update
    - apt-get install -yq rdiff-backup
Patrik Dufresne's avatar
Patrik Dufresne committed
  script:
    - pip install tox
    - export TOXENV=${TOXENV:-$CI_JOB_NAME}
    - echo TOXENV=$TOXENV
    - useradd myuser
    - su myuser -c tox
      - coverage-*.xml
      - xunit-*.xml
flake8:
  <<: *tox

  image: $IMAGE
  parallel:
    matrix:
      - TOXENV: py3
        IMAGE: python:3.6
      - TOXENV: py3
        IMAGE: python:3.8
      - TOXENV: bullseye
        IMAGE: python:3.9-bullseye
      - TOXENV: py3
        IMAGE: python:3.10
      - TOXENV: bookworm
        IMAGE: python:3.11
sqlalchemy2:
  <<: *tox

selenium:
  <<: *tox
  before_script:
    - apt update
    - apt -y --no-install-recommends install xvfb xauth chromium-driver rdiff-backup
  artifacts:
    paths:
      - coverage.xml
      - xunit.xml

rdiff-backup-latest:
  image: python:3.9-bullseye
  variables:
    TOXENV: bullseye
  allow_failure: true
  before_script:
    - apt-get update
    - apt -y install librsync-dev
    - pip install tox
    - pip install -U rdiff-backup
Patrik Dufresne's avatar
Patrik Dufresne committed
  <<: *tox
  image: $IMAGE
  services:
    - postgres:12.2-alpine
Patrik Dufresne's avatar
Patrik Dufresne committed
  variables:
    TOXENV: bullseye
    IMAGE: python:3.9-bullseye
    RDIFFWEB_TEST_DATABASE_URI: "postgresql://admin@postgres/test"
    POSTGRES_DB: test
    POSTGRES_USER: admin
    POSTGRES_PASSWORD: ""
    POSTGRES_HOST_AUTH_METHOD: trust
doc:
  <<: *tox
  stage: doc
  needs: []
  dependencies: []
  artifacts:
    paths:
      - .tox/doc/tmp/html
    - pip3 install wheel
    - python3 setup.py sdist bdist_wheel
  dependencies: []
  artifacts:
    paths:
    expire_in: 1 day
Patrik Dufresne's avatar
Patrik Dufresne committed
package:docker:
  stage: package
  needs: []
  dependencies: []
  image: docker:20
  services:
    - name: docker:20-dind
Patrik Dufresne's avatar
Patrik Dufresne committed
  script:
    # Get docker layes
    - docker pull ikus060/rdiffweb:latest || true
    - docker pull ikus060/rdiffweb:$CI_COMMIT_REF_SLUG || true
    - docker build --cache-from ikus060/rdiffweb:latest --cache-from ikus060/rdiffweb:$CI_COMMIT_REF_SLUG -t rdiffweb .
    - docker build --target test .
    - mkdir dist
    - docker save rdiffweb --output dist/rdiffweb-docker.tar
  artifacts:
    paths:
      - dist/*-docker.tar
    expire_in: 1 day
  image: buildpack-deps:$DIST
  parallel:
    matrix:
      - DIST: [bullseye, bookworm]
Patrik Dufresne's avatar
Patrik Dufresne committed
      - DIST: [jammy, lunar, mantic]
  script:
    # Clean-up
    - rm -f ../rdiffweb_*
    - rm -Rf ./dist/$DIST/*
    # Install dependencies
    - apt update
    - apt -y --no-install-recommends install devscripts lsb-release
    - apt build-dep -y .
    # Generate change log
    - export DEBEMAIL=${CI_COMMIT_AUTHOR}
    - debian/rules changelog
    # Generate orig.tar.gz
    - debian/rules gentarball
    # Run build in separate target
    - debuild -us -uc
    # Move files to archives
    - mkdir -p ./dist/$DIST
    - mv ../rdiffweb_* ./dist/$DIST/
Patrik Dufresne's avatar
Patrik Dufresne committed
  artifacts:
    paths:
    expire_in: 1 day
test-package:deb:
  stage: test-package
  image: buildpack-deps:$DIST
  needs: ["package:deb"]
  parallel:
    matrix:
      - DIST: [bullseye, bookworm]
      # Ubuntu tzdata is broken https://githubmate.com/repo/regebro/tzlocal/issues/101
      # So we need to make it explicit using environment variable
Patrik Dufresne's avatar
Patrik Dufresne committed
      - DIST: [jammy, lunar, mantic]
    - apt update
    - apt install -y ./dist/$DIST/rdiffweb*.deb
    - rdiffweb --version
    - (/usr/bin/rdiffweb &)
    - timeout 60 bash -c 'until curl --silent http://localhost:8080; do sleep 1; done'
    # Check if static files are working
    - curl http://localhost:8080/static/css/bootstrap.min.css
    - curl http://localhost:8080/static/css/bootstrap.min.css.map
    - curl http://localhost:8080/static/css/font-awesome.css.map
    - curl http://localhost:8080/static/css/font-awesome.min.css
    - curl http://localhost:8080/static/css/jquery.dataTables.min.css
    - curl http://localhost:8080/static/css/responsive.dataTables.min.css
    - curl http://localhost:8080/static/fonts/fontawesome-webfont.eot
    - curl http://localhost:8080/static/fonts/fontawesome-webfont.svg
    - curl http://localhost:8080/static/fonts/fontawesome-webfont.woff
    - curl http://localhost:8080/static/fonts/fontawesome-webfont.woff2
    - curl http://localhost:8080/static/images/sort_asc.png
    - curl http://localhost:8080/static/images/sort_both.png
    - curl http://localhost:8080/static/images/sort_desc.png
    - curl http://localhost:8080/static/js/bootstrap.bundle.js.map
    - curl http://localhost:8080/static/js/bootstrap.bundle.min.js
    - curl http://localhost:8080/static/js/dataTables.buttons.min.js
    - curl http://localhost:8080/static/js/dataTables.responsive.min.js
    - curl http://localhost:8080/static/js/jquery.dataTables.min.js
    - curl http://localhost:8080/static/js/jquery.min.js

publish:sonar:master:
  allow_failure: True
  image: sonarsource/sonar-scanner-cli
  variables:
    SONAR_PROJECT_BASE_DIR: "${CI_PROJECT_DIR}"
Patrik Dufresne's avatar
Patrik Dufresne committed
  script:
    - sonar-scanner -X -Dsonar.python.coverage.reportPaths=coverage-*.xml -Dsonar.python.xunit.reportPaths=xunit-py3.xml -Dsonar.host.url=$SONAR_URL -Dsonar.login=$SONAR_TOKEN -Dsonar.projectKey=$CI_PROJECT_NAME -Dsonar.projectVersion=$(git describe) -Dsonar.qualitygate.wait=True
publish:sonar:dev:
  allow_failure: True
  image: sonarsource/sonar-scanner-cli
  variables:
    SONAR_PROJECT_BASE_DIR: "${CI_PROJECT_DIR}"
    - sonar-scanner -X -Dsonar.python.coverage.reportPaths=coverage-*.xml -Dsonar.python.xunit.reportPaths=xunit-*.xml -Dsonar.host.url=$SONAR_URL -Dsonar.login=$SONAR_TOKEN -Dsonar.projectKey=$CI_PROJECT_NAME-dev -Dsonar.projectVersion=$(git describe) -Dsonar.qualitygate.wait=True
publish:docker:
  needs:
    - package:docker
  image: docker:20
  services:
    - name: docker:20-dind
  only:
    variables:
      - $DOCKER_USR
      - $DOCKER_PWD
  script: |
    set -x
    docker login $DOCKER_REGISTRY -u $DOCKER_USR -p $DOCKER_PWD
    docker load --input dist/*.tar
    # Push commit hash
    docker tag rdiffweb ikus060/rdiffweb:$CI_COMMIT_SHORT_SHA
    docker push ikus060/rdiffweb:$CI_COMMIT_SHORT_SHA
    # Push branch name
    docker tag rdiffweb ikus060/rdiffweb:$CI_COMMIT_REF_SLUG
    docker push ikus060/rdiffweb:$CI_COMMIT_REF_SLUG
    # Push tags
    if [ -n "$CI_COMMIT_TAG" ]; then
      docker tag rdiffweb ikus060/rdiffweb:$CI_COMMIT_TAG
      docker push ikus060/rdiffweb:$CI_COMMIT_TAG
    fi
    # Push tag as latest
    case ${CI_COMMIT_TAG##*.} in
      [0-9]*)
        docker tag rdiffweb ikus060/rdiffweb:latest
        docker push ikus060/rdiffweb:latest      
        ;;
    esac
  stage: publish

publish:docker-readme:
  needs:
    - package:docker
  only:
    variables:
      - $DOCKER_USR
      - $DOCKER_PWD
      - $CI_COMMIT_TAG
  image:
    name: chko/docker-pushrm
Patrik Dufresne's avatar
Patrik Dufresne committed
    entrypoint: ["/bin/sh", "-c"]
  variables:
    DOCKER_USER: $DOCKER_USR
    DOCKER_PASS: $DOCKER_PWD
    PUSHRM_SHORT: A web interface to rdiff-backup repositories.
    PUSHRM_TARGET: docker.io/ikus060/rdiffweb
    PUSHRM_DEBUG: 1
    PUSHRM_FILE: $CI_PROJECT_DIR/README.md
Patrik Dufresne's avatar
Patrik Dufresne committed
  script:
    # Keep top 400 lines to workarround Dockerhub limitation.
    - cp README.md README.md.orig
    - head -n 400 README.md.orig > README.md
    # Push file
    - /docker-pushrm
publish:deb:
  needs:
    - package:deb
      - DIST: [bullseye, bookworm, jammy, lunar, mantic]
  script: |
    set -x
    if [[ "$CI_COMMIT_TAG" == *.+([0-9]) ]]; then
      APT_URL="$NEXUS_URL/repository/apt-release-${DIST}/"
      APT_URL="$NEXUS_URL/repository/apt-dev-${DIST}/"
    fi
    export FILE=$(ls -1 ./dist/$DIST/rdiffweb*.deb)
    curl --fail -u "$NEXUS_USR:$NEXUS_PWD" -H "Content-Type: multipart/form-data" --data-binary "@$FILE" "$APT_URL"
  stage: publish
Patrik Dufresne's avatar
Patrik Dufresne committed
  stage: publish
  only:
    variables:
      - $NEXUS_USR
      - $NEXUS_PWD
      - $NEXUS_PYPI_URL
  script: |
    set -x
    # Publish wheel
Patrik Dufresne's avatar
Patrik Dufresne committed
    pip3 install wheel twine readme_renderer[md] --upgrade
    LANG="C.UTF-8" python3 -m readme_renderer README.md -o /tmp/README.html
    twine upload dist/*.whl -u $NEXUS_USR -p $NEXUS_PWD --repository-url $NEXUS_PYPI_URL
    if [ ! -z "$CI_COMMIT_TAG" ]; then
      twine upload dist/*.whl -u $PYPI_USR -p $PYPI_PWD
    fi

publish:doc:
  stage: publish
      - $NEXUS_USR
      - $NEXUS_PWD
      - $NEXUS_URL
  script:
    # publish to nexus
    - export VERSION=$(python3 setup.py --version)
    - cd .tox/doc/tmp/html
    - find * -type f -exec curl --fail -u "$NEXUS_USR:$NEXUS_PWD" --upload-file "{}" $NEXUS_URL/repository/archive/rdiffweb/$VERSION/doc/{} \;
      - $GITLAB_ANSIBLE_TOKEN
  environment:
    name: demo
    url: https://rdiffweb-demo.ikus-soft.com/
  needs:
    - package:deb
  image: registry.gitlab.com/finestructure/pipeline-trigger
Patrik Dufresne's avatar
Patrik Dufresne committed
    - export DEB_VERSION=$(ls -1 ./dist/bookworm/rdiffweb_*_all.deb | cut -d '_' -f 2)
    - echo DEB_VERSION=$DEB_VERSION
    # Trigger ansible-config pipeline
    - trigger -a "$ANSIBLE_PIPELINE_GITLAB_API_TOKEN" -t master -e "RDIFFWEB_VERSION=$DEB_VERSION" -p 36bae86778d901fc6b2d6453a41844 18716492
  stage: deploy
  variables:
    GIT_STRATEGY: none