Skip to content

Commit

Permalink
Merge pull request #245 from unicef-drp/feat-logto-file
Browse files Browse the repository at this point in the history
redirect logs to file
  • Loading branch information
danangmassandy authored Nov 13, 2024
2 parents 0d7d1b1 + 2156b09 commit 7f49441
Show file tree
Hide file tree
Showing 16 changed files with 255 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ test-azure:
@echo "------------------------------------------------------------------"
@echo "Run Azure production instance"
@echo "------------------------------------------------------------------"
@docker compose ${ARGS} up -d azurite django auth worker celery_beat nginx
@docker compose ${ARGS} up -d azurite django auth worker celery_beat nginx logrotate

# below commands are executed already from django entrypoint+initialize.py
# @docker compose ${ARGS} exec -T django python manage.py migrate
Expand Down
5 changes: 5 additions & 0 deletions deployment/.template.env
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,8 @@ TEGOLA_CONCURRENCY=2
AZURE_STORAGE=
# Azure container name
AZURE_STORAGE_CONTAINER=

# log rotate
LOGROTATE_COPIES=14
LOGROTATE_SIZE=100M
LOGROTATE_INTERVAL=daily
16 changes: 16 additions & 0 deletions deployment/docker-compose.azure.override.devcontainer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ services:
ports:
- "5432:5432"

redis:
volumes:
# fix redis permission issue because it's using user redis (1001)
# sudo chown -R 1001:1001 ./volumes/tmp_data/redis
- ./volumes/tmp_data/redis:/tmp
- ./redis/redis.conf:/opt/bitnami/redis/mounted-etc/overrides.conf

worker:
image: kartoza/georepo_dev
build:
Expand All @@ -19,6 +26,7 @@ services:
- ./volumes/static:/home/web/static
- ./volumes/media:/home/web/media
- ./volumes/tegola_config:/opt/tegola_config
- ./volumes/tmp_data/worker:/tmp
links:
- db
- azurite
Expand All @@ -35,6 +43,7 @@ services:
- ./volumes/static:/home/web/static
- ./volumes/media:/home/web/media
- ./volumes/tegola_config:/opt/tegola_config
- ./volumes/tmp_data/celery_beat:/tmp

dev:
image: kartoza/georepo_dev
Expand All @@ -49,6 +58,8 @@ services:
- ./volumes/static:/home/web/static
- ./volumes/media:/home/web/media
- ./volumes/tegola_config:/opt/tegola_config
- ./volumes/tmp_data/django:/tmp
- ./volumes/tmp_data:/home/web/logs
links:
- db
- worker
Expand All @@ -61,3 +72,8 @@ services:
- ./volumes/azurite:/opt/azurite/data
ports:
- 10000:10000

logrotate:
volumes:
- ./volumes/tmp_data:/logs
- ./volumes/tmp_data/logrotate:/tmp
16 changes: 16 additions & 0 deletions deployment/docker-compose.override.devcontainer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ services:
ports:
- "5432:5432"

redis:
volumes:
# fix redis permission issue because it's using user redis (1001)
# sudo chown -R 1001:1001 ./volumes/tmp_data/redis
- ./volumes/tmp_data/redis:/tmp
- ./redis/redis.conf:/opt/bitnami/redis/mounted-etc/overrides.conf

worker:
image: kartoza/georepo_dev
build:
Expand All @@ -19,6 +26,7 @@ services:
- ./volumes/media:/home/web/media
- ./volumes/tegola_config:/opt/tegola_config
- ./volumes/layer_tiles:/opt/layer_tiles
- ./volumes/tmp_data/worker:/tmp

celery_beat:
image: kartoza/georepo_dev
Expand All @@ -32,6 +40,7 @@ services:
- ./volumes/media:/home/web/media
- ./volumes/tegola_config:/opt/tegola_config
- ./volumes/layer_tiles:/opt/layer_tiles
- ./volumes/tmp_data/celery_beat:/tmp

