diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..e69de29bb diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..a6d820a1b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM python:3.10-slim-bullseye + +ENV PYTHONUNBUFFERED 1 + +RUN apt-get update && apt-get install -y libcairo2-dev gcc + +WORKDIR /app/ + +COPY . . + +RUN chmod +x /app/entrypoint.sh + +RUN pip install -r requirements.txt + +EXPOSE 8000 + +CMD ["python3", "manage.py", "runserver"] \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 000000000..6f7076e27 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,38 @@ +version: '3.8' +services: + server: + build: + context: . + dockerfile: Dockerfile + ports: + - 8000:8000 + restart: unless-stopped + environment: + DATABASE_URL: "postgres://postgres:postgres@db:5432/horilla" + command: ./entrypoint.sh + depends_on: + db: + condition: service_healthy + + db: + image: postgres:16-bullseye + environment: + POSTGRES_DB: horilla + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + 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: + + + diff --git a/docker.md b/docker.md new file mode 100644 index 000000000..81c6548b8 --- /dev/null +++ b/docker.md @@ -0,0 +1,15 @@ +# 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``` diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 000000000..2c4520a31 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,8 @@ +#!/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 \ No newline at end of file diff --git a/horilla/settings.py b/horilla/settings.py index bc979567a..4d40ba4df 100755 --- a/horilla/settings.py +++ b/horilla/settings.py @@ -65,6 +65,7 @@ APSCHEDULER_RUN_NOW_TIMEOUT = 25 # Seconds MIDDLEWARE = [ "django.middleware.security.SecurityMiddleware", + "whitenoise.middleware.WhiteNoiseMiddleware", "django.contrib.sessions.middleware.SessionMiddleware", "django.middleware.common.CommonMiddleware", "corsheaders.middleware.CorsMiddleware", @@ -151,6 +152,8 @@ STATICFILES_DIRS = [ BASE_DIR / "static", ] +STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage" + MEDIA_URL = "/media/" MEDIA_ROOT = os.path.join(BASE_DIR, "media/") # Default primary key field type diff --git a/requirements.txt b/requirements.txt index 8431bfe29..a26198a50 100644 --- a/requirements.txt +++ b/requirements.txt @@ -56,3 +56,6 @@ webencodings Whoosh xhtml2pdf XlsxWriter +gunicorn +psycopg2-binary +whitenoise \ No newline at end of file