Skip to content

Commit

Permalink
Merge branch 'main' into feat-refactor-package
Browse files Browse the repository at this point in the history
  • Loading branch information
danangmassandy committed Aug 15, 2024
2 parents 9976eed + 7e081c6 commit 4e38dd8
Show file tree
Hide file tree
Showing 30 changed files with 744 additions and 129 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
- name: Run Coverage test
working-directory: deployment
run: |
cat << EOF | docker-compose exec -T dev bash
cat << EOF | docker compose exec -T dev bash
python manage.py makemigrations
python manage.py migrate
python manage.py collectstatic --noinput --verbosity 0
Expand Down
22 changes: 11 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ build:
@echo "------------------------------------------------------------------"
@echo "Building in production mode"
@echo "------------------------------------------------------------------"
@docker-compose build
@docker compose build

build-dev:
@echo
@echo "------------------------------------------------------------------"
@echo "Building in dev mode"
@echo "------------------------------------------------------------------"
@docker-compose build dev
@docker compose build dev

wait-db:
@docker-compose ${ARGS} exec -T db su - postgres -c "until pg_isready; do sleep 5; done"
@docker compose ${ARGS} exec -T db su - postgres -c "until pg_isready; do sleep 5; done"

sleep:
@echo
Expand All @@ -31,53 +31,53 @@ up:
@echo "------------------------------------------------------------------"
@echo "Running in production mode"
@echo "------------------------------------------------------------------"
@docker-compose ${ARGS} up -d nginx django worker celery_beat
@docker compose ${ARGS} up -d nginx django worker celery_beat

dev:
@echo
@echo "------------------------------------------------------------------"
@echo "Running in dev mode"
@echo "------------------------------------------------------------------"
@docker-compose ${ARGS} up -d dev worker
@docker compose ${ARGS} up -d dev worker

down:
@echo
@echo "------------------------------------------------------------------"
@echo "Running in dev mode"
@echo "------------------------------------------------------------------"
@docker-compose ${ARGS} down
@docker compose ${ARGS} down

migrate:
@echo
@echo "------------------------------------------------------------------"
@echo "Running migration"
@echo "------------------------------------------------------------------"
@docker-compose ${ARGS} exec -T dev python manage.py migrate
@docker compose ${ARGS} exec -T dev python manage.py migrate

dev-runserver:
@echo
@echo "------------------------------------------------------------------"
@echo "Start django runserver in dev container"
@echo "------------------------------------------------------------------"
@docker-compose $(ARGS) exec -T dev bash -c "nohup python manage.py runserver 0.0.0.0:8080 &"
@docker compose $(ARGS) exec -T dev bash -c "nohup python manage.py runserver 0.0.0.0:8080 &"

dev-shell:
@echo
@echo "------------------------------------------------------------------"
@echo "Start django runserver in dev container"
@echo "------------------------------------------------------------------"
@docker-compose $(ARGS) exec dev bash
@docker compose $(ARGS) exec dev bash

scale-worker:
@echo
@echo "------------------------------------------------------------------"
@echo "scale-worker"
@echo "------------------------------------------------------------------"
@docker-compose up -d worker --no-deps --no-recreate --scale worker=$(COUNT)
@docker compose up -d worker --no-deps --no-recreate --scale worker=$(COUNT)

init-bucket:
@echo
@echo "------------------------------------------------------------------"
@echo "Init createbuckets Minio"
@echo "------------------------------------------------------------------"
@docker-compose ${ARGS} up -d createbuckets
@docker compose ${ARGS} up -d createbuckets
38 changes: 1 addition & 37 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,4 @@
# 🚀 Kartoza Django React

A boilerplate for kickstarting Kartoza Django backend and React frontend projects

