Skip to content

Commit

Permalink
initial project setup for api and worker
Browse files Browse the repository at this point in the history
  • Loading branch information
danangmassandy committed Mar 1, 2024
1 parent 419c1d4 commit 3178e26
Show file tree
Hide file tree
Showing 122 changed files with 702 additions and 20,014 deletions.
29 changes: 14 additions & 15 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
{
"name": "Django Docker Environment",
"remoteUser": "vscode",
// "remoteUser": "vscode",
"postCreateCommand": "git config --global --add safe.directory /home/web/project",
"dockerComposeFile": [
"../deployment/docker-compose.yml",
"../deployment/docker-compose.override.devcontainer.yml"
],
"service": "dev",
"runServices": ["db", "redis", "celery_beat", "worker","dev"],
"workspaceFolder": "/home/web/project",
"settings": {
"terminal.integrated.shell.linux": "/bin/bash",
"python.pythonPath": "/usr/local/bin/python",
"python.linting.pylintEnabled": true,
"python.linting.enabled": true
},
"runArgs": [
"--env-file",
"../deployment/.env"
],
"portsAttributes": {
"9000": {
"label": "Frontend",
"onAutoForward": "notify"
"forwardPorts": [8000],
"shutdownAction": "stopCompose",
"customizations": {
"vscode": {
"extensions": ["ms-python.python", "ms-azuretools.vscode-docker"],
"settings": {
"terminal.integrated.shell.linux": "/bin/bash",
"python.pythonPath": "/usr/local/bin/python",
"python.linting.pylintEnabled": true,
"python.linting.enabled": true
}
}
},
"forwardPorts": [8000, 9000],
"extensions": ["ms-python.python", "ms-azuretools.vscode-docker"],
"shutdownAction": "stopCompose"
}
}
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ coverage.xml

django_project/.env
django_project/tmp/
django_project/frontend/bundles/
django_project/frontend/stats.json

docs/site/*
docks/mkdocs.yml
Expand Down
7 changes: 0 additions & 7 deletions .run/DJANGO+REACT.run.xml

This file was deleted.

27 changes: 0 additions & 27 deletions .run/Run Server.run.xml

This file was deleted.

12 changes: 0 additions & 12 deletions .run/serve.run.xml

This file was deleted.

24 changes: 0 additions & 24 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,6 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch Chrome",
"request": "launch",
"type": "chrome",
"url": "http://localhost:8000",
"webRoot": "${workspaceFolder}/django_project/frontend",
"sourceMapPathOverrides": {
"webpack:///./src/*": "${webRoot}/*"
}
},
{
"name": "Django: Run server",
"type": "python",
Expand All @@ -24,20 +14,6 @@
],
"django": true,
"justMyCode": true,
},
{
"command": "npm run serve",
"name": "React: Run webpack-dev-server",
"request": "launch",
"type": "node-terminal",
"cwd": "${workspaceFolder}/django_project/frontend",
},
],
"compounds": [
{
"name": "Django + React",
"configurations": ["Django: Run server", "React: Run webpack-dev-server"],
"stopAll": true
}
]
}
11 changes: 11 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"git.enableCommitSigning": true,
"python.testing.pytestArgs": [
"django_project",
"-s",
"-c",
"${workspaceFolder}/django_project/pytest.ini"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
21 changes: 0 additions & 21 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,6 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "React: Install dependencies",
"type": "shell",
"command": "npm install",
"options": {
"cwd": "${workspaceFolder}/django_project/frontend"
},
"group": "build",
"problemMatcher": []
},
{
"label": "React: Webpack-dev-server",
"type": "shell",
"command": "npm run serve",
"port": 9000,
"options": {
"cwd": "${workspaceFolder}/django_project/frontend"
},
"group": "build",
"problemMatcher": []
},
{
"label": "Django: Migrate",
"type": "shell",
Expand Down
7 changes: 0 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,3 @@ dev:
@echo "------------------------------------------------------------------"
@docker-compose ${ARGS} up -d dev worker
@docker-compose ${ARGS} up --no-recreate --no-deps -d

serve:
@echo
@echo "------------------------------------------------------------------"
@echo "Execute webpack serve command"
@echo "------------------------------------------------------------------"
@docker-compose ${ARGS} exec -T dev npm --prefix /home/web/django_project/frontend run serve
2 changes: 1 addition & 1 deletion deployment/.template.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
COMPOSE_PROJECT_NAME=kartoza_django_project
COMPOSE_PROJECT_NAME=cplus_api
DJANGO_SETTINGS_MODULE=core.settings.dev
DATABASE_NAME=django
DATABASE_USERNAME=docker
Expand Down
30 changes: 15 additions & 15 deletions deployment/docker-compose.override.devcontainer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,32 @@ services:
volumes:
- ./volumes/database:/opt/postgres/data
- ./volumes/backups:/backups
ports:
- "${DATABASE_PORT:-7432}:5432"

dbbackups:
volumes:
- ./volumes/backups:/backups

worker:
image: kartoza/${COMPOSE_PROJECT_NAME:-django_project}_dev
image: kartoza/${COMPOSE_PROJECT_NAME:-django_project}_worker_dev
build:
context: ../
dockerfile: deployment/docker/Dockerfile
target: vscode
target: worker
volumes:
- ../:/home/web/project
- ./volumes/static:/home/web/static
- ./volumes/media:/home/web/media
- ../django_project:/home/web/django_project

celery_beat:
image: kartoza/${COMPOSE_PROJECT_NAME:-django_project}_worker_dev
build:
context: ../
dockerfile: deployment/docker/Dockerfile
target: worker
volumes:
- ../:/home/web/project
- ../django_project:/home/web/django_project

dev:
image: kartoza/${COMPOSE_PROJECT_NAME:-django_project}_dev
Expand All @@ -34,14 +45,3 @@ services:
links:
- db
- worker

django:
build:
context: ../
dockerfile: deployment/docker/Dockerfile
target: vscode
volumes:
- ../django_project:/home/web/django_project
- ./volumes/static:/home/web/static
- ./volumes/media:/home/web/media

14 changes: 5 additions & 9 deletions deployment/docker-compose.override.template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
- ./volumes/database:/opt/postgres/data
- ./volumes/backups:/backups
ports:
- "${DB_PORT:-6432}:5432"
- "${DB_PORT:-7432}:5432"

dbbackups:
volumes:
Expand All @@ -21,23 +21,19 @@ services:
- ./volumes/static:/home/web/static
- ./volumes/media:/home/web/media

celery_beat:
volumes:
- ../django_project:/home/web/django_project

worker:
image: kartoza/django_react_base_dev
build:
context: ../
dockerfile: deployment/docker/Dockerfile
target: dev
volumes:
- ../django_project:/home/web/django_project
- ./volumes/static:/home/web/static
- ./volumes/media:/home/web/media

dev:
build:
context: ../
dockerfile: deployment/docker/Dockerfile
target: dev
command: python -m debugpy --listen 0.0.0.0:5678 --wait manage.py runserver 0.0.0.0:8000
volumes:
- ../django_project:/home/web/django_project
- ./volumes/static:/home/web/static
Expand Down
41 changes: 34 additions & 7 deletions deployment/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version: '3.9'
name: 'cplus'

volumes:
static-data:
Expand Down Expand Up @@ -26,24 +27,24 @@ x-common-django:
- CSRF_TRUSTED_ORIGINS=${CSRF_TRUSTED_ORIGINS:-[]}
- SENTRY_ENVIRONMENT=${SENTRY_ENVIRONMENT:-production}
- SENTRY_DSN=${SENTRY_DSN:-}

# Email where alters should be sent. This will be used by let's encrypt and as the django admin email.
- ADMIN_USERNAME=${ADMIN_USERNAME:-admin}
- ADMIN_PASSWORD=${ADMIN_PASSWORD:-admin}
- ADMIN_EMAIL=${ADMIN_EMAIL:[email protected]}
volumes:
- static-data:/home/web/static
- media-data:/home/web/media
# worker variables
- CPLUS_QUEUE_CONCURRENCY=${CPLUS_QUEUE_CONCURRENCY:-1}
restart: on-failure

services:
redis:
image: bitnami/redis:7.0.2
container_name: "cplus_api_redis"
environment:
- REDIS_PASSWORD=${REDIS_PASSWORD:-redis_password}

db:
image: kartoza/postgis:14-3.3
container_name: "cplus_api_db"
volumes:
- data-volume:/opt/postgres/data
environment:
Expand All @@ -55,10 +56,11 @@ services:

dbbackups:
image: kartoza/pg-backup:14-3.3
container_name: "cplus_api_dbbackups"
environment:
# take care to let the project name below match that
# declared in the top of the makefile
- DUMPPREFIX=PG_GeoSight
- DUMPPREFIX=PG_Cplus_API
# These are all defaults anyway, but setting explicitly in
# case we ever want to ever use different credentials
- POSTGRES_USER=${DATABASE_USERNAME:-docker}
Expand All @@ -73,24 +75,49 @@ services:

django:
<<: *default-common-django
container_name: "cplus_api_django"
command: 'uwsgi --ini /uwsgi.conf'
volumes:
- static-data:/home/web/static
- media-data:/home/web/media
links:
- db
- redis
- worker

worker:
celery_beat:
<<: *default-common-django
container_name: "cplus_api_celery_beat"
entrypoint: []
command: 'celery -A core worker -l info'
command: 'celery -A core beat --loglevel=info --scheduler django_celery_beat.schedulers:DatabaseScheduler'
links:
- db
- redis

worker:
<<: *default-common-django
container_name: "cplus_api_worker"
entrypoint: []
command: '/bin/bash -c /home/web/django_project/worker_entrypoint.sh'
links:
- celery_beat

dev:
image: kartoza/${COMPOSE_PROJECT_NAME:-django_project}_dev
<<: *default-common-django
container_name: "cplus_api_dev_django"
entrypoint: []
volumes:
- static-data:/home/web/static
- media-data:/home/web/media
links:
- db
- redis
- worker

nginx:
image: nginx
container_name: "cplus_api_nginx"
hostname: nginx
volumes:
- conf-data:/etc/nginx/conf.d:ro
Expand Down
Loading

0 comments on commit 3178e26

Please sign in to comment.