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

Uipa containerization #105

Merged
merged 8 commits into from
Aug 30, 2024
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
29 changes: 29 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM ssthapa/django4:0.2

LABEL maintainer="Suchandra Thapa <[email protected]>"

ENV PYTHONFAULTHANDLER=1 \
PYTHONUNBUFFERED=1 \
PYTHONHASHSEED=random \
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100


COPY pyproject.toml /srv/django/pyproject.toml

RUN apk update && \
apk add rust cargo qpdf qpdf-dev poppler poppler-dev g++ gdal geos alpine-sdk \
imagemagick imagemagick-dev pango nodejs npm yarn

ENV PYTHONPATH="${PYTHONPATH}:/srv/django"
WORKDIR /srv/django
COPY . /srv/django
RUN /root/.local/bin/poetry config installer.max-workers 1
RUN /root/.local/bin/poetry install --no-root --no-interaction


COPY run-backend.sh /srv/django

ENTRYPOINT ["/srv/django/run-backend.sh"]
#ENTRYPOINT ["/bin/sleep", "3600"]
56 changes: 56 additions & 0 deletions docker-compose.local.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
services:
app:
image: uipa_backend:0.10
volumes:
- .:/app
environment:
- "DATABASE_URL=postgis://froide:froide@db:5432/froide"
- "DJANGO_ELASTICSEARCH_HOST=elasticsearch"
- "DJANGO_ELASTICSEARCH_USER=elastic"
- "DJANGO_ELASTICSEARCH_PASSWORD=froide"
- "GDAL_LIBRARY_PATH=/usr/lib/libgdal.so.34"
- "GEOS_LIBRARY_PATH=/usr/lib/libgeos_c.so.1"
ports:
- "8000:8000"
networks:
uipa: {}
depends_on:
- db
- elasticsearch
db:
image: postgis/postgis:14-3.1
platform: linux/amd64
volumes:
- ./data/postgres_data:/var/lib/postgresql/data/:Z
environment:
POSTGRES_USER: froide
POSTGRES_DB: froide
POSTGRES_PASSWORD: froide
ports:
- "127.0.0.1:5432:5432"
networks:
uipa: {}
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.15.0
platform: linux/amd64
volumes:
- es-data:/usr/share/elasticsearch/data:Z
- es-logs:/var/log:Z
environment:
- "discovery.type=single-node"
- "xpack.security.enabled=true"
- "ELASTIC_PASSWORD=froide"
- "cluster.routing.allocation.disk.threshold_enabled=false"
- "cluster.routing.allocation.disk.watermark.low=3gb"
- "cluster.routing.allocation.disk.watermark.high=2gb"
- "cluster.routing.allocation.disk.watermark.flood_stage=1gb"
ports:
- "127.0.0.1:9200:9200"
networks:
uipa: {}
volumes:
es-data: {}
es-logs: {}
pg-data: {}
networks:
uipa: {}
4,299 changes: 4,299 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

92 changes: 92 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
[tool.poetry]
name = "uipa"
version = "0.1.0"
description = "Uipa.org django container pyproject"
authors = ["Suchandra Thapa <[email protected]>"]
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.10"
Django = "~=4.2"
bleach = "^6.1.0"
celery = ">=5.2.2"
channels = "^4.0.0"
coreapi = "^2.3.3"
dj-database-url = "^2.1.0"
django-celery-beat = "^2.6.0"
django-celery-email = "^3.0.0"
django-configurations = "^2.5"
django-contrib-comments = "^2.2.0"
django-crossdomainmedia = ">=0.0.4"
django-elasticsearch-dsl = ">=8.0,<9.0"
django-filter = "^23.5"
django-floppyforms = "~1.9.0"
django-fsm = "^2.8.1"
django-json-widget = "^1.1.1"
django-leaflet = "^0.29.0"
django-mfa3 = "^0.11.0"
django-oauth-toolkit = "<2.0.0"
django-parler = "^2.3"
django-storages = "^1.14.2"
django-taggit = ">=2"
django-treebeard = "^4.7.1"
djangorestframework = "^3.14.0"
djangorestframework-csv = "^3.0.2"
djangorestframework-jsonp = "^1.0.2"
drf-spectacular = {extras = ["sidecar"], version = "^0.27.1"}
easy-thumbnails = "^2.8.5"
elasticsearch-dsl = ">=8.0.0,<9.0.0"
elasticsearch = ">=8.0.0,<9.0.0"
froide = {git = "https://github.com/codewithaloha/froide.git", rev = "container_fixes"}
geoip2 = "^4.8.0"
icalendar = "^5.0.11"
lxml = ">=4.6.5"
markdown = "^3.5.2"
phonenumbers = "^8.13.31"
pillow = ">=9.0.0"
psycopg = {version = ">=3.1.8", extras = ["binary"]}
pyisemail = "^2.0.1"
pypdf = ">=3"
python-magic = "^0.4.27"
python-mimeparse = "^1.6.0"
python-slugify = "^8.0.4"
reportlab = "^4.1.0"
requests = "^2.31.0"
wand = "^0.6.13"
weasyprint = "^61.1"
websockets = "^12.0"
pikepdf = "7.0.0"
django-filingcabinet = {git = "https://github.com/okfde/django-filingcabinet.git", rev = "main"}
pygtail = {git = "https://github.com/okfde/pygtail.git", rev = "3be17b00f55781caba62d589bcf8aceb0805a58c"}