dev:
image: kartoza/georepo_dev
Expand All @@ -46,3 +55,10 @@ services:
- ./volumes/media:/home/web/media
- ./volumes/tegola_config:/opt/tegola_config
- ./volumes/layer_tiles:/opt/layer_tiles
- ./volumes/tmp_data/django:/tmp
- ./volumes/tmp_data:/home/web/logs

logrotate:
volumes:
- ./volumes/tmp_data:/logs
- ./volumes/tmp_data/logrotate:/tmp
19 changes: 19 additions & 0 deletions deployment/docker-compose.override.template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ services:
ports:
- "4432:5432"

redis:
volumes:
# fix redis permission issue because it's using user redis (1001)
# sudo chown -R 1001:1001 ./volumes/tmp_data/redis
- ./volumes/tmp_data/redis:/tmp
- ./redis/redis.conf:/opt/bitnami/redis/mounted-etc/overrides.conf

dbbackups:
volumes:
- ./volumes/backups:/backups
Expand All @@ -23,6 +30,8 @@ services:
- ./volumes/tegola_config:/opt/tegola_config
- ./volumes/layer_tiles:/opt/layer_tiles
- ./volumes/arcgis-configs:/home/web/arcgis
- ./volumes/tmp_data/django:/tmp
- ./volumes/tmp_data:/home/web/logs

worker:
volumes:
Expand All @@ -32,6 +41,7 @@ services:
- ./volumes/tegola_config:/opt/tegola_config
- ./volumes/layer_tiles:/opt/layer_tiles
- ./volumes/arcgis-configs:/home/web/arcgis
- ./volumes/tmp_data/worker:/tmp

celery_beat:
volumes:
Expand All @@ -41,6 +51,7 @@ services:
- ./volumes/tegola_config:/opt/tegola_config
- ./volumes/layer_tiles:/opt/layer_tiles
- ./volumes/arcgis-configs:/home/web/arcgis
- ./volumes/tmp_data/celery_beat:/tmp

auth:
build:
Expand All @@ -54,6 +65,7 @@ services:
- ./volumes/tegola_config:/opt/tegola_config
- ./volumes/layer_tiles:/opt/layer_tiles
- ./volumes/arcgis-configs:/home/web/arcgis
- ./volumes/tmp_data/auth:/tmp

webpack-watcher:
command: bash -c 'cd /home/web/django_project/dashboard/; npm run dev-watch'
Expand All @@ -76,6 +88,7 @@ services:
- ./volumes/tegola_config:/opt/tegola_config
- ./volumes/layer_tiles:/opt/layer_tiles
- ./volumes/arcgis-configs:/home/web/arcgis
- ./volumes/tmp_data:/home/web/logs
ports:
# for django test server
- "51102:8080"
Expand All @@ -92,10 +105,16 @@ services:
- ./volumes/layer_tiles:/home/web/layer_tiles
- ./volumes/nginx_cache:/home/web/nginx_cache
- ./volumes/arcgis-configs:/home/web/arcgis
- ./volumes/tmp_data/nginx:/tmp
ports:
- "${HTTP_PORT:-8888}:80"
- "9001:9001"
links:
- auth
- django
- worker

logrotate:
volumes:
- ./volumes/tmp_data:/logs
- ./volumes/tmp_data/logrotate:/tmp
26 changes: 25 additions & 1 deletion deployment/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ volumes:
nginx-cache:
backups-data:
nginx-conf:
tmp-data:
redis-conf:
tmp-logrotate:
redis-data:

x-common-django:
&default-common-django
Expand Down Expand Up @@ -70,13 +74,18 @@ x-common-django:
- tegola-data:/opt/tegola_config
- layer-tiles:/opt/layer_tiles
- arcgis-configs:/home/web/arcgis
- tmp-data:/tmp
restart: on-failure

services:
redis:
image: bitnami/redis:7.0.2
environment:
- REDIS_PASSWORD=${REDIS_PASSWORD:-redis_password}
volumes:
- redis-data:/bitnami/redis/data
- tmp-data:/tmp
- redis-conf:/opt/bitnami/redis/mounted-etc/overrides.conf

