Refactor Jenkinsfile to utilize Docker for Python environment setup during backend testing, enhancing consistency and isolation of dependencies.
This commit is contained in:
28
Jenkinsfile
vendored
28
Jenkinsfile
vendored
@@ -37,7 +37,6 @@ pipeline {
|
||||
set -euxo pipefail
|
||||
echo "== Test backend stage started =="
|
||||
echo "Workspace: $WORKSPACE"
|
||||
python3 --version
|
||||
docker --version
|
||||
|
||||
DB_CONTAINER="anexo76-test-db-${BUILD_NUMBER}"
|
||||
@@ -46,8 +45,10 @@ pipeline {
|
||||
DB_PASS="anexo76"
|
||||
DB_PORT="55432"
|
||||
export TEST_DATABASE_URL="postgresql://${DB_USER}:${DB_PASS}@127.0.0.1:${DB_PORT}/${DB_NAME}"
|
||||
PY_CONTAINER="anexo76-test-py-${BUILD_NUMBER}"
|
||||
|
||||
cleanup() {
|
||||
docker rm -f "$PY_CONTAINER" >/dev/null 2>&1 || true
|
||||
docker rm -f "$DB_CONTAINER" >/dev/null 2>&1 || true
|
||||
}
|
||||
trap cleanup EXIT
|
||||
@@ -69,16 +70,21 @@ pipeline {
|
||||
done
|
||||
docker exec "$DB_CONTAINER" pg_isready -U "$DB_USER" -d "$DB_NAME"
|
||||
|
||||
VENV="$WORKSPACE/.pytest-venv"
|
||||
python3 -m venv "$VENV"
|
||||
. "$VENV/bin/activate"
|
||||
|
||||
python -m pip install --upgrade pip
|
||||
pip install -r "$WORKSPACE/backend/requirements.txt"
|
||||
|
||||
cd "$WORKSPACE/backend"
|
||||
alembic upgrade head
|
||||
pytest -q tests -v -ra -s
|
||||
docker run --name "$PY_CONTAINER" --rm \
|
||||
--network host \
|
||||
-e TEST_DATABASE_URL="$TEST_DATABASE_URL" \
|
||||
-v "$WORKSPACE:/workspace" \
|
||||
-w /workspace \
|
||||
python:3.12-slim \
|
||||
sh -lc '
|
||||
set -euxo pipefail
|
||||
python --version
|
||||
python -m pip install --upgrade pip
|
||||
pip install -r /workspace/backend/requirements.txt
|
||||
cd /workspace/backend
|
||||
alembic upgrade head
|
||||
pytest -q tests -v -ra -s
|
||||
'
|
||||
'''
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user