Fix docker (#953)
* [FIX] DOCKER: Update docker files to standardize the dev and prod Docker image * [FIX] DOCKER: Fix docker configuration of Horilla for runtime errors * [FIX] Standardise and reduce Docker configuration of Horilla * [UPDT] DOCKER: Standardise directory structure of Docker and related files for Horilla standards (#934) * Multi stage Dockerfile for size reduction
This commit is contained in:
@@ -1,5 +1,89 @@
|
||||
.github
|
||||
.gitignore
|
||||
*.md
|
||||
LICENSE
|
||||
docker-compose.yaml
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
|
||||
# PyInstaller
|
||||
*.manifest
|
||||
*.spec
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.nox/
|
||||
.coverage
|
||||
.coverage.*
|
||||
.cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*.cover
|
||||
.hypothesis/
|
||||
.pytest_cache/
|
||||
|
||||
# Django stuff:
|
||||
*.log
|
||||
local_settings.py
|
||||
media/
|
||||
staticfiles/
|
||||
static_root/
|
||||
|
||||
# Environments
|
||||
.env
|
||||
.venv
|
||||
env/
|
||||
venv/
|
||||
ENV/
|
||||
|
||||
# IDEs
|
||||
.vscode/
|
||||
.idea/
|
||||
*.swp
|
||||
|
||||
# MacOS
|
||||
.DS_Store
|
||||
|
||||
# Node
|
||||
node_modules/
|
||||
|
||||
# Git
|
||||
.git
|
||||
.gitignore
|
||||
README.md
|
||||
Dockerfile
|
||||
.dockerignore
|
||||
docker-compose.yml
|
||||
.vscode
|
||||
.idea
|
||||
*.pyc
|
||||
__pycache__
|
||||
.pytest_cache
|
||||
.coverage
|
||||
*.log
|
||||
.env
|
||||
horillavenv
|
||||
node_modules
|
||||
.DS_Store
|
||||
|
||||
19
.env.example
Normal file
19
.env.example
Normal file
@@ -0,0 +1,19 @@
|
||||
# Django
|
||||
DJANGO_SETTINGS_MODULE=horilla.settings
|
||||
SECRET_KEY=change-me
|
||||
DEBUG=False
|
||||
ALLOWED_HOSTS=*
|
||||
|
||||
# Database (used by compose to form DATABASE_URL)
|
||||
POSTGRES_DB=horilla
|
||||
POSTGRES_USER=horilla
|
||||
POSTGRES_PASSWORD=horilla
|
||||
|
||||
# Optional: storage/other
|
||||
# AWS_ACCESS_KEY_ID=
|
||||
# AWS_SECRET_ACCESS_KEY=
|
||||
# AWS_STORAGE_BUCKET_NAME=
|
||||
|
||||
# Redis Cache
|
||||
REDIS_PASSWORD=horilla
|
||||
REDIS_URL=redis://:horilla@redis:6379/0
|
||||
84
Dockerfile
84
Dockerfile
@@ -1,17 +1,85 @@
|
||||
FROM python:3.10-slim-bullseye
|
||||
# Build stage - for compiling dependencies
|
||||
FROM python:3.12-slim as builder
|
||||
|
||||
ENV PYTHONUNBUFFERED=1
|
||||
ENV PYTHONDONTWRITEBYTECODE=1 \
|
||||
PYTHONUNBUFFERED=1
|
||||
|
||||
RUN apt-get update && apt-get install -y libcairo2-dev gcc
|
||||
# Install build dependencies
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends \
|
||||
build-essential \
|
||||
libpq-dev \
|
||||
libjpeg-dev \
|
||||
zlib1g-dev \
|
||||
libcairo2-dev \
|
||||
libpango1.0-dev \
|
||||
libgdk-pixbuf-xlib-2.0-dev \
|
||||
libxml2-dev \
|
||||
libxslt1-dev \
|
||||
libffi-dev \
|
||||
pkg-config \
|
||||
gcc \
|
||||
g++ \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
WORKDIR /app/
|
||||
# Create virtual environment
|
||||
RUN python -m venv /opt/venv
|
||||
ENV PATH="/opt/venv/bin:$PATH"
|
||||
|
||||
COPY . .
|
||||
# Install Python dependencies
|
||||
COPY requirements.txt .
|
||||
RUN pip install --upgrade pip \
|
||||
&& pip install --no-cache-dir -r requirements.txt gunicorn psycopg2-binary
|
||||
|
||||
RUN chmod +x /app/entrypoint.sh
|
||||
# Production stage - minimal runtime image
|
||||
FROM python:3.12-slim as production
|
||||
|
||||
RUN pip install -r requirements.txt
|
||||
ENV PYTHONDONTWRITEBYTECODE=1 \
|
||||
PYTHONUNBUFFERED=1 \
|
||||
PATH="/opt/venv/bin:$PATH"
|
||||
|
||||
# Install only runtime dependencies
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends \
|
||||
libpq5 \
|
||||
libjpeg62-turbo \
|
||||
zlib1g \
|
||||
libcairo2 \
|
||||
libpango-1.0-0 \
|
||||
libgdk-pixbuf-xlib-2.0-0 \
|
||||
libxml2 \
|
||||
libxslt1.1 \
|
||||
libffi8 \
|
||||
curl \
|
||||
netcat-openbsd \
|
||||
&& rm -rf /var/lib/apt/lists/* \
|
||||
&& apt-get clean
|
||||
|
||||
# Create non-root user
|
||||
RUN useradd --create-home --uid 1000 appuser
|
||||
|
||||
# Copy virtual environment from builder stage
|
||||
COPY --from=builder /opt/venv /opt/venv
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy application code
|
||||
COPY --chown=appuser:appuser . .
|
||||
|
||||
# Copy entrypoint script
|
||||
COPY --chown=appuser:appuser docker/entrypoint.sh /entrypoint.sh
|
||||
RUN chmod +x /entrypoint.sh
|
||||
|
||||
# Create necessary directories and set permissions
|
||||
RUN mkdir -p staticfiles media \
|
||||
&& chown -R appuser:appuser /app
|
||||
|
||||
USER appuser
|
||||
|
||||
EXPOSE 8000
|
||||
|
||||
CMD ["python3", "manage.py", "runserver"]
|
||||
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
|
||||
CMD curl -f http://localhost:8000/health/ || exit 1
|
||||
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
CMD ["gunicorn", "horilla.wsgi:application", "--config", "docker/gunicorn.conf.py"]
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
services:
|
||||
server:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
ports:
|
||||
- 8000:8000
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
DATABASE_URL: "postgres://postgres:postgres@db:5432/horilla"
|
||||
command: sh ./entrypoint.sh
|
||||
volumes:
|
||||
- ./horilla:/app/horilla
|
||||
- ./media:/app/media
|
||||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
||||
|
||||
db:
|
||||
image: postgres:16-bullseye
|
||||
environment:
|
||||
POSTGRES_DB: horilla
|
||||
POSTGRES_USER: postgres
|
||||
POSTGRES_PASSWORD: postgres
|
||||
POSTGRES_INITDB_ARGS: "--auth-host=scram-sha-256"
|
||||
PGDATA: /var/lib/postgresql/data/pgdata
|
||||
ports:
|
||||
- 5432:5432
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
- horilla-data:/var/lib/postgresql/data
|
||||
healthcheck:
|
||||
test: ["CMD", "pg_isready", "-U", "postgres"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
|
||||
volumes:
|
||||
horilla-data:
|
||||
56
docker-compose.yml
Normal file
56
docker-compose.yml
Normal file
@@ -0,0 +1,56 @@
|
||||
services:
|
||||
web:
|
||||
build: .
|
||||
ports:
|
||||
- "8000:8000"
|
||||
volumes:
|
||||
- .:/app
|
||||
- staticfiles:/app/staticfiles
|
||||
- media:/app/media
|
||||
environment:
|
||||
- DEBUG=1
|
||||
- SECRET_KEY=dev-secret-key
|
||||
- ALLOWED_HOSTS=localhost,127.0.0.1,0.0.0.0
|
||||
- CSRF_TRUSTED_ORIGINS=http://localhost:8000
|
||||
- DATABASE_URL=postgres://horilla_user:horilla_pass@db:5432/horilla_db
|
||||
- REDIS_URL=redis://:horilla_pass@redis:6379/0
|
||||
depends_on:
|
||||
- db
|
||||
- redis
|
||||
|
||||
db:
|
||||
image: postgres:16-alpine
|
||||
environment:
|
||||
POSTGRES_DB: horilla_db
|
||||
POSTGRES_USER: horilla_user
|
||||
POSTGRES_PASSWORD: horilla_pass
|
||||
volumes:
|
||||
- postgres_data:/var/lib/postgresql/data
|
||||
ports:
|
||||
- "5432:5432"
|
||||
|
||||
redis:
|
||||
image: redis:7-alpine
|
||||
command: redis-server --appendonly yes --requirepass horilla_pass
|
||||
volumes:
|
||||
- redis_data:/data
|
||||
ports:
|
||||
- "6379:6379"
|
||||
|
||||
nginx:
|
||||
image: nginx:alpine
|
||||
ports:
|
||||
- "80:80"
|
||||
volumes:
|
||||
- staticfiles:/static:ro
|
||||
- media:/media:ro
|
||||
- ./docker/nginx.conf:/etc/nginx/nginx.conf:ro
|
||||
depends_on:
|
||||
- web
|
||||
profiles: ["production"]
|
||||
|
||||
volumes:
|
||||
staticfiles:
|
||||
media:
|
||||
postgres_data:
|
||||
redis_data:
|
||||
15
docker.md
15
docker.md
@@ -1,15 +0,0 @@
|
||||
# Docker
|
||||
|
||||
- Built on Python 3.10 image
|
||||
- Uses PostgreSQL 16 Database
|
||||
- Creates admin user with default username - 'admin' & password - 'admin'
|
||||
|
||||
# Docker & Docker compose installation
|
||||
|
||||
- [Linux Docker Desktop](https://docs.docker.com/desktop/install/linux-install/)
|
||||
- [Windows Docker Desktop](https://docs.docker.com/desktop/install/windows-install/)
|
||||
- [Mac Docker Desktop](https://docs.docker.com/desktop/install/mac-install/)
|
||||
|
||||
## Build & Run
|
||||
|
||||
- ```docker compose up```
|
||||
20
docker/entrypoint.sh
Executable file
20
docker/entrypoint.sh
Executable file
@@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
echo "Starting Horilla HR..."
|
||||
|
||||
# Wait for PostgreSQL to be ready
|
||||
echo "Waiting for PostgreSQL..."
|
||||
while ! nc -z db 5432; do
|
||||
sleep 0.1
|
||||
done
|
||||
echo "PostgreSQL is ready!"
|
||||
|
||||
# Run migrations
|
||||
python manage.py migrate --noinput
|
||||
|
||||
# Collect static files
|
||||
python manage.py collectstatic --noinput
|
||||
|
||||
echo "Starting server..."
|
||||
exec "$@"
|
||||
45
docker/gunicorn.conf.py
Normal file
45
docker/gunicorn.conf.py
Normal file
@@ -0,0 +1,45 @@
|
||||
# Gunicorn configuration for Horilla-HR
|
||||
# This file provides advanced configuration options for the WSGI server
|
||||
|
||||
import os
|
||||
import multiprocessing
|
||||
|
||||
# Bind settings
|
||||
bind = f"0.0.0.0:{os.environ.get('PORT', '8000')}"
|
||||
host = "0.0.0.0"
|
||||
port = int(os.environ.get('PORT', '8000'))
|
||||
|
||||
# Worker settings
|
||||
workers = int(os.environ.get('GUNICORN_WORKERS', max(2, min(multiprocessing.cpu_count() * 2 + 1, 8))))
|
||||
worker_class = "gthread"
|
||||
threads = 4
|
||||
worker_connections = 1000
|
||||
max_requests = 1000
|
||||
max_requests_jitter = 50
|
||||
preload_app = True
|
||||
|
||||
# Timeout settings
|
||||
timeout = 120
|
||||
keepalive = 5
|
||||
|
||||
# Logging
|
||||
accesslog = "-"
|
||||
errorlog = "-"
|
||||
loglevel = os.environ.get('GUNICORN_LOG_LEVEL', 'info')
|
||||
access_log_format = '%(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s" %(D)s'
|
||||
|
||||
# Process naming
|
||||
proc_name = "horilla-hrms"
|
||||
|
||||
# Server mechanics
|
||||
pidfile = "/tmp/gunicorn.pid"
|
||||
user = None # Run as current user in container
|
||||
group = None
|
||||
tmp_upload_dir = None
|
||||
|
||||
# Development settings
|
||||
reload = os.environ.get('GUNICORN_RELOAD', 'false').lower() == 'true'
|
||||
|
||||
# SSL settings (if needed)
|
||||
# ssl_keyfile = os.environ.get('SSL_KEYFILE')
|
||||
# ssl_certfile = os.environ.get('SSL_CERTFILE')
|
||||
31
docker/nginx.conf
Normal file
31
docker/nginx.conf
Normal file
@@ -0,0 +1,31 @@
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
http {
|
||||
upstream django {
|
||||
server web:8000;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
client_max_body_size 50M;
|
||||
|
||||
location /static/ {
|
||||
alias /static/;
|
||||
expires 1y;
|
||||
}
|
||||
|
||||
location /media/ {
|
||||
alias /media/;
|
||||
}
|
||||
|
||||
location / {
|
||||
proxy_pass http://django;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "Waiting for database to be ready..."
|
||||
python3 manage.py makemigrations
|
||||
python3 manage.py migrate
|
||||
python3 manage.py collectstatic --noinput
|
||||
python3 manage.py createhorillauser --first_name admin --last_name admin --username admin --password admin --email admin@example.com --phone 1234567890
|
||||
gunicorn --bind 0.0.0.0:8000 horilla.wsgi:application
|
||||
15844
package-lock.json
generated
15844
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
34
package.json
34
package.json
@@ -1,34 +0,0 @@
|
||||
{
|
||||
"name": "openhrms-core",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "src/index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"dev":"npm run development",
|
||||
"development":"mix"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/ArjunCybro/OpenHRMS-Dashboard.git"
|
||||
},
|
||||
"author": "OpenHRMS",
|
||||
"license": "ISC",
|
||||
"bugs": {
|
||||
"url": "https://github.com/ArjunCybro/OpenHRMS-Dashboard/issues"
|
||||
},
|
||||
"homepage": "https://github.com/ArjunCybro/OpenHRMS-Dashboard#readme",
|
||||
"devDependencies": {
|
||||
"laravel-mix": "^6.0.49"
|
||||
},
|
||||
"dependencies": {
|
||||
"alpinejs": "^3.10.5",
|
||||
"ionicons": "^7.1.0",
|
||||
"jquery": "^3.6.3",
|
||||
"jquery-ui": "^1.13.2",
|
||||
"jquery-ui-touch-punch": "^0.2.3",
|
||||
"js-datepicker": "^5.18.2",
|
||||
"select2": "^4.1.0-rc.0",
|
||||
"uuid": "^9.0.0"
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,7 @@ drf-yasg
|
||||
et-xmlfile
|
||||
geopy
|
||||
google-api-python-client
|
||||
google-auth-oauthlib
|
||||
google-cloud-storage==3.0.0
|
||||
html5lib
|
||||
Jinja2
|
||||
|
||||
Reference in New Issue
Block a user