Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup postgis dependencies #1009

Merged
merged 4 commits into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: |
Expand Down
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ typings/

### VisualStudioCode template
.vscode/*
!.vscode/settings.json
# !.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
Expand Down Expand Up @@ -344,12 +344,10 @@ care/media/*
.envs/*
!.envs/.local/

.vscode
.idea/
test_db

celerybeat-schedule

config/settings/local.py

secrets.sh
secrets.sh
30 changes: 30 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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
},
]
}
14 changes: 1 addition & 13 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down Expand Up @@ -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-<version>-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
Expand Down Expand Up @@ -218,8 +208,6 @@ In the virtualenv shell type the following commands also::

export DATABASE_URL=postgres://postgres:<password>@127.0.0.1:5432/care

export TEST_POSTGIS_URL="postgis://postgres:<password>@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::
Expand Down
4 changes: 1 addition & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions config/settings/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 16 additions & 19 deletions config/settings/local.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import os

from .base import * # noqa
from .base import env

Expand All @@ -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
Expand Down Expand Up @@ -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...
# ------------------------------------------------------------------------------
Expand All @@ -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,
}

Expand Down
1 change: 0 additions & 1 deletion config/settings/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 8 additions & 7 deletions docker-compose.local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,34 @@ 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:
context: .
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:
Expand Down
4 changes: 2 additions & 2 deletions docker/.local.env
Original file line number Diff line number Diff line change
@@ -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
29 changes: 19 additions & 10 deletions docker/DevDockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -27,4 +36,4 @@ COPY . /app

WORKDIR /app

ENTRYPOINT ["bash", "docker/docker-entrypoint.sh"]
# ENTRYPOINT ["bash", "docker/docker-entrypoint.sh"]
6 changes: 5 additions & 1 deletion docker/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading