diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 16fb57b160aca793f53d0669e9ad03caeab07db4..ca2ec5a629f2a70b1ea1e31412691b479a137e43 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -58,7 +58,7 @@ backend-tests: - test-report.xml script: - - arkindex/manage.py test + - arkindex test backend-lint: image: python:3.10 @@ -91,7 +91,7 @@ backend-migrations: alias: postgres script: - - arkindex/manage.py makemigrations --check --noinput --dry-run -v 3 + - arkindex makemigrations --check --noinput --dry-run -v 3 backend-openapi: extends: .backend-setup diff --git a/Dockerfile b/Dockerfile index 091db1964cb93a1e96578564119c8374a9beb784..29185f9b0d4c36622dbc9171bf22c329505e4891 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,10 +19,13 @@ RUN chown -R ark:teklia /backend_static # Copy Version file COPY VERSION /etc/arkindex.version -HEALTHCHECK --start-period=1m --interval=1m --timeout=5s \ - CMD wget --spider --quiet http://localhost/api/v1/public-key/ || exit 1 +ENV PORT 8000 +HEALTHCHECK --start-period=10s --interval=30s --timeout=5s \ + CMD wget --spider --quiet http://localhost:$PORT/api/v1/corpus/ || exit 1 + +# Allow usage of django-admin by exposing our settings +ENV DJANGO_SETTINGS_MODULE "arkindex.project.settings" # Run with Gunicorn -ENV PORT 8000 EXPOSE $PORT -CMD manage.py gunicorn --host=0.0.0.0 --port $PORT +CMD arkindex gunicorn --host=0.0.0.0 --port $PORT diff --git a/Makefile b/Makefile index dd13c5dd7491487e9df22324ff76e44edbb4db12..ce25922e9888a3d2e41bc7ebf357b0eb5867c152 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ build: CI_PROJECT_DIR=$(ROOT_DIR) CI_REGISTRY_IMAGE=$(IMAGE_TAG) $(ROOT_DIR)/ci/build.sh worker: - arkindex/manage.py rqworker -v 2 default high tasks + arkindex rqworker -v 2 default high tasks test-fixtures: $(eval export PGPASSWORD=devdata) @@ -27,9 +27,9 @@ test-fixtures: $(MAKE) test-fixtures-restore test-fixtures-run: - arkindex/manage.py migrate - arkindex/manage.py build_fixtures - arkindex/manage.py dumpdata --indent 4 process documents images users auth ponos training > arkindex/documents/fixtures/data.json + arkindex migrate + arkindex build_fixtures + arkindex dumpdata --indent 4 process documents images users auth ponos training > arkindex/documents/fixtures/data.json test-fixtures-restore: # This first renaming ensures that arkindex_tmp_fixtures exists; we don't want to drop arkindex_dev without a backup @@ -42,7 +42,7 @@ require-version: @git rev-parse $(version) >/dev/null 2>&1 && (echo "Version $(version) already exists on local git repo !" && exit 1) || true schema: - ./arkindex/manage.py spectacular --fail-on-warn --validate --file schema.yml + arkindex spectacular --fail-on-warn --validate --file schema.yml release: $(eval version:=$(shell cat VERSION)) diff --git a/README.md b/README.md index 1209bef98d43a99ef49574158b32fe1a9b57c54e..7c9bfdcbfd544b9a13ca2cb6a6ff3cfcf0b7724d 100644 --- a/README.md +++ b/README.md @@ -25,8 +25,8 @@ pip install -e .[test] When the [architecture](https://gitlab.teklia.com/arkindex/architecture) is running locally to provide required services: ``` -arkindex/manage.py migrate -arkindex/manage.py createsuperuser +arkindex migrate +arkindex createsuperuser ``` ### Local configuration @@ -55,7 +55,7 @@ local_imageserver_id: 999 Here is how to quickly create the ImageServer using the shell: ``` -backend/arkindex$ ./manage.py shell +$ arkindex shell >>> from arkindex.images.models import ImageServer >>> ImageServer.objects.create(id=1, display_name='local', url='https://ark.localhost/iiif') ``` @@ -81,7 +81,7 @@ At the root of the repository is a Makefile that provides commands for common op ### Django commands -Aside from the usual Django commands, some custom commands are available via `manage.py`: +Aside from the usual Django commands, some custom commands are available via `arkindex`: * `build_fixtures`: Create a set of database elements designed for use by unit tests in a fixture (see `make test-fixtures`); * `from_csv`: Import manifests and index files from a CSV list; @@ -92,15 +92,15 @@ Aside from the usual Django commands, some custom commands are available via `ma * `telegraf`: A special command with InfluxDB-compatible output for Grafana statistics. * `move_lines_to_parents`: Moves element children to their geographical parents; -See `manage.py <command> --help` to view more details about a specific command. +See `arkindex <command> --help` to view more details about a specific command. ## Code validation Once your code appears to be working on a local server, a few checks have to be performed: -* **Migrations:** Ensure that all migrations have been created by typing `./manage.py makemigrations`. -* **Unit tests:** Run `./manage.py test` to perform unit tests. - - Use `./manage.py test module_name` to perform tests on a single module, if you wish to spend less time waiting for all tests to complete. +* **Migrations:** Ensure that all migrations have been created by typing `arkindex makemigrations`. +* **Unit tests:** Run `arkindex test` to perform unit tests. + - Use `arkindex test module_name` to perform tests on a single module, if you wish to spend less time waiting for all tests to complete. ### Linting @@ -123,11 +123,11 @@ If you want to run the full workflow on all the files: `pre-commit run -a`. Run `pip install ipython django-debug-toolbar django_extensions` to install all the available optional dev tools for the backend. -IPython will give you a nicer shell with syntax highlighting, auto reloading and much more via `./manage.py shell`. +IPython will give you a nicer shell with syntax highlighting, auto reloading and much more via `arkindex shell`. [Django Debug Toolbar](https://django-debug-toolbar.readthedocs.io/en/latest/) provides you with a neat debug sidebar that will help diagnosing slow API endpoints or weird template bugs. Since the Arkindex frontend is completely decoupled from the backend, you will need to browse to an API endpoint to see the debug toolbar. -[Django Extensions](https://django-extensions.readthedocs.io/en/latest/) adds a *lot* of `manage.py` commands ; the most important one is `./manage.py shell_plus` which runs the usual shell but with all the available models pre-imported. You can add your own imports with the `local_settings.py` file. Here is an example that imports most of the backend's enums and some special QuerySet features: +[Django Extensions](https://django-extensions.readthedocs.io/en/latest/) adds a *lot* of `arkindex` commands ; the most important one is `arkindex shell_plus` which runs the usual shell but with all the available models pre-imported. You can add your own imports with the `local_settings.py` file. Here is an example that imports most of the backend's enums and some special QuerySet features: ``` python SHELL_PLUS_POST_IMPORTS = [ @@ -162,7 +162,7 @@ To run them, use `make worker` to start a RQ worker. You will need to have Redis Process tasks are run in RQ by default (Community Edition). Two RQ workers must be running at the same time to actually run a process with worker activities, so the initialisation task can wait for the worker activity task to finish: ```sh -$ manage.py rqworker -v 3 default high & manage.py rqworker -v 3 tasks +$ arkindex rqworker -v 3 default high & arkindex rqworker -v 3 tasks ``` ## Metrics diff --git a/arkindex/documents/migrations/0006_index_cleanup.py b/arkindex/documents/migrations/0006_index_cleanup.py index 5e2f26e8bc0eb798024997e5f17256932b4d5020..8a98c4f656cb3505aa10d71f34d50007b8277caf 100644 --- a/arkindex/documents/migrations/0006_index_cleanup.py +++ b/arkindex/documents/migrations/0006_index_cleanup.py @@ -57,7 +57,7 @@ class Migration(migrations.Migration): ), ), ], - # This can be removed by manage.py squashmigrations + # This can be removed by `arkindex squashmigrations` elidable=True, ), ] diff --git a/arkindex/images/migrations/0002_index_cleanup.py b/arkindex/images/migrations/0002_index_cleanup.py index 8a093b53d1e20eaf15f2d8c8ac5d1d62cfa5364b..c7ebad6215d66ff3dd5127f5bfd22eb317846947 100644 --- a/arkindex/images/migrations/0002_index_cleanup.py +++ b/arkindex/images/migrations/0002_index_cleanup.py @@ -34,7 +34,7 @@ class Migration(migrations.Migration): constraint=models.UniqueConstraint(models.F("url"), name="unique_imageserver_url"), ), ], - # This can be removed by manage.py squashmigrations + # This can be removed by `arkindex squashmigrations` elidable=True, ), ] diff --git a/arkindex/manage.py b/arkindex/manage.py index 5343a931579e20fc97b8eec1f533b615a24b9176..33a97022b456ae0a4fbaee72d670009d106e247b 100755 --- a/arkindex/manage.py +++ b/arkindex/manage.py @@ -2,7 +2,8 @@ import os import sys -if __name__ == "__main__": + +def main(): os.environ.setdefault("DJANGO_SETTINGS_MODULE", "arkindex.project.settings") try: from django.core.management import execute_from_command_line @@ -20,3 +21,8 @@ if __name__ == "__main__": ) raise execute_from_command_line(sys.argv) + + +if __name__ == "__main__": + sys.stderr.write("WARNING: manage.py is deprecated, you should use the `arkindex` script instead\n") + main() diff --git a/arkindex/ponos/migrations/0004_index_cleanup.py b/arkindex/ponos/migrations/0004_index_cleanup.py index 5e9697ff4b4711a468852305fff62b2871e33861..6e25ec7c743706c0bf9aa8b530e3dfc9834fbf6c 100644 --- a/arkindex/ponos/migrations/0004_index_cleanup.py +++ b/arkindex/ponos/migrations/0004_index_cleanup.py @@ -42,7 +42,7 @@ class Migration(migrations.Migration): ), ), ], - # This can be removed by manage.py squashmigrations + # This can be removed by `arkindex squashmigrations` elidable=True, ), # Remove the implicit LIKE index on Secret.name and make the unique constraint explicit @@ -70,7 +70,7 @@ class Migration(migrations.Migration): ), ), ], - # This can be removed by manage.py squashmigrations + # This can be removed by `arkindex squashmigrations` elidable=True, ), # Remove the implicit LIKE index on Task.token and make the unique constraint explicit @@ -101,7 +101,7 @@ class Migration(migrations.Migration): ), ), ], - # This can be removed by manage.py squashmigrations + # This can be removed by `arkindex squashmigrations` elidable=True, ), ] diff --git a/arkindex/process/migrations/0005_migrate_workflows.py b/arkindex/process/migrations/0005_migrate_workflows.py index 00d0be410140f1b515d29dbe26eba03ab97c432a..f4a782a37a217e58d13e43cb0e3545cf659e72f2 100644 --- a/arkindex/process/migrations/0005_migrate_workflows.py +++ b/arkindex/process/migrations/0005_migrate_workflows.py @@ -124,7 +124,7 @@ class Migration(migrations.Migration): SET workflow_id = process_id """, ], - # manage.py squashmigrations is allowed to remove this data migration + # `arkindex squashmigrations` is allowed to remove this data migration elidable=True, ), ] diff --git a/arkindex/process/migrations/0007_index_cleanup.py b/arkindex/process/migrations/0007_index_cleanup.py index 2411ba88ae59f5ee6406c65eb1a2dabee71c7193..9e6ca50a7aec83b8f6b16a19767058207e41d03e 100644 --- a/arkindex/process/migrations/0007_index_cleanup.py +++ b/arkindex/process/migrations/0007_index_cleanup.py @@ -35,7 +35,7 @@ class Migration(migrations.Migration): ), ), ], - # This can be removed by manage.py squashmigrations + # This can be removed by `arkindex squashmigrations` elidable=True, ), # Remove the implicit LIKE index on Farm.seed and make the unique constraint explicit @@ -63,7 +63,7 @@ class Migration(migrations.Migration): ), ), ], - # This can be removed by manage.py squashmigrations + # This can be removed by `arkindex squashmigrations` elidable=True, ), # Remove the implicit LIKE index on Farm.seed and make the unique constraint explicit @@ -94,7 +94,7 @@ class Migration(migrations.Migration): ), ), ], - # This can be removed by manage.py squashmigrations + # This can be removed by `arkindex squashmigrations` elidable=True, ), ] diff --git a/arkindex/project/settings.py b/arkindex/project/settings.py index 38c1353eb10f97d4659ec822ceb6adacf86a349d..4399e4c525b16c8ff019dd036ae7d60599a6c7a5 100644 --- a/arkindex/project/settings.py +++ b/arkindex/project/settings.py @@ -613,7 +613,7 @@ if DEBUG and not TEST_ENV: try: import django_extensions # noqa INSTALLED_APPS.append("django_extensions") - # With disable_existing_loggers=True, Django's logging config causes manage.py runserver_plus --print-sql + # With disable_existing_loggers=True, Django's logging config causes arkindex runserver_plus --print-sql # to no longer be able to log SQL queries. # https://github.com/django-extensions/django-extensions/issues/1626#issuecomment-774698668 LOGGING["loggers"]["django_extensions.management.commands.runserver_plus"] = { diff --git a/arkindex/project/tests/openapi/test_views.py b/arkindex/project/tests/openapi/test_views.py index 3752c6d27ac868d2bb98514f31bfb1c513fd5458..c8c6afac46fdf40ea06228ba3cc7e8a6e56c8b44 100644 --- a/arkindex/project/tests/openapi/test_views.py +++ b/arkindex/project/tests/openapi/test_views.py @@ -12,7 +12,7 @@ class TestSchemaView(FixtureAPITestCase): def test_constant_schema(self): """ Ensure that what a SchemaView outputs is always exactly the same - as what manage.py spectacular outputs. + as what `arkindex spectacular` outputs. Note that we use the JSON output format instead of the normal YAML because JSON will not allow Python-specific objects, while PyYAML would use YAML tags such as "!!python/object", diff --git a/arkindex/project/urls.py b/arkindex/project/urls.py index 628887be890304cbfd661949d6df79cdad97eef0..4ff83f59621b28f94c501c255221b62a7d5f77b6 100644 --- a/arkindex/project/urls.py +++ b/arkindex/project/urls.py @@ -35,7 +35,7 @@ if "debug_toolbar" in settings.INSTALLED_APPS: ] + urlpatterns if settings.DEBUG: - # Serve static files in development—this is done by manage.py runserver, but not by Daphne in dev + # Serve static files in development—this is done by arkindex runserver, but not by Daphne in dev urlpatterns.extend(staticfiles_urlpatterns()) # Add index.html using CDN assets diff --git a/arkindex/training/migrations/0003_index_cleanup.py b/arkindex/training/migrations/0003_index_cleanup.py index d20bc17225130bcacd87285ac2c94b03ac60009a..f63de79303a3fe9ee335d5fcff70089ae28d1f11 100644 --- a/arkindex/training/migrations/0003_index_cleanup.py +++ b/arkindex/training/migrations/0003_index_cleanup.py @@ -35,7 +35,7 @@ class Migration(migrations.Migration): ), ), ], - # This can be removed by manage.py squashmigrations + # This can be removed by `arkindex squashmigrations` elidable=True, ), ] diff --git a/ci/openapi.sh b/ci/openapi.sh index ae808d468093274687e1e2d4ec33bb8004a6ae06..fa674ee63d8d787186aa5ee75077a123bfa2b462 100755 --- a/ci/openapi.sh +++ b/ci/openapi.sh @@ -1,4 +1,4 @@ #!/bin/sh -e mkdir -p output pip install -e . -arkindex/manage.py spectacular --fail-on-warn --validate > output/schema.yml +arkindex spectacular --fail-on-warn --validate > output/schema.yml diff --git a/ci/static-collect.sh b/ci/static-collect.sh index 81ac94ec17e5584c162ebca0749d785996eac3ce..2f4062eb337e5b0ce357bc7a845414bdb2488847 100755 --- a/ci/static-collect.sh +++ b/ci/static-collect.sh @@ -2,4 +2,4 @@ mkdir -p static pip install -e . echo "static: {root_path: '$(pwd)/static'}" >> "$CONFIG_PATH" -arkindex/manage.py collectstatic --noinput +arkindex collectstatic --noinput diff --git a/setup.py b/setup.py index 029ce5bd3ea5be7bf6d5f05e7b43a9d2a82d8ee4..7e4242e3a1fab4d0f867fbc70d4d665a8d634ea3 100755 --- a/setup.py +++ b/setup.py @@ -41,6 +41,7 @@ setup( packages=find_packages(), include_package_data=True, py_modules=["arkindex", ], + entry_points={"console_scripts": ["arkindex=arkindex.manage:main"]}, scripts=[ "arkindex/manage.py", ],