Dockerized the application (#119)

* dockerized the application

* Update docker.md

---------

Co-authored-by: Horilla <131998600+horilla-opensource@users.noreply.github.com>
This commit is contained in:
Ashwanth Balakrishnan
2024-03-13 11:51:23 +05:30
committed by GitHub
parent 606f77da71
commit 03ff0aec9c
7 changed files with 84 additions and 0 deletions

0
.dockerignore Normal file
View File

17
Dockerfile Normal file
View File

@@ -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"]

38
docker-compose.yaml Normal file
View File

@@ -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:

15
docker.md Normal file
View File

@@ -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```

8
entrypoint.sh Normal file
View File

@@ -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

View File

@@ -65,6 +65,7 @@ APSCHEDULER_RUN_NOW_TIMEOUT = 25 # Seconds
MIDDLEWARE = [ MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware", "django.middleware.security.SecurityMiddleware",
"whitenoise.middleware.WhiteNoiseMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware", "django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware", "django.middleware.common.CommonMiddleware",
"corsheaders.middleware.CorsMiddleware", "corsheaders.middleware.CorsMiddleware",
@@ -151,6 +152,8 @@ STATICFILES_DIRS = [
BASE_DIR / "static", BASE_DIR / "static",
] ]
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
MEDIA_URL = "/media/" MEDIA_URL = "/media/"
MEDIA_ROOT = os.path.join(BASE_DIR, "media/") MEDIA_ROOT = os.path.join(BASE_DIR, "media/")
# Default primary key field type # Default primary key field type

View File

@@ -56,3 +56,6 @@ webencodings
Whoosh Whoosh
xhtml2pdf xhtml2pdf
XlsxWriter XlsxWriter
gunicorn
psycopg2-binary
whitenoise