Skip to content

Commit 2243ba1

Browse files
Optimize docker build caching and fix coverage.
1 parent 736d14e commit 2243ba1

8 files changed

Lines changed: 59 additions & 66 deletions

File tree

.github/workflows/coverage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Post coverage comment
22

33
on:
44
workflow_run:
5-
workflows: ["Django Tests on PR"]
5+
workflows: ["Django Tests"]
66
types:
77
- completed
88

.github/workflows/test-django.yml

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
name: Django Tests on PR
1+
name: Django Tests
22

3-
# trigger: every pull-request
43
on:
54
push:
65
pull_request:
76
branches:
87
- main
98
- develop
10-
- fix/ci_test
119
workflow_dispatch: # allow manual trigger
1210

1311
permissions:
@@ -61,20 +59,24 @@ jobs:
6159
- name: Initialize submodules
6260
run: git submodule update --init --recursive
6361

64-
# 1. Build only the stage that contains code + deps
6562
- name: Build test image
6663
run: |
6764
cd django && \
6865
docker build . \
6966
--target cohiva-platform-django \
7067
-t cohiva:test
7168
72-
# 2. Run the test script inside that image
73-
- name: Run Django tests
69+
- name: Prepare for coverage report
7470
run: |
7571
set -e
7672
cd django
7773
touch .coverage
74+
ln -sf website_example website
75+
76+
- name: Run Django tests
77+
run: |
78+
set -e
79+
cd django
7880
docker run --rm \
7981
--network host \
8082
-e GITHUB_ACTIONS=true \
@@ -101,29 +103,3 @@ jobs:
101103
# If you use a different name, update COMMENT_FILENAME accordingly
102104
path: python-coverage-comment-action.txt
103105

104-
105-
# - name: Upload coverage to Codecov
106-
# uses: codecov/codecov-action@v3.1.0
107-
# with:
108-
# files: ./django/coverage.xml
109-
# fail_ci_if_error: true
110-
# verbose: true
111-
# flags: unittests
112-
# name: codecov-umbrella
113-
# token: ${{ secrets.CODECOV_TOKEN }}
114-
# directory: ./django/
115-
# workdir: ./django/
116-
#
117-
# - name: Upload coverage html report
118-
# #uses: actions/upload-artifact@v3
119-
# uses: actions/upload-pages-artifact@v3
120-
# with:
121-
# #name: coverage-html-report
122-
# path: ./django/htmlcov/
123-
#
124-
#
125-
# - name: Publish to GitHub pages
126-
# #uses: peaceiris/actions-gh-pages@v3
127-
# uses: actions/deploy-pages@v3
128-
# #with:
129-
# # artifact_name: coverage-html-report

