fix: correct CI pipeline stage ordering and DB auth issues

- Add e2e stage after build so e2e_tests runs after build_image
- Remove git clone from test runner (addon is already in Docker image)
- Fix kubectl context: remove use-context call, kubeconfig already has correct context
- Add PGPASSWORD export to unit_tests before_script and script
- Add --junitxml flag to unit_tests so junit artifact is actually generated
- Remove Odoo re-install from E2E K8s job (template DB is pre-primed)
- Use dropdb --if-exists + createdb for clean DB on each E2E run
- Add needs: [build_image] to e2e_tests for correct dependency ordering

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Nicholas Riegel 2026-05-30 02:16:54 -04:00
parent 0d88ffdd6e
commit 8148b9eb3a

View file

@ -2,6 +2,7 @@ stages:
- lint - lint
- test - test
- build - build
- e2e
- notify - notify
variables: variables:
@ -50,6 +51,7 @@ unit_tests:
- -c - -c
- shared_buffers=512MB - shared_buffers=512MB
before_script: before_script:
- export PGPASSWORD=$POSTGRES_PASSWORD
# Create primed template database # Create primed template database
- createdb -h $POSTGRES_HOST -U $POSTGRES_USER $TEMPLATE_DATABASE - createdb -h $POSTGRES_HOST -U $POSTGRES_USER $TEMPLATE_DATABASE
# Install Odoo + modules into template DB # Install Odoo + modules into template DB
@ -57,10 +59,12 @@ unit_tests:
odoo -d $TEMPLATE_DATABASE \ odoo -d $TEMPLATE_DATABASE \
-i base,website,website_blog,mail,itsulu_blog_publisher \ -i base,website,website_blog,mail,itsulu_blog_publisher \
--addons-path=/usr/lib/python3/dist-packages/odoo/addons,/builds/$CI_PROJECT_PATH/addons \ --addons-path=/usr/lib/python3/dist-packages/odoo/addons,/builds/$CI_PROJECT_PATH/addons \
--without-demo=all --stop-after-init --db_host=$POSTGRES_HOST --db_user=$POSTGRES_USER --without-demo=all --stop-after-init --db_host=$POSTGRES_HOST --db_user=$POSTGRES_USER \
--db_password=$POSTGRES_PASSWORD
# Install test dependencies # Install test dependencies
- pip install --no-cache-dir pytest pytest-odoo pytest-bdd pytest-cov pytest-html - pip install --no-cache-dir pytest pytest-odoo pytest-bdd pytest-cov pytest-html
script: script:
- export PGPASSWORD=$POSTGRES_PASSWORD
# Clone template DB for test isolation # Clone template DB for test isolation
- createdb -h $POSTGRES_HOST -U $POSTGRES_USER -T $TEMPLATE_DATABASE $POSTGRES_DB - createdb -h $POSTGRES_HOST -U $POSTGRES_USER -T $TEMPLATE_DATABASE $POSTGRES_DB
# Run TDD, BDD, and performance tests # Run TDD, BDD, and performance tests
@ -73,6 +77,7 @@ unit_tests:
--cov-report=term-missing \ --cov-report=term-missing \
--cov-report=html \ --cov-report=html \
--cov-report=xml \ --cov-report=xml \
--junitxml=report.xml \
--html=report-unit.html \ --html=report-unit.html \
--self-contained-html --self-contained-html
artifacts: artifacts:
@ -93,16 +98,13 @@ unit_tests:
# ================================================================ # ================================================================
e2e_tests: e2e_tests:
stage: build # Runs after unit tests, uses built Docker image stage: e2e
image: bitnami/kubectl:latest image: bitnami/kubectl:latest
services: needs: [build_image]
- docker:dind
before_script: before_script:
# Configure kubectl to access ITSulu K8s cluster
- | - |
mkdir -p ~/.kube mkdir -p ~/.kube
echo "$KUBE_CONFIG" | base64 -d > ~/.kube/config echo "$KUBE_CONFIG" | base64 -d > ~/.kube/config
kubectl config use-context itsulu-testing
script: script:
# Create ephemeral E2E test job on K8s cluster # Create ephemeral E2E test job on K8s cluster
- | - |
@ -142,7 +144,8 @@ e2e_tests:
args: args:
- | - |
until pg_isready -h test-db-svc -U $$DB_USER; do sleep 2; done until pg_isready -h test-db-svc -U $$DB_USER; do sleep 2; done
createdb -h test-db-svc -U $$DB_USER -T odoo_template odoo_e2e 2>/dev/null || true PGPASSWORD=$$PGPASSWORD dropdb -h test-db-svc -U $$DB_USER odoo_e2e --if-exists
PGPASSWORD=$$PGPASSWORD createdb -h test-db-svc -U $$DB_USER -T odoo_template odoo_e2e
containers: containers:
- name: test-runner - name: test-runner
image: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA image: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
@ -163,15 +166,11 @@ e2e_tests:
command: [sh, -c] command: [sh, -c]
args: args:
- | - |
pip install --no-cache-dir -r e2e/requirements.txt python3 -m pytest /mnt/extra-addons/itsulu_blog_publisher/tests/ \
odoo -d odoo_e2e -i base,website,website_blog,mail,itsulu_blog_publisher \ --odoo-database=odoo_e2e \
--addons-path=/usr/lib/python3/dist-packages/odoo/addons,/mnt/extra-addons \
--without-demo=all --stop-after-init --db_host=test-db-svc --db_user=$$DB_USER
python3 -m pytest e2e/ \
--base-url=http://localhost:8069 \
-v --tb=short \ -v --tb=short \
--html=/tmp/report-e2e.html --self-contained-html --html=/tmp/report-e2e.html --self-contained-html \
--junitxml=/tmp/report-e2e.xml
volumeMounts: volumeMounts:
- name: test-results - name: test-results
mountPath: /tmp mountPath: /tmp