diff --git a/.github/workflows/deployment.yaml b/.github/workflows/deployment.yaml index 0bf6eb1d61..4f10a31cae 100644 --- a/.github/workflows/deployment.yaml +++ b/.github/workflows/deployment.yaml @@ -29,11 +29,11 @@ jobs: if: github.ref == 'refs/heads/production' runs-on: ubuntu-latest env: - DATABASE_URL: postgis://postgres:postgres@localhost:5432/care + DATABASE_URL: postgres://postgres:postgres@localhost:5432/care name: Test services: db: - image: postgis/postgis:latest + image: postgres:latest env: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres @@ -89,7 +89,7 @@ jobs: - name: Install dependencies run: | sudo apt-get update - sudo apt-get install binutils libproj-dev gdal-bin -y + sudo apt-get install binutils libproj-dev libjpeg-dev zlib1g-dev -y pip install --upgrade pip pip install -r requirements/local.txt diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 289785bc40..827b049dc8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -7,10 +7,10 @@ jobs: test: runs-on: ubuntu-latest env: - DATABASE_URL: postgis://postgres:postgres@localhost:5432/care + DATABASE_URL: postgres://postgres:postgres@localhost:5432/care services: db: - image: postgis/postgis:latest + image: postgres:latest env: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres @@ -51,7 +51,7 @@ jobs: - name: Install system packages run: | sudo apt-get update - sudo apt-get install binutils libproj-dev gdal-bin -y + sudo apt-get install binutils libproj-dev libjpeg-dev zlib1g-dev -y - name: Install CI dependencies run: | diff --git a/.gitignore b/.gitignore index 5a890d578c..37047ab020 100644 --- a/.gitignore +++ b/.gitignore @@ -152,7 +152,7 @@ typings/ ### VisualStudioCode template .vscode/* -!.vscode/settings.json +# !.vscode/settings.json !.vscode/tasks.json !.vscode/launch.json !.vscode/extensions.json @@ -344,12 +344,10 @@ care/media/* .envs/* !.envs/.local/ -.vscode -.idea/ test_db celerybeat-schedule config/settings/local.py -secrets.sh \ No newline at end of file +secrets.sh diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000000..67165ab0a1 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,30 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Docker: Django", + "type": "python", + "request": "attach", + "pathMappings": [ + { + "localRoot": "${workspaceFolder}", + "remoteRoot": "/app" + } + ], + "port": 9876, + "host": "127.0.0.1", + }, + { + "name": "Python: Django", + "type": "python", + "request": "launch", + "program": "${workspaceFolder}/manage.py", + "args": ["runserver"], + "django": true, + "justMyCode": false + }, + ] +} diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index b689b8dc6c..3a24ca699d 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -39,7 +39,7 @@ Troubleshooting Local Setup If you're on Mac and you have installed Postgres.app Run: `export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/14/bin` -If you're pip install is failing on Pillow Consider installing +If you're pip install is failing on Pillow Consider installing `brew install libjpeg libtiff little-cms2 openjpeg webp` @@ -147,16 +147,6 @@ Login to the postgres shell and run: You may replace `care` with the database name of your preference -You also might have to install PostGIS scripts. - -* Linux users can install PostGIS scripts by running :: - - $ sudo apt install postgresql--postgis-scripts - -* Windows users can install - - PostGIS through Application Stack Builder which is installed along PostgreSQL using standard PostgreSQL installer. - - OSGeo4W from this site_. - Then follow the steps listed here_. Setting up Pre-Commit @@ -218,8 +208,6 @@ In the virtualenv shell type the following commands also:: export DATABASE_URL=postgres://postgres:@127.0.0.1:5432/care - export TEST_POSTGIS_URL="postgis://postgres:@127.0.0.1:5432/care" - You may replace 'care' with the database you have created before. After doing this you can type the following command:: diff --git a/Dockerfile b/Dockerfile index 371e146641..987a053fc3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ ARG BUILD_ENVIRONMENT=production # Install apt packages RUN apt-get update && apt-get install --no-install-recommends -y \ # dependencies for building Python packages - build-essential libgdal-dev \ + build-essential libjpeg-dev zlib1g-dev \ # psycopg2 dependencies libpq-dev @@ -44,8 +44,6 @@ RUN addgroup --system django \ RUN apt-get update && apt-get install --no-install-recommends -y \ # psycopg2 dependencies libpq-dev \ - # PostGIS dependencies - libgdal-dev \ # Translations dependencies gettext \ # Msic diff --git a/config/settings/base.py b/config/settings/base.py index 310c3a8a9f..3dd1f1e66c 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -6,9 +6,6 @@ from datetime import timedelta import environ -from healthy_django.healthcheck.celery_queue_length import ( - DjangoCeleryQueueLengthHealthCheck, -) from healthy_django.healthcheck.django_cache import DjangoCacheHealthCheck from healthy_django.healthcheck.django_database import DjangoDatabaseHealthCheck @@ -53,7 +50,6 @@ DATABASES = {"default": env.db("DATABASE_URL", default="postgres:///care")} DATABASES["default"]["ATOMIC_REQUESTS"] = True -# DATABASES["default"]["ENGINE"] = "django.contrib.gis.db.backends.postgis" DATABASES["default"]["CONN_MAX_AGE"] = 300 # URLS @@ -424,8 +420,12 @@ def GETKEY(group, request): OTP_LENGTH = 5 # ICD -ICD_SCRAPER_ROOT_CONCEPTS_URL = "https://icd.who.int/browse11/l-m/en/JsonGetRootConcepts" -ICD_SCRAPER_CHILD_CONCEPTS_URL = "https://icd.who.int/browse11/l-m/en/JsonGetChildrenConcepts" +ICD_SCRAPER_ROOT_CONCEPTS_URL = ( + "https://icd.who.int/browse11/l-m/en/JsonGetRootConcepts" +) +ICD_SCRAPER_CHILD_CONCEPTS_URL = ( + "https://icd.who.int/browse11/l-m/en/JsonGetChildrenConcepts" +) # SMS USE_SMS = False diff --git a/config/settings/deployment.py b/config/settings/deployment.py index 6c4f580aeb..cc9908bd92 100644 --- a/config/settings/deployment.py +++ b/config/settings/deployment.py @@ -27,6 +27,7 @@ # DATABASES # ------------------------------------------------------------------------------ +# TODO: rename POSTGIS_URL to DATABASE_URL DATABASES["default"] = env.db("POSTGIS_URL") # noqa F405 DATABASES["default"]["ATOMIC_REQUESTS"] = True # noqa F405 DATABASES["default"]["CONN_MAX_AGE"] = env.int("CONN_MAX_AGE", default=60) # noqa F405 diff --git a/config/settings/local.py b/config/settings/local.py index 2597ab063d..288db0a97a 100644 --- a/config/settings/local.py +++ b/config/settings/local.py @@ -1,5 +1,3 @@ -import os - from .base import * # noqa from .base import env @@ -9,11 +7,19 @@ DEBUG = env.bool("DJANGO_DEBUG", True) ALLOWED_HOSTS = ["*"] # https://docs.djangoproject.com/en/dev/ref/settings/#secret-key -SECRET_KEY = env("DJANGO_SECRET_KEY", default="eXZQzOzx8gV38rDG0Z0fFZWweUGl3LwMZ9aTKqJiXQTI0nKMh0Z7sbHfqT8KFEnd",) +SECRET_KEY = env( + "DJANGO_SECRET_KEY", + default="eXZQzOzx8gV38rDG0Z0fFZWweUGl3LwMZ9aTKqJiXQTI0nKMh0Z7sbHfqT8KFEnd", +) # The first key will be used to encrypt all new data, and decryption of existing values will be attempted # with all given keys in order. This is useful for key rotation: place a new key at the head of the list # for use with all new or changed data, but existing values encrypted with old keys will still be accessible -FERNET_KEYS = [env("FERNET_SECRET_KEY_1", default="f685a83652d782188382a3f2696e623a764c8012b1488d2fc5bc6460cddc7878")] +FERNET_KEYS = [ + env( + "FERNET_SECRET_KEY_1", + default="f685a83652d782188382a3f2696e623a764c8012b1488d2fc5bc6460cddc7878", + ) +] # https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hostsRUNSERVER_PLUS_PRINT_SQL_TRUNCATE # CACHES @@ -64,19 +70,6 @@ # https://django-extensions.readthedocs.io/en/latest/installation_instructions.html#configuration INSTALLED_APPS += ["django_extensions"] # noqa F405 -# Required for gis on windows platform -# Make sure to install OSGeo4W from https://trac.osgeo.org/osgeo4w/ -if os.name == "nt": - import platform - - OSGEO4W = r"C:\OSGeo4W" - if "64" in platform.architecture()[0]: - OSGEO4W += "64" - assert os.path.isdir(OSGEO4W), "Directory does not exist: " + OSGEO4W - os.environ["OSGEO4W_ROOT"] = OSGEO4W - os.environ["GDAL_DATA"] = OSGEO4W + r"\share\gdal" - os.environ["PROJ_LIB"] = OSGEO4W + r"\share\proj" - os.environ["PATH"] = OSGEO4W + r"\bin;" + os.environ["PATH"] # Your stuff... # ------------------------------------------------------------------------------ @@ -94,8 +87,12 @@ # Simple JWT SIMPLE_JWT = { - "ACCESS_TOKEN_LIFETIME": timedelta(minutes=env("JWT_ACCESS_TOKEN_LIFETIME", default=1000000000)), - "REFRESH_TOKEN_LIFETIME": timedelta(minutes=env("JWT_REFRESH_TOKEN_LIFETIME", default=3000000000)), + "ACCESS_TOKEN_LIFETIME": timedelta( # noqa + minutes=env("JWT_ACCESS_TOKEN_LIFETIME", default=1000000000) + ), + "REFRESH_TOKEN_LIFETIME": timedelta( # noqa + minutes=env("JWT_REFRESH_TOKEN_LIFETIME", default=3000000000) + ), "ROTATE_REFRESH_TOKENS": True, } diff --git a/config/settings/test.py b/config/settings/test.py index 1739bc75e0..26b8c42676 100644 --- a/config/settings/test.py +++ b/config/settings/test.py @@ -60,7 +60,6 @@ DATABASES = {"default": env.db("DATABASE_URL", default="postgres:///care-test")} DATABASES["default"]["ATOMIC_REQUESTS"] = True -# DATABASES["default"]["ENGINE"] = "django.contrib.gis.db.backends.postgis" # https://whitenoise.evans.io/en/stable/django.html#whitenoise-makes-my-tests-run-slow WHITENOISE_AUTOREFRESH = True diff --git a/docker-compose.local.yaml b/docker-compose.local.yaml index 728d9daf95..7ffa9b4e4f 100644 --- a/docker-compose.local.yaml +++ b/docker-compose.local.yaml @@ -7,13 +7,18 @@ networks: services: db: container_name: care_db - image: postgres + image: postgres:latest restart: always env_file: - ./docker/.local.env volumes: - postgres-data:/var/lib/postgresql/data + redis: + container_name: care_redis + image: redis:alpine + restart: always + backend: container_name: care build: @@ -21,19 +26,15 @@ services: dockerfile: docker/DevDockerfile env_file: - ./docker/.local.env - command: python manage.py runserver 0.0.0.0:9000 + entrypoint: ["bash", "docker/docker-entrypoint.sh"] ports: - "9000:9000" + - "9876:9876" #debugpy depends_on: - db volumes: - .:/app - redis: - container_name: care_redis - image: redis:alpine - restart: always - celery: container_name: care_celery build: diff --git a/docker/.local.env b/docker/.local.env index 378691b893..0de74cbf10 100644 --- a/docker/.local.env +++ b/docker/.local.env @@ -1,12 +1,12 @@ -DEBUG=True POSTGRES_USER=postgres POSTGRES_PASSWORD=postgres POSTGRES_HOST=db POSTGRES_DB=care POSTGRES_PORT=5432 DATABASE_URL=postgres://postgres:postgres@db:5432/care -TEST_POSTGIS_URL=postgis://postgres:postgres@db:5432/care CELERY_BROKER_URL=redis://redis:6379/0 +DJANGO_DEBUG=False + FILE_UPLOAD_BUCKET=patient-bucket FACILITY_S3_BUCKET=facility-bucket diff --git a/docker/DevDockerfile b/docker/DevDockerfile index a122e4f459..0c0be777e9 100644 --- a/docker/DevDockerfile +++ b/docker/DevDockerfile @@ -1,17 +1,26 @@ -FROM python:3.8.9-slim-buster +FROM python:3.10-slim-bullseye # These two environment variables prevent __pycache__/ files. # since ipython is already present in required, you might as well use it ENV PYTHONUNBUFFERED 1 PYTHONDONTWRITEBYTECODE 1 PYTHONBREAKPOINT=ipython -RUN : \ - && apt-get update \ - && DEBIAN_FRONTEND=noninteractive apt-get install -y \ - --no-install-recommends \ - python3-dev \ - build-essential \ - && rm -rf /var/lib/apt/lists/* \ - &&: +# Install required system dependencies +RUN apt-get update && apt-get install --no-install-recommends -y \ + # dependencies for building Python packages + build-essential libjpeg-dev zlib1g-dev \ + # psycopg2 dependencies + libpq-dev \ + # Translations dependencies + gettext \ + # Msic + wget gnupg \ + # Install Chrome + && wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \ + && echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list \ + && apt-get update && apt-get -y install google-chrome-stable \ + # cleaning up unused files + && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \ + && rm -rf /var/lib/apt/lists/* # Copy the requirements folder to ensure they are cached COPY requirements ./requirements @@ -27,4 +36,4 @@ COPY . /app WORKDIR /app -ENTRYPOINT ["bash", "docker/docker-entrypoint.sh"] +# ENTRYPOINT ["bash", "docker/docker-entrypoint.sh"] diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh index 0b29d2ece4..74c6c62a81 100644 --- a/docker/docker-entrypoint.sh +++ b/docker/docker-entrypoint.sh @@ -6,4 +6,8 @@ python manage.py migrate echo "All migrations have been made successfully" -python manage.py runserver_plus 0.0.0.0:9000 +if ["${DJANGO_DEBUG,,}" == "true"]; then + python -m debugpy --wait-for-client --listen 0.0.0.0:9876 manage.py runserver_plus 0.0.0.0:9000 +else + python manage.py runserver 0.0.0.0:9000 +fi diff --git a/docs/local-setup/configuration.rst b/docs/local-setup/configuration.rst index c6ebf91092..e95efe2f10 100644 --- a/docs/local-setup/configuration.rst +++ b/docs/local-setup/configuration.rst @@ -10,22 +10,22 @@ There are two ways to run the development server: Using Docker Compose --------------------- - This setup will run 5 Docker containers: + This setup will run 5 Docker containers: - - PostGIS + - postgres (database) - care (main repo) - redis (in-memory cache) - celery (task queue) - localstack (to mimic AWS services locally) -This is the most recommended way of setting up care locally, -as it installs appropriate dependencies in containers so there -is no chance of conflicting dependencies. If you are running this +This is the most recommended way of setting up care locally, +as it installs appropriate dependencies in containers so there +is no chance of conflicting dependencies. If you are running this first time, it might take a while depending upon your internet speed and machine specs. - Steps to run the development server: - 1. Run the following command to start the development environment: + 1. Run the following command to start the development environment: .. code-block:: bash $ make up @@ -33,10 +33,10 @@ first time, it might take a while depending upon your internet speed and machine 2. Open a browser and go to `http://localhost:9000` -- To stop the development environment: +- To stop the development environment: .. code-block:: bash - $ make down + $ make down - To run tests: .. code-block:: bash @@ -66,7 +66,7 @@ Do the following steps to set up password authentication. sudo -u postgres psql -In the `postgres#` shell type:: +In the `postgres#` shell type:: \password postgres @@ -102,16 +102,6 @@ Login to the postgres shell and run: You may replace `care` with the database name of your preference -You also might have to install PostGIS scripts. - -* Linux users can install PostGIS scripts by running :: - - $ sudo apt install postgresql--postgis-scripts - -* Windows users can install - - PostGIS through Application Stack Builder which is installed along PostgreSQL using standard PostgreSQL installer. - - OSGeo4W from this site_. - Then follow the steps listed here_. Setting up Pre-Commit @@ -153,7 +143,7 @@ Setting Up Your Users $ python manage.py createsuperuser If the command prompts for username only and after entering if it goes to error -do make sure that you have done the following +do make sure that you have done the following Note: Make sure that you have created a database named `care` (replace thisw with your database name) with privileges set for the user `postgres` @@ -161,8 +151,6 @@ In the virtualenv shell type the following commands also:: export DATABASE_URL=postgres://postgres:@127.0.0.1:5432/care - export TEST_POSTGIS_URL="postgis://postgres:@127.0.0.1:5432/care" - You may replace **care** with the database you have created before. After doing this you can type the following command:: diff --git a/docs/working-components/configuration.rst b/docs/working-components/configuration.rst index 852cbdc9f9..2be911281a 100644 --- a/docs/working-components/configuration.rst +++ b/docs/working-components/configuration.rst @@ -17,7 +17,7 @@ The celery worker is used to asynchronously execute code, The summary jobs are a Database (PostgreSQL) --------------------- -Care uses a Postgresql database with the PostGIS plugin enabled, PostGIS is used in different contexts to store location information, it was used so that in a later context the application could intelligently suggest nearby locations to shift patients or do geo queries really quickly. +Care uses a Postgresql database. Cache (Redis) ------------- diff --git a/requirements/local.txt b/requirements/local.txt index 836e52ecc4..5cdbf4b94d 100644 --- a/requirements/local.txt +++ b/requirements/local.txt @@ -25,3 +25,4 @@ tblib==1.7.0 # https://github.com/ionelmc/python-tblib # ------------------------------- watchdog==0.10.2 argh==0.26.2 +debugpy==1.6.3