## 🌟 Features
- Django backend with Django Rest Framework (DRF) for API development
- React frontend with Redux for state management
- Webpack configurations for modern JavaScript (ES6+) support
- Responsive design with [MUI](https://mui.com/)
- Docker and docker-compose support for containerization
- Code linting with ESLint and Prettier (frontend) and flake8 (backend)

## ⚡ Quick Start


- Clone the repository
```
git clone https://github.com/kartoza/django-react-base.git
cd django-react-base
```

- Copy and customize the environment file and the Docker Compose override file from the template.
```
cp deployment/.template.env deployment/.env
cp deployment/docker-compose.override.template.yml deployment/docker-compose.override.yml
```

- Build the project using the provided command in makefile
```
make build
```

- Run the application using Docker and the provided makefile
```
make run
```

# CPLUS API for CPLUS QGIS PLUGIN

## 📚 Documentation
For detailed setup instructions, custom configurations, deployment, and additional features, please refer to the wiki.
Expand Down
2 changes: 1 addition & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ coverage:
changes: false
patch:
default:
threshold: "5%"
threshold: "10%"
ignore:
- "**/migrations/*.py"
11 changes: 9 additions & 2 deletions django_project/core/models/base_task_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ class BaseTaskRequest(models.Model):
blank=True
)

stack_trace_errors = models.TextField(
null=True,
blank=True
)

progress = models.FloatField(
null=True,
blank=True
Expand Down Expand Up @@ -212,11 +217,13 @@ def task_on_errors(self, exception=None, traceback=None):
except Exception:
if isinstance(traceback, str):
ex_msg += str(traceback) + '\n'
self.errors = ex_msg
self.errors = str(exception) + '\n'
self.stack_trace_errors = ex_msg
self.add_log('Task is stopped with errors.', logging.ERROR)
self.add_log(str(exception), logging.ERROR)
self.save(
update_fields=['last_update', 'status', 'errors']
update_fields=['last_update', 'status',
'errors', 'stack_trace_errors']
)

def task_on_retried(self, reason):
Expand Down
3 changes: 2 additions & 1 deletion django_project/core/settings/contrib.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
'DEFAULT_VERSIONING_CLASS': (
'rest_framework.versioning.NamespaceVersioning'
),
'EXCEPTION_HANDLER': 'core.tools.custom_exception_handler'
'EXCEPTION_HANDLER': 'core.tools.custom_exception_handler',
'DATETIME_FORMAT': '%Y-%m-%dT%H:%M:%SZ'
}

AUTHENTICATION_BACKENDS = (
Expand Down
16 changes: 13 additions & 3 deletions django_project/core/settings/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
import os # noqa

from django.db import connection
from boto3.s3.transfer import TransferConfig
from .contrib import * # noqa
from .utils import code_release_version
from .utils import code_release_version, code_commit_release_version

ALLOWED_HOSTS = ['*']
ADMINS = (
Expand Down Expand Up @@ -42,16 +43,24 @@
)

CODE_RELEASE_VERSION = code_release_version()
CODE_COMMIT_HASH = code_commit_release_version()

# s3
# TODO: set CacheControl in object_parameters+endpoint_url
MB = 1024 ** 2
AWS_TRANSFER_CONFIG = TransferConfig(
multipart_chunksize=512 * MB,
use_threads=True,
max_concurrency=10
)
STORAGES = {
"default": {
"BACKEND": "storages.backends.s3.S3Storage",
"OPTIONS": {
"bucket_name": os.environ.get("AWS_S3_BUCKET_NAME"),
"file_overwrite": False,
"max_memory_size": 300 * 1024 * 1024, # 300MB
"max_memory_size": 300 * MB, # 300MB
"transfer_config": AWS_TRANSFER_CONFIG
},
},
"staticfiles": {
Expand All @@ -62,7 +71,8 @@
"OPTIONS": {
"bucket_name": os.environ.get("MINIO_BUCKET_NAME"),
"file_overwrite": False,
"max_memory_size": 300 * 1024 * 1024, # 300MB
"max_memory_size": 300 * MB, # 300MB,
"transfer_config": AWS_TRANSFER_CONFIG
},
},
}
10 changes: 10 additions & 0 deletions django_project/core/settings/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ def code_release_version():
return '0.0.1'


def code_commit_release_version():
""" Read code commit release version from file."""
version = absolute_path('version', 'commit.txt')
if os.path.exists(version):
commit = (open(version, 'rb').read()).decode("utf-8")
if commit:
return commit
return 'no-info'


class UUIDEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, uuid.UUID):
Expand Down
Loading

0 comments on commit 4e38dd8

Please sign in to comment.