django/.coveragerc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[run]
2+
relative_files = True
3+
4+
[report]
5+
omit =
6+
cohiva/base_config.py
7+
cohiva/settings.py
8+
cohiva/settings_production.py
9+
cohiva/*example*.py
10+
scripts/*
11+
website_example/*
12+
manage.py

django/Dockerfile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,19 @@ RUN apt-get update && \
1010

1111
# Install python dependencies in /usr/local/
1212
WORKDIR /cohiva
13-
COPY . .
14-
RUN cp /cohiva/requirements-docker.txt /cohiva/requirements.txt # Use requirements without dev packages
13+
# Copy only the necessary files to improve build caching
14+
COPY requirements-docker.txt requirements.txt
15+
COPY install_dependencies.sh install.py ./
16+
COPY geno/python-sepa geno/python-sepa
17+
COPY cohiva/saml2/*.patch cohiva/saml2/
1518
RUN chmod +x ./install_dependencies.sh
1619
RUN ./install_dependencies.sh -e docker
1720

1821
# Remove unnecessary stuff from /usr/local/
1922
RUN find /usr/local/lib -type d -name '__pycache__' -exec rm -rf {} + && \
2023
find /usr/local/lib -type f -name '*.dist-info' -exec rm -rf {} +
2124

25+
# Runtime stage
2226
FROM python:3.13-slim-bookworm AS cohiva-platform-os
2327

2428
# Set environment variables to ensure LibreOffice runs in headless mode

django/README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,12 @@ Example for Debian 11 (should work on most Debian/Ubuntu based systems):
8484
sudo apt install clang
8585
sudo apt install python3-dev
8686
sudo apt install python3-venv
87-
sudo apt install libmariadb-dev ## or default-libmysqlclient-dev
87+
sudo apt install libmariadb-dev ## or default-libmysqlclient-dev
8888
sudo apt install libfreetype-dev
8989
sudo apt install libjpeg-dev
9090
sudo apt install libffi-dev
91-
sudo apt install xmlsec1 ## for SAML 2.0 IDP
92-
sudo apt install poppler-utils ## (optional, for tests)
93-
sudo apt install libreoffice-writer ## (optional, for PDF generation)
91+
sudo apt install xmlsec1 ## for SAML 2.0 IDP
92+
sudo apt install libreoffice-writer ## (or libreoffice-writer-nogui, required for PDF generation)
9493

9594
**Note:** If using Docker for development (recommended), you don't need `redis-server` or `mariadb-server` system packages. The bootstrap script automatically detects and offers to install required packages on macOS.
9695

django/docker-compose.dev.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ services:
77
MYSQL_ROOT_PASSWORD: root
88
# Database is created in init script with correct collation
99
MYSQL_USER: cohiva
10-
MYSQL_PASSWORD: cohiva_password
10+
MYSQL_PASSWORD: c0H1v4
1111
ports:
1212
- "3306:3306"
1313
volumes:
1414
- mariadb_data:/var/lib/mysql
15-
#- ./docker/mariadb-init:/docker-entrypoint-initdb.d
15+
- ./docker/mariadb-init:/docker-entrypoint-initdb.d
1616
command: >
1717
--character-set-server=utf8mb4
1818
--collation-server=utf8mb4_unicode_ci

django/run-tests.sh

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,38 @@
33
# exit on error
44
set -e
55

6-
# if called from CI (GitHub Actions), copy the base_config_for_tests.py to base_config.py
7-
#if [ -n "$GITHUB_ACTIONS" ] ; then
8-
# This is done with setup.py in the workflow already...
9-
# touch cohiva/settings.py
10-
# cp cohiva/base_config_for_tests.py cohiva/base_config.py
11-
#fi
6+
## Uncomment to enable coverage
7+
#COVERAGE="true"
128

139
## Show warnings?
1410
export PYTHONWARNINGS=always
1511

1612
INSTALL_DIR=$(grep "^INSTALL_DIR = " cohiva/base_config.py | cut -d \" -f 2)
1713

14+
## Normalize flags
15+
case "${COVERAGE,,}" in
16+
true|1|yes|on)
17+
COVERAGE="true"
18+
;;
19+
*)
20+
COVERAGE="false"
21+
;;
22+
esac
23+
case "${GITHUB_ACTIONS,,}" in
24+
true|1|yes|on)
25+
GITHUB_ACTIONS="true"
26+
;;
27+
*)
28+
GITHUB_ACTIONS="false"
29+
;;
30+
esac
31+
1832
## Coverage options
19-
#COVERAGE="true" # Uncomment to enable coverage
2033
COVERAGE_OPTS=()
2134
#COVERAGE_OPTS=(--source "$INSTALL_DIR/django")
2235
#COVERAGE_OPTS=(--append)
23-
if [ -n "$GITHUB_ACTIONS" ] ; then
24-
#COVERAGE_OPTS=(--source "/cohiva/")
25-
cat <<EOT >.coveragerc
26-
[run]
27-
source = /cohiva/
28-
relative_files = True
29-
EOT
30-
31-
fi
3236

33-
if [ -n "$COVERAGE" ] ; then
37+
if [ "$COVERAGE" = "true" ] ; then
3438
COVERAGE_CMD="coverage run ${COVERAGE_OPTS[*]}"
3539
else
3640
COVERAGE_CMD=""
@@ -46,7 +50,7 @@ TEST_OPTS=""
4650
## Select test to run (leave emtpy to run all tests)
4751
SELECTED_TESTS=""
4852
# Examples:
49-
SELECTED_TESTS="finance.tests geno.tests.test_documents.DocumentSendTest.test_send_member_bill"
53+
#SELECTED_TESTS="finance.tests geno.tests.test_documents.DocumentSendTest.test_send_member_bill"
5054

5155
## Full test suite incl. migrations
5256
# Run tests and capture the exit code of the test runner even though output is piped to tee.
@@ -57,13 +61,14 @@ TEST_EXIT_CODE=${PIPESTATUS[0]}
5761
set -e
5862

5963
if [ -n "$COVERAGE_CMD" ] ; then
60-
if [ -n "$GITHUB_ACTIONS" ] ; then
61-
#coverage html 2>&1 | tee coverage.log
62-
# Copy the output to the mounted docker host file
64+
if [ "$GITHUB_ACTIONS" = "true" ] ; then
65+
# Copy the output to the mounted docker host file because
66+
# coverage can't use the mounted file directly in the container.
6367
cp .coverage .coverage_output_for_github_action
68+
#coverage html 2>&1 | tee coverage.log
6469
else
65-
coverage html 2>&1 | tee coverage.log
6670
#coverage report
71+
coverage html 2>&1 | tee coverage.log
6772
fi
6873
fi
6974

django/scripts/mariadb/init_test.sql

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,3 @@ FLUSH PRIVILEGES;
1313
CREATE DATABASE IF NOT EXISTS `cohiva_gnucash_test`
1414
CHARACTER SET utf8mb4
1515
COLLATE utf8mb4_unicode_ci;
16-
17-
-- USE `cohiva_gnucash_test`;
18-
-- SOURCE demo-data/demo-data-gnucash.sql;

0 commit comments

Comments
 (0)