Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • arkindex/backend
1 result
Show changes
Commits on Source (2)
Showing
with 49 additions and 39 deletions
...@@ -58,7 +58,7 @@ backend-tests: ...@@ -58,7 +58,7 @@ backend-tests:
- test-report.xml - test-report.xml
script: script:
- arkindex/manage.py test - arkindex test
backend-lint: backend-lint:
image: python:3.10 image: python:3.10
...@@ -91,7 +91,7 @@ backend-migrations: ...@@ -91,7 +91,7 @@ backend-migrations:
alias: postgres alias: postgres
script: script:
- arkindex/manage.py makemigrations --check --noinput --dry-run -v 3 - arkindex makemigrations --check --noinput --dry-run -v 3
backend-openapi: backend-openapi:
extends: .backend-setup extends: .backend-setup
......
...@@ -19,10 +19,13 @@ RUN chown -R ark:teklia /backend_static ...@@ -19,10 +19,13 @@ RUN chown -R ark:teklia /backend_static
# Copy Version file # Copy Version file
COPY VERSION /etc/arkindex.version COPY VERSION /etc/arkindex.version
HEALTHCHECK --start-period=1m --interval=1m --timeout=5s \ ENV PORT 8000
CMD wget --spider --quiet http://localhost/api/v1/public-key/ || exit 1 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 # Run with Gunicorn
ENV PORT 8000
EXPOSE $PORT EXPOSE $PORT
CMD manage.py gunicorn --host=0.0.0.0 --port $PORT CMD arkindex gunicorn --host=0.0.0.0 --port $PORT
...@@ -16,7 +16,7 @@ build: ...@@ -16,7 +16,7 @@ build:
CI_PROJECT_DIR=$(ROOT_DIR) CI_REGISTRY_IMAGE=$(IMAGE_TAG) $(ROOT_DIR)/ci/build.sh CI_PROJECT_DIR=$(ROOT_DIR) CI_REGISTRY_IMAGE=$(IMAGE_TAG) $(ROOT_DIR)/ci/build.sh
worker: worker:
arkindex/manage.py rqworker -v 2 default high tasks arkindex rqworker -v 2 default high tasks
test-fixtures: test-fixtures:
$(eval export PGPASSWORD=devdata) $(eval export PGPASSWORD=devdata)
...@@ -27,9 +27,9 @@ test-fixtures: ...@@ -27,9 +27,9 @@ test-fixtures:
$(MAKE) test-fixtures-restore $(MAKE) test-fixtures-restore
test-fixtures-run: test-fixtures-run:
arkindex/manage.py migrate arkindex migrate
arkindex/manage.py build_fixtures arkindex build_fixtures
arkindex/manage.py dumpdata --indent 4 process documents images users auth ponos training > arkindex/documents/fixtures/data.json arkindex dumpdata --indent 4 process documents images users auth ponos training > arkindex/documents/fixtures/data.json
test-fixtures-restore: test-fixtures-restore:
# This first renaming ensures that arkindex_tmp_fixtures exists; we don't want to drop arkindex_dev without a backup # 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: ...@@ -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 @git rev-parse $(version) >/dev/null 2>&1 && (echo "Version $(version) already exists on local git repo !" && exit 1) || true
schema: schema:
./arkindex/manage.py spectacular --fail-on-warn --validate --file schema.yml arkindex spectacular --fail-on-warn --validate --file schema.yml
release: release:
$(eval version:=$(shell cat VERSION)) $(eval version:=$(shell cat VERSION))
......
...@@ -25,8 +25,8 @@ pip install -e .[test] ...@@ -25,8 +25,8 @@ pip install -e .[test]
When the [architecture](https://gitlab.teklia.com/arkindex/architecture) is running locally to provide required services: When the [architecture](https://gitlab.teklia.com/arkindex/architecture) is running locally to provide required services:
``` ```
arkindex/manage.py migrate arkindex migrate
arkindex/manage.py createsuperuser arkindex createsuperuser
``` ```
### Local configuration ### Local configuration
...@@ -55,7 +55,7 @@ local_imageserver_id: 999 ...@@ -55,7 +55,7 @@ local_imageserver_id: 999
Here is how to quickly create the ImageServer using the shell: Here is how to quickly create the ImageServer using the shell:
``` ```
backend/arkindex$ ./manage.py shell $ arkindex shell
>>> from arkindex.images.models import ImageServer >>> from arkindex.images.models import ImageServer
>>> ImageServer.objects.create(id=1, display_name='local', url='https://ark.localhost/iiif') >>> 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 ...@@ -81,7 +81,7 @@ At the root of the repository is a Makefile that provides commands for common op
### Django commands ### 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`); * `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; * `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 ...@@ -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. * `telegraf`: A special command with InfluxDB-compatible output for Grafana statistics.
* `move_lines_to_parents`: Moves element children to their geographical parents; * `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 ## Code validation
Once your code appears to be working on a local server, a few checks have to be performed: 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`. * **Migrations:** Ensure that all migrations have been created by typing `arkindex makemigrations`.
* **Unit tests:** Run `./manage.py test` to perform unit tests. * **Unit tests:** Run `arkindex 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. - 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 ### Linting
...@@ -123,11 +123,11 @@ If you want to run the full workflow on all the files: `pre-commit run -a`. ...@@ -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. 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 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 ``` python
SHELL_PLUS_POST_IMPORTS = [ 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 ...@@ -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: 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 ```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 ## Metrics
......
1.5.4 1.6.0-alpha4
...@@ -57,7 +57,7 @@ class Migration(migrations.Migration): ...@@ -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, elidable=True,
), ),
] ]
...@@ -34,7 +34,7 @@ class Migration(migrations.Migration): ...@@ -34,7 +34,7 @@ class Migration(migrations.Migration):
constraint=models.UniqueConstraint(models.F("url"), name="unique_imageserver_url"), 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, elidable=True,
), ),
] ]
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
import os import os
import sys import sys
if __name__ == "__main__":
def main():
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "arkindex.project.settings") os.environ.setdefault("DJANGO_SETTINGS_MODULE", "arkindex.project.settings")
try: try:
from django.core.management import execute_from_command_line from django.core.management import execute_from_command_line
...@@ -20,3 +21,8 @@ if __name__ == "__main__": ...@@ -20,3 +21,8 @@ if __name__ == "__main__":
) )
raise raise
execute_from_command_line(sys.argv) 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()
...@@ -42,7 +42,7 @@ class Migration(migrations.Migration): ...@@ -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, elidable=True,
), ),
# Remove the implicit LIKE index on Secret.name and make the unique constraint explicit # Remove the implicit LIKE index on Secret.name and make the unique constraint explicit
...@@ -70,7 +70,7 @@ class Migration(migrations.Migration): ...@@ -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, elidable=True,
), ),
# Remove the implicit LIKE index on Task.token and make the unique constraint explicit # Remove the implicit LIKE index on Task.token and make the unique constraint explicit
...@@ -101,7 +101,7 @@ class Migration(migrations.Migration): ...@@ -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, elidable=True,
), ),
] ]
...@@ -124,7 +124,7 @@ class Migration(migrations.Migration): ...@@ -124,7 +124,7 @@ class Migration(migrations.Migration):
SET workflow_id = process_id 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, elidable=True,
), ),
] ]
...@@ -35,7 +35,7 @@ class Migration(migrations.Migration): ...@@ -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, elidable=True,
), ),
# Remove the implicit LIKE index on Farm.seed and make the unique constraint explicit # Remove the implicit LIKE index on Farm.seed and make the unique constraint explicit
...@@ -63,7 +63,7 @@ class Migration(migrations.Migration): ...@@ -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, elidable=True,
), ),
# Remove the implicit LIKE index on Farm.seed and make the unique constraint explicit # Remove the implicit LIKE index on Farm.seed and make the unique constraint explicit
...@@ -94,7 +94,7 @@ class Migration(migrations.Migration): ...@@ -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, elidable=True,
), ),
] ]
...@@ -613,7 +613,7 @@ if DEBUG and not TEST_ENV: ...@@ -613,7 +613,7 @@ if DEBUG and not TEST_ENV:
try: try:
import django_extensions # noqa import django_extensions # noqa
INSTALLED_APPS.append("django_extensions") 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. # to no longer be able to log SQL queries.
# https://github.com/django-extensions/django-extensions/issues/1626#issuecomment-774698668 # https://github.com/django-extensions/django-extensions/issues/1626#issuecomment-774698668
LOGGING["loggers"]["django_extensions.management.commands.runserver_plus"] = { LOGGING["loggers"]["django_extensions.management.commands.runserver_plus"] = {
......
...@@ -12,7 +12,7 @@ class TestSchemaView(FixtureAPITestCase): ...@@ -12,7 +12,7 @@ class TestSchemaView(FixtureAPITestCase):
def test_constant_schema(self): def test_constant_schema(self):
""" """
Ensure that what a SchemaView outputs is always exactly the same 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 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", Python-specific objects, while PyYAML would use YAML tags such as "!!python/object",
......
...@@ -35,7 +35,7 @@ if "debug_toolbar" in settings.INSTALLED_APPS: ...@@ -35,7 +35,7 @@ if "debug_toolbar" in settings.INSTALLED_APPS:
] + urlpatterns ] + urlpatterns
if settings.DEBUG: 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()) urlpatterns.extend(staticfiles_urlpatterns())
# Add index.html using CDN assets # Add index.html using CDN assets
......
...@@ -35,7 +35,7 @@ class Migration(migrations.Migration): ...@@ -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, elidable=True,
), ),
] ]
#!/bin/sh -e #!/bin/sh -e
mkdir -p output mkdir -p output
pip install -e . pip install -e .
arkindex/manage.py spectacular --fail-on-warn --validate > output/schema.yml arkindex spectacular --fail-on-warn --validate > output/schema.yml
...@@ -2,4 +2,4 @@ ...@@ -2,4 +2,4 @@
mkdir -p static mkdir -p static
pip install -e . pip install -e .
echo "static: {root_path: '$(pwd)/static'}" >> "$CONFIG_PATH" echo "static: {root_path: '$(pwd)/static'}" >> "$CONFIG_PATH"
arkindex/manage.py collectstatic --noinput arkindex collectstatic --noinput
...@@ -41,6 +41,7 @@ setup( ...@@ -41,6 +41,7 @@ setup(
packages=find_packages(), packages=find_packages(),
include_package_data=True, include_package_data=True,
py_modules=["arkindex", ], py_modules=["arkindex", ],
entry_points={"console_scripts": ["arkindex=arkindex.manage:main"]},
scripts=[ scripts=[
"arkindex/manage.py", "arkindex/manage.py",
], ],
......