Draft: Pipeline for documentation

Address Issue #72.

We use the Forge docker registry. We need to have the Dockerfile of the runner (which is needed to initialize the runner with python and all the dependencies).

The docker image is hosted in the Forge Registry, and it is built only when a change is applied to the Dockerfile or the requirements.txt file.

I also added the CI/CD yaml file which calls the command for testing the documentation. If it does not fail, the pipeline proceed with an OK.

Edited by Marco Cavalli

Merge request reports

Loading

.gitlab-ci.yml

0 → 100644
+80 −0
Changes for .gitlab-ci.yml: 80 added lines, 0 removed lines.
Original line number Diff line number Diff line
stages:
  - build
  - test

variables:
  DOCKER_DRIVER: overlay2
  DOCKER_TLS_CERTDIR: ""
  GIT_CLEAN_FLAGS: -ffdx

build_image:
  stage: build
  image: docker:25.0.3
  services:
    - docker:25.0.3-dind
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
      changes:
        - Dockerfile
        - requirements.txt
    - if: '$CI_COMMIT_BRANCH == "develop"'
      changes:
        - Dockerfile
        - requirements.txt
    - when: never
  variables:
    GIT_STRATEGY: clone
    GIT_CLEAN_FLAGS: -ffdx

  before_script:
    - echo "CI_REGISTRY = $CI_REGISTRY"
    - echo "CI_PROJECT_PATH = $CI_PROJECT_PATH"
    - export IMAGE_NAME="$CI_REGISTRY/$(echo $CI_PROJECT_PATH | tr '[:upper:]' '[:lower:]')"
    - echo "IMAGE_NAME = $IMAGE_NAME"

  script:
    - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY

    - docker pull $IMAGE_NAME:cache || true

    - docker build --cache-from=$IMAGE_NAME:cache -t $IMAGE_NAME:$CI_COMMIT_SHA -t $IMAGE_NAME:cache .

    - docker push $IMAGE_NAME:$CI_COMMIT_SHA
    - docker push $IMAGE_NAME:cache
    
    - echo "IMAGE_TAG=$CI_COMMIT_SHA" > build.env
    - echo "IMAGE_NAME=$IMAGE_NAME" >> build.env
    - cat build.env

  artifacts:
    expire_in: 3 months
    reports:
      dotenv: build.env

test_documentation:
  stage: test
  image: docker:25.0.3
  services:
    - docker:25.0.3-dind
  needs: 
    - job: build_image
      artifacts: true
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
    - if: '$CI_COMMIT_BRANCH == "develop"'
    - when: never
  variables:
    GIT_STRATEGY: clone
    GIT_CLEAN_FLAGS: -ffdx
  before_script:
    - echo "IMAGE_NAME from artifact = $IMAGE_NAME"
    - echo "IMAGE_TAG from artifact = $IMAGE_TAG"
    - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
    - docker pull $IMAGE_NAME:$IMAGE_TAG
  script:
    - echo "Running tests in container..."
    - docker run --rm -v $CI_PROJECT_DIR:/workspace -w /workspace $IMAGE_NAME:$IMAGE_TAG python -m unittest discover -s ./doc/tests -t ./doc
  
  after_script:
    - rm -rf __pycache__ || true
    - find . -type d -name __pycache__ -exec rm -rf {} + || true
 No newline at end of file

Dockerfile

0 → 100644
+8 −0
Changes for Dockerfile: 8 added lines, 0 removed lines.
Original line number Diff line number Diff line
FROM python:3.11

WORKDIR /app
COPY requirements.txt .

RUN pip install --no-cache-dir -r requirements.txt

CMD ["python", "-m", "unittest", "discover", "-s", "./doc/tests", "-t", "./doc"]
 No newline at end of file
Loading