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:
committed by
GitHub
parent
606f77da71
commit
03ff0aec9c
0
.dockerignore
Normal file
0
.dockerignore
Normal file
17
Dockerfile
Normal file
17
Dockerfile
Normal 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
38
docker-compose.yaml
Normal 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
15
docker.md
Normal 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
8
entrypoint.sh
Normal 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
|
||||
@@ -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
|
||||
|
||||
@@ -56,3 +56,6 @@ webencodings
|
||||
Whoosh
|
||||
xhtml2pdf
|
||||
XlsxWriter
|
||||
gunicorn
|
||||
psycopg2-binary
|
||||
whitenoise
|
||||
Reference in New Issue
Block a user