db:
image: kartoza/postgis:14-3.2
Expand Down Expand Up @@ -123,7 +132,9 @@ services:
celery_beat:
<<: *default-common-django
entrypoint: []
command: 'celery -A core beat --loglevel=info --scheduler django_celery_beat.schedulers:DatabaseScheduler'
command: 'celery -A core beat --loglevel=info --scheduler django_celery_beat.schedulers:DatabaseScheduler --logfile=/tmp/celery_beat.log'
links:
- db

auth:
<<: *default-common-django
Expand Down Expand Up @@ -151,7 +162,20 @@ services:
- layer-tiles:/home/web/layer_tiles
- arcgis-configs:/home/web/arcgis
- nginx-cache:/home/web/nginx_cache
- tmp-data:/tmp
links:
- auth
- django
- worker

logrotate:
image: blacklabelops/logrotate:1.3
volumes:
- tmp-data:/logs
- tmp-logrotate:/tmp
environment:
- LOGS_DIRECTORIES=/logs
- LOGROTATE_STATUSFILE=/tmp/logrotate.status
- LOGROTATE_COPIES=${LOGROTATE_COPIES:-14}
- LOGROTATE_SIZE=${LOGROTATE_SIZE:-100M}
- LOGROTATE_INTERVAL=${LOGROTATE_INTERVAL:-daily}
5 changes: 3 additions & 2 deletions deployment/docker/uwsgi.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ workers = 4
cheaper = 2
env = DJANGO_SETTINGS_MODULE=core.settings.prod
# disabled so we run in the foreground for docker
#daemonize = /tmp/django.log
# daemonize = /tmp/django.log
logto = /tmp/django.log
# reload-os-env reload env for each request
# disabled because making type error
# https://github.com/unbit/uwsgi/issues/1432
Expand All @@ -22,4 +23,4 @@ memory-report = true
# increase harakiri timeout to 6mins
harakiri = 300
buffer-size = 8192
disable-logging=True
# disable-logging=True
5 changes: 3 additions & 2 deletions deployment/docker/uwsgi_auth.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ workers = 4
cheaper = 2
env = DJANGO_SETTINGS_MODULE=core.settings.prod
# disabled so we run in the foreground for docker
#daemonize = /tmp/django.log
# daemonize = /tmp/auth.log
logto = /tmp/auth.log
# reload-os-env reload env for each request
# disabled because making type error
# https://github.com/unbit/uwsgi/issues/1432
Expand All @@ -22,4 +23,4 @@ env = DJANGO_SETTINGS_MODULE=core.settings.prod
# gid = 1000
memory-report = true
harakiri = 20
disable-logging=True
# disable-logging=True
6 changes: 3 additions & 3 deletions deployment/nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
user root;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
error_log /tmp/error.log notice;
pid /tmp/nginx.pid;

events {
worker_connections 1024;
Expand All @@ -19,7 +19,7 @@ http {
log_format main '[$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main if=$logme;
access_log /tmp/access.log main if=$logme;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
Expand Down
1 change: 1 addition & 0 deletions deployment/redis/redis.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
logfile /tmp/redis.log
5 changes: 5 additions & 0 deletions django_project/core/settings/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,8 @@
EXPORT_DATA_EXPIRY_IN_HOURS = int(os.environ.get(
'EXPORT_DATA_EXPIRY_IN_HOURS', '48'
))

# LOGS Directory
LOGS_DIRECTORY = os.environ.get(
'LOGS_DIRECTORY', '/home/web/logs'
)
Loading

1 comment on commit 7f49441

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report for django_project/dashboard

St.
Category Percentage Covered / Total
🔴 Statements 5.16% 520/10077
🔴 Branches 0.72% 39/5421
🔴 Functions 2.38% 59/2478
🔴 Lines 5.24% 514/9811

Test suite run success

12 tests passing in 5 suites.

Report generated by 🧪jest coverage report action from 7f49441

Please sign in to comment.