mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
Instead of using Dockerfile for everything, we've introduced a docker-compose.yml file and kept the Dockerfile to producing a pure base image for the services defined. docker-compose services: - `mariadb` - Setup mariadb - `sharness` - Run sharness suites - `pytest-mysql` - Run pytest suites with MariaDB - `pytest-sqlite` - Run pytest suites with SQLite - `test` - Run all tests and produce a collective coverage report - This target mounts a cache volume and copies any successful coverage report back to `./cache/.coverage`. Users can run `./util/fix-coverage ./cache/.coverage` to rewrite source code paths and move coverage into place to view reports on your local system. == Get Started == Build `aurweb:latest`. $ docker build -t aurweb:latest . Run all tests via `docker-compose`. $ docker-compose up test You can also purely run `pytest` in SQLite or MariaDB modes. $ docker-compose up pytest-sqlite $ docker-compose up pytest-mysql Or `sharness` alone, which only uses SQLite internally. $ docker-compose up sharness After running tests, coverage reports are stored in `./cache/.coverage`. This database was most likely created in a different path, and so it needs to be sanitized with `./util/fix-coverage`. $ ./util/fix-coverage cache/.coverage Copied coverage db to /path/to/aurweb/.coverage. $ coverage report ... $ coverage html $ coverage xml ... Defined components: **Entrypoints** - mariadb-entrypoint.sh - setup mariadb and run its daemon - test-mysql-entrypoint.sh - setup mysql configurations - test-sqlite-entrypoint.sh - setup sqlite configurations - tests-entrypoint.sh - setup mysql and sqlite configurations **Scripts** - run-mariadb.sh - setup databases - run-pytests.sh - run pytest suites - run-sharness.sh - run sharness suites - run-tests.sh - run both pytests and sharness **Health** - mariadb.sh - A healthcheck script for the mariadb service - pytest.sh - A healthcheck script for the pytest-* services - sharness.sh - A healthcheck script for the sharness service This Docker configuration is setup for tests, but should be extendable for web and git servers. **Changes to Makefile** - Remove `.coverage` in the `clean` target - Add a `coverage` target which prints a report and outputs xml Signed-off-by: Kevin Morris <kevr@0cost.org>
68 lines
1.6 KiB
Python
Executable file
68 lines
1.6 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
""" A simple script which updates paths for .coverage executed
|
|
in another directory. This is particularly useful for fixing
|
|
.coverage files received via ./cache/.coverage after Docker runs.
|
|
|
|
Copyright (C) 2021 aurweb Development
|
|
All Rights Reserved.
|
|
"""
|
|
import os
|
|
import re
|
|
import sqlite3
|
|
import sys
|
|
import traceback
|
|
|
|
import aurweb.config
|
|
|
|
|
|
def eprint(*args, **kwargs):
|
|
print(*args, **kwargs, file=sys.stderru)
|
|
|
|
|
|
def main():
|
|
if len(sys.argv) == 1:
|
|
print(f"usage: {sys.argv[0]} .coverage")
|
|
return 1
|
|
|
|
coverage_db = sys.argv[1]
|
|
if not os.path.exists(coverage_db):
|
|
eprint("error: coverage file not found")
|
|
return 2
|
|
|
|
aurwebdir = aurweb.config.get("options", "aurwebdir")
|
|
new_coverage_db = os.path.join(aurwebdir, ".coverage")
|
|
with open(coverage_db, "rb") as i:
|
|
with open(new_coverage_db, "wb") as f:
|
|
f.write(i.read())
|
|
print(f"Copied coverage db to {new_coverage_db}.")
|
|
coverage_db = new_coverage_db
|
|
|
|
sqlite3.paramstyle = "format"
|
|
db = sqlite3.connect(coverage_db)
|
|
|
|
cursor = db.cursor()
|
|
results = cursor.execute("SELECT * FROM file")
|
|
|
|
files = dict()
|
|
for i, path in results:
|
|
files[i] = path
|
|
|
|
for _, i in enumerate(files.keys()):
|
|
new_path = re.sub(r'^/aurweb', aurwebdir, files[i])
|
|
cursor.execute("UPDATE file SET path = ? WHERE id = ?", (
|
|
new_path, i))
|
|
|
|
db.commit()
|
|
db.close()
|
|
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
e = 1
|
|
try:
|
|
e = main()
|
|
except Exception:
|
|
traceback.print_exc()
|
|
e = 1
|
|
sys.exit(e)
|