[tool.poetry.group.test.dependencies]
beautifulsoup4 = "^4.12.3"
black = "^24.2.0"
coverage = "^7.4.3"
django-coverage-plugin = "^3.1.0"
django-stubs = "^4.2.7"
factory-boy = "^3.3.0"
faker = "^23.3.0"
flake8 = "^7.0.0"
flake8-bugbear = "^24.2.6"
isort = "^5.13.2"
monkeytype = "^23.3.0"
mypy = "^1.8.0"
pbr = "^6.0.0"
pre-commit = "^3.6.2"
pycodestyle = "^2.11.1"
pyflakes = "^3.2.0"
pytest-django = "^4.8.0"
pytest-factoryboy = "^2.6.0"
tblib = "^3.0.0"
text-unidecode = "^1.3"
time-machine = "^2.13.0"
types-markdown = "^3.5.0.20240129"
types-python-dateutil = "^2.8.19.20240106"
types-requests = "^2.31.0.20240218"
django-configurations = "^2.5"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
36 changes: 0 additions & 36 deletions requirements.txt

This file was deleted.

19 changes: 19 additions & 0 deletions run-backend.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/ash


#yarn link
yarn install
yarn build
yarn serve dev &

# hack until we get the froide setup build working (i.e. include templates)
echo "STARTING DB"
# To initialise the database:
/root/.local/bin/poetry run ./manage.py migrate --skip-checks
# Create a superuser
/root/.local/bin/poetry run ./manage.py createsuperuser
russtoku marked this conversation as resolved.
Show resolved Hide resolved
# Create and populate search index
/root/.local/bin/poetry run ./manage.py search_index --create
/root/.local/bin/poetry run ./manage.py search_index --populate

/root/.local/bin/poetry run /bin/ash /srv/django/run-django.sh
4 changes: 4 additions & 0 deletions run-django.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/ash

#python ./manage.py diffsettings --all
python ./manage.py runserver 0.0.0.0:8000
11 changes: 11 additions & 0 deletions setup-uipa.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/ash

export GDAL_LIBRARY_PATH='/usr/lib/libgdal.so.34'
export GEOS_LIBRARY_PATH='/usr/lib/libgeos_c.so.1'

python ./manage.py migrate --skip-checks
# Create a superuser
python ./manage.py createsuperuser
# Create and populate search index
python ./manage.py search_index --create
python ./manage.py search_index --populate
2 changes: 1 addition & 1 deletion uipa_org/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def FROIDE_CONFIG(self):
request_public_after_due_days=14,
payment_possible=False,
default_law=1,
greetings=[rec(u"Aloha (?:Mr\.?|Ms\.? .*?)")],
greetings=[rec(u"Aloha (?:Mr.|Ms. .*?)")],
closings=[rec(u"Mahalo,?")],
public_body_boosts={},
dryrun=False,
Expand Down
20 changes: 16 additions & 4 deletions uipa_org/settings/development.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import

from configurations import values
from setuptools.msvc import environ

from .base import UipaOrgThemeBase, env, required_env

class Dev(UipaOrgThemeBase):
Expand All @@ -12,12 +15,21 @@ class Dev(UipaOrgThemeBase):

CACHES = {"default": {"BACKEND": "django.core.cache.backends.dummy.DummyCache"}}

# setup GDAL and GEOS
GDAL_LIBRARY_PATH = values.Value('/usr/lib/libgdal.so.34', environ=True, environ_name="GDAL_LIBRARY_PATH",
environ_prefix="")
GEOS_LIBRARY_PATH = values.PathValue('/usr/lib/libgeos_c.so.1', environ=True, environ_name="GEOS_LIBRARY_PATH",
environ_prefix="")

ELASTICSEARCH_HOST = values.Value("localhost", environ=True, environ_name="ELASTICSEARCH_HOST")
ELASTICSEARCH_USER = values.Value("elastic", environ=True, environ_name="ELASTICSEARCH_USER")
ELASTICSEARCH_PASSWORD = values.Value("****", environ=True, environ_name="ELASTICSEARCH_PASSWORD")
russtoku marked this conversation as resolved.
Show resolved Hide resolved
ELASTICSEARCH_DSL = {
'default': {
'hosts': 'http://localhost:9200',
'http_auth': ('elastic', 'froide')
}
"default": {
"hosts": "http://%s:9200" % ELASTICSEARCH_HOST,
'http_auth': (ELASTICSEARCH_USER, ELASTICSEARCH_PASSWORD)
}
}

@property
def TEMPLATES(self):
Expand Down