From eda58ace70f95112e3153ca0dae7fe2970791dd8 Mon Sep 17 00:00:00 2001 From: Klagarge Date: Wed, 19 Mar 2025 21:55:06 +0100 Subject: [PATCH] feat(CI): add custom docker for CI Refs: #4 Signed-off-by: Klagarge --- .gitlab-ci.yml | 32 +++++++++++++++----------------- Dockerfile | 23 +++++++++++++++++++++++ 2 files changed, 38 insertions(+), 17 deletions(-) create mode 100644 Dockerfile diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c0412a4..6e5d649 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,33 +1,31 @@ +variables: + DOCKER_IMAGE: registry.forge.hefr.ch/klagarge/mse2425-grp09/python-pdm:latest + default: - image: python:3.9 + image: $DOCKER_IMAGE stages: - lint - - build + - test -build job: - stage: build +test job: + stage: test script: - cd src - # - apt-get update -qy - # - apt-get install -y python3-dev python3-pip python3.12-venv curl - - python3 -V -# - pip3 install --break-system-packages -r requirements.txt - - curl -sSL https://pdm-project.org/install-pdm.py | python3 - - - export PATH=/root/.local/bin:$PATH - - pdm install + - cp -r /app/__pypackages__ . # Set environment variables for the tests - export FLASK_SECRET_KEY=$FLASK_SECRET_KEY # launch tests - - export PYTHONPATH=. + - export PYTHONPATH="/builds/Klagarge/mse2425-grp09/src:/builds/Klagarge/mse2425-grp09/src/__pypackages__/3.9/lib" + - export PATH="/builds/Klagarge/mse2425-grp09/src/__pypackages__/3.9/bin:$PATH" - export FLASK_APP=app - pdm run pytest tests --cov --cov-report term --cov-report html artifacts: - paths: - - src/htmlcov/ + paths: + - src/htmlcov/ lint job: stage: lint @@ -38,10 +36,10 @@ lint job: allow_failure: true # Linter can fail, fixing it is for now outside of the projects scope pages: - stage: build + stage: test dependencies: - - build job - needs: ["build job"] + - test job + needs: ["test job"] script: - mv src/htmlcov/ public/ artifacts: diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d1e5cd4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +FROM python:3.9-slim +LABEL maintener="Rémi Heredero " + +RUN apt-get update && \ + apt-get install -y --no-install-recommends curl && \ + rm -rf /var/lib/apt/lists/* + +RUN curl -sSL https://pdm-project.org/install-pdm.py | python3 - + +ENV PATH="/root/.local/bin:$PATH" \ + PDM_USE_VENV=false + +WORKDIR /app + +COPY src/pyproject.toml src/pdm.lock ./ + +RUN pdm config python.use_venv false && \ + pdm install -G:all + +ENV PATH="/root/.local/bin:$PATH" \ + PDM_USE_VENV=false \ + PYTHONPATH="/app/__pypackages__/3.9/lib" \ + PATH="/app/__pypackages__/3.9/bin:$PATH" \ No newline at end of file