From 925d6f6ace9fa8540b6398267e435c8e696760ca Mon Sep 17 00:00:00 2001 From: Ross Whitfield Date: Fri, 21 Jun 2024 11:38:24 +1000 Subject: [PATCH] Simplify code coverage --- .github/workflows/unittest.yml | 1 + Dockerfile.coverage | 18 --------- config/docker-compose.coverage.yml | 61 ------------------------------ config/docker-compose.envlocal.yml | 1 + docker-entrypoint-coverage.sh | 27 ------------- docker-entrypoint.sh | 2 +- src/live_data_server/.coveragerc | 4 ++ 7 files changed, 7 insertions(+), 107 deletions(-) delete mode 100644 Dockerfile.coverage delete mode 100644 config/docker-compose.coverage.yml delete mode 100755 docker-entrypoint-coverage.sh create mode 100644 src/live_data_server/.coveragerc diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml index f7dbd3a..395c932 100644 --- a/.github/workflows/unittest.yml +++ b/.github/workflows/unittest.yml @@ -22,6 +22,7 @@ jobs: LIVE_PLOT_SECRET_KEY: "1234_live_data_server" DJANGO_SUPERUSER_USERNAME: livedatauser DJANGO_SUPERUSER_PASSWORD: livedatapass + COVERAGE_RUN: coverage run -m steps: - uses: actions/checkout@v4 - uses: conda-incubator/setup-miniconda@v3 diff --git a/Dockerfile.coverage b/Dockerfile.coverage deleted file mode 100644 index 35628f7..0000000 --- a/Dockerfile.coverage +++ /dev/null @@ -1,18 +0,0 @@ -FROM continuumio/miniconda3:23.10.0-1 - -COPY environment.yml . -RUN conda env create - -WORKDIR /var/www/livedata - -COPY docker-entrypoint-coverage.sh /usr/bin/docker-entrypoint.sh - -COPY src/live_data_server app -RUN mkdir ./static - -WORKDIR /var/www/livedata/app - -RUN echo "[run]\nsource=live_data_server,plots\nparallel=True\nrelative_files=True" > /var/www/livedata/app/.coveragerc - -RUN chmod +x /usr/bin/docker-entrypoint.sh -ENTRYPOINT ["conda", "run", "--no-capture-output", "-n", "livedata", "/usr/bin/docker-entrypoint.sh"] diff --git a/config/docker-compose.coverage.yml b/config/docker-compose.coverage.yml deleted file mode 100644 index 9311687..0000000 --- a/config/docker-compose.coverage.yml +++ /dev/null @@ -1,61 +0,0 @@ -services: - - nginx: - image: nginx:1.21.1 - ports: - - "80:80" - - "443:443" - volumes: - - web-static:/var/www/livedata/static - - ./config/nginx/envlocal.conf:/etc/nginx/conf.d/nginx.conf - depends_on: - livedata: - condition: service_healthy - - livedata: - build: - context: . - dockerfile: Dockerfile.coverage - network: host - environment: - APP_DEBUG: 1 # 0 for False, otherwise will evaluate to True - DJANGO_SUPERUSER_USERNAME: ${DATABASE_USER} - DJANGO_SUPERUSER_PASSWORD: ${DATABASE_PASS} - DATABASE_NAME: ${DATABASE_NAME} - DATABASE_USER: ${DATABASE_USER} - DATABASE_PASS: ${DATABASE_PASS} - DATABASE_HOST: ${DATABASE_HOST} - DATABASE_PORT: ${DATABASE_PORT} - LIVE_PLOT_SECRET_KEY: ${LIVE_PLOT_SECRET_KEY} - command: /usr/bin/docker-entrypoint.sh - volumes: - - web-static:/var/www/livedata/static - healthcheck: - test: wget --no-verbose --tries=1 --spider http://localhost:8000/admin || exit 1 - interval: 60s - retries: 5 - start_period: 20s - timeout: 10s - ports: - - "8000:8000" - depends_on: - db: - condition: service_healthy - - db: - # do not upgrade to version > 9.6.23 unless you also upgrade livedata image - image: postgres:9.6.23 - environment: - POSTGRES_DB: ${DATABASE_NAME} - POSTGRES_USER: ${DATABASE_USER} - POSTGRES_PASSWORD: ${DATABASE_PASS} - healthcheck: - test: ["CMD-SHELL", "pg_isready -U ${DATABASE_USER} -d ${DATABASE_NAME}"] - interval: 5s - timeout: 5s - retries: 5 - ports: - - "${DATABASE_PORT}:${DATABASE_PORT}" - -volumes: - web-static: diff --git a/config/docker-compose.envlocal.yml b/config/docker-compose.envlocal.yml index 25d54d9..7e3d395 100644 --- a/config/docker-compose.envlocal.yml +++ b/config/docker-compose.envlocal.yml @@ -27,6 +27,7 @@ services: DATABASE_HOST: ${DATABASE_HOST} DATABASE_PORT: ${DATABASE_PORT} LIVE_PLOT_SECRET_KEY: ${LIVE_PLOT_SECRET_KEY} + COVERAGE_RUN: ${COVERAGE_RUN} command: /usr/bin/docker-entrypoint.sh volumes: - web-static:/var/www/livedata/static diff --git a/docker-entrypoint-coverage.sh b/docker-entrypoint-coverage.sh deleted file mode 100755 index eeca130..0000000 --- a/docker-entrypoint-coverage.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/sh -set -e - -# wait for database -until PGPASSWORD=${DATABASE_PASS} psql -h "${DATABASE_HOST}" -U "${DATABASE_USER}" -d "${DATABASE_NAME}" -c '\q'; do - >&2 echo "Postgres is unavailable - sleeping" - sleep 1 -done - -cd /var/www/livedata/app - -# collect static files -python manage.py collectstatic --noinput - -# migrate django models -python manage.py makemigrations --noinput -python manage.py migrate --noinput - -# create superuser -#echo "from django.contrib.auth.models import User; User.objects.create_superuser('${DJANGO_SUPERUSER_USERNAME}', '${DJANGO_SUPERUSER_USERNAME}@example.com', '${DJANGO_SUPERUSER_PASSWORD}')" | python manage.py shell - -# Create the webcache -python manage.py createcachetable webcache -python manage.py ensure_adminuser --username=${DJANGO_SUPERUSER_USERNAME} --email='workflow@example.com' --password=${DJANGO_SUPERUSER_PASSWORD} - -# run application with code coverage -coverage run -m gunicorn live_data_server.wsgi:application -b :8000 diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 2125ca7..b56730a 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -24,4 +24,4 @@ python manage.py createcachetable webcache python manage.py ensure_adminuser --username=${DJANGO_SUPERUSER_USERNAME} --email='workflow@example.com' --password=${DJANGO_SUPERUSER_PASSWORD} # run application -gunicorn live_data_server.wsgi:application -w 2 -b :8000 --reload +${COVERAGE_RUN} gunicorn live_data_server.wsgi:application -w 2 -b :8000 --reload diff --git a/src/live_data_server/.coveragerc b/src/live_data_server/.coveragerc new file mode 100644 index 0000000..c900f8e --- /dev/null +++ b/src/live_data_server/.coveragerc @@ -0,0 +1,4 @@ +[run] +source=live_data_server,plots +parallel=True +relative_files=True