abhisheksan commited on
Commit
a5b50da
Β·
1 Parent(s): 12952ee

Refactor Docker setup: streamline Dockerfile, remove redundant files, and enhance scripts for clarity and functionality

Browse files
.dockerignore CHANGED
@@ -21,7 +21,7 @@ wheels/
21
  *.egg
22
 
23
  # Virtual environments
24
- .venv
25
  venv/
26
  ENV/
27
  env/
@@ -52,25 +52,23 @@ tests/
52
  .coverage
53
  htmlcov/
54
 
55
- # Documentation
56
- docs/
57
- *.md
58
- !README.md
59
-
60
  # Git
61
  .git/
62
  .gitignore
63
 
64
- # Docker
65
- Dockerfile
66
- docker-compose*.yml
67
- .dockerignore
68
 
69
- # Environment files
70
  .env
71
  .env.local
72
  .env.*.local
73
 
74
  # Temporary files
75
  *.tmp
76
- *.temp
 
 
 
 
 
 
21
  *.egg
22
 
23
  # Virtual environments
24
+ .venv/
25
  venv/
26
  ENV/
27
  env/
 
52
  .coverage
53
  htmlcov/
54
 
 
 
 
 
 
55
  # Git
56
  .git/
57
  .gitignore
58
 
59
+ # Redundant Docker files (removed)
60
+ # scripts/ removed from ignore list - they're useful for deployment
 
 
61
 
62
+ # Environment files (keep .env.example)
63
  .env
64
  .env.local
65
  .env.*.local
66
 
67
  # Temporary files
68
  *.tmp
69
+ *.temp
70
+
71
+ # Documentation (except README.md)
72
+ docs/
73
+ *.md
74
+ !README.md
Dockerfile CHANGED
@@ -7,8 +7,10 @@ ENV PYTHONUNBUFFERED=1 \
7
  POETRY_VERSION=1.7.1 \
8
  POETRY_HOME="/opt/poetry" \
9
  POETRY_VIRTUALENVS_IN_PROJECT=true \
10
- POETRY_NO_INTERACTION=1 \
11
- PATH="$POETRY_HOME/bin:$PATH"
 
 
12
 
13
  # Install system dependencies
14
  RUN apt-get update \
@@ -23,8 +25,8 @@ RUN curl -sSL https://install.python-poetry.org | python3 -
23
  # Set work directory
24
  WORKDIR /app
25
 
26
- # Copy Poetry files with explicit file listing
27
- COPY ["pyproject.toml", "poetry.lock", "./"]
28
 
29
  # Install Python dependencies
30
  RUN poetry install --only=main --no-dev
 
7
  POETRY_VERSION=1.7.1 \
8
  POETRY_HOME="/opt/poetry" \
9
  POETRY_VIRTUALENVS_IN_PROJECT=true \
10
+ POETRY_NO_INTERACTION=1
11
+
12
+ # Add Poetry to PATH
13
+ ENV PATH="$POETRY_HOME/bin:$PATH"
14
 
15
  # Install system dependencies
16
  RUN apt-get update \
 
25
  # Set work directory
26
  WORKDIR /app
27
 
28
+ # Copy project files (poetry files first for better layer caching)
29
+ COPY pyproject.toml poetry.lock ./
30
 
31
  # Install Python dependencies
32
  RUN poetry install --only=main --no-dev
Dockerfile.alt DELETED
@@ -1,45 +0,0 @@
1
- # Alternative Dockerfile - copy all files first
2
- FROM python:3.11-slim
3
-
4
- # Set environment variables
5
- ENV PYTHONUNBUFFERED=1 \
6
- PYTHONDONTWRITEBYTECODE=1 \
7
- POETRY_VERSION=1.7.1 \
8
- POETRY_HOME="/opt/poetry" \
9
- POETRY_VIRTUALENVS_IN_PROJECT=true \
10
- POETRY_NO_INTERACTION=1 \
11
- PATH="$POETRY_HOME/bin:$PATH"
12
-
13
- # Install system dependencies
14
- RUN apt-get update \
15
- && apt-get install -y --no-install-recommends \
16
- curl \
17
- build-essential \
18
- && rm -rf /var/lib/apt/lists/*
19
-
20
- # Install Poetry
21
- RUN curl -sSL https://install.python-poetry.org | python3 -
22
-
23
- # Set work directory
24
- WORKDIR /app
25
-
26
- # Copy all project files
27
- COPY . .
28
-
29
- # Install Python dependencies
30
- RUN poetry install --only=main --no-dev
31
-
32
- # Create non-root user
33
- RUN useradd --create-home --shell /bin/bash app \
34
- && chown -R app:app /app
35
- USER app
36
-
37
- # Expose port
38
- EXPOSE 8000
39
-
40
- # Health check
41
- HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
42
- CMD curl -f http://localhost:8000/health || exit 1
43
-
44
- # Run the application
45
- CMD ["poetry", "run", "uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Dockerfile.dev DELETED
@@ -1,41 +0,0 @@
1
- # Development Dockerfile with hot reloading
2
- FROM python:3.11-slim
3
-
4
- # Set environment variables
5
- ENV PYTHONUNBUFFERED=1 \
6
- PYTHONDONTWRITEBYTECODE=1 \
7
- POETRY_VERSION=1.7.1 \
8
- POETRY_HOME="/opt/poetry" \
9
- POETRY_VIRTUALENVS_IN_PROJECT=true \
10
- POETRY_NO_INTERACTION=1 \
11
- PATH="$POETRY_HOME/bin:$PATH"
12
-
13
- # Install system dependencies
14
- RUN apt-get update \
15
- && apt-get install -y --no-install-recommends \
16
- curl \
17
- build-essential \
18
- && rm -rf /var/lib/apt/lists/*
19
-
20
- # Install Poetry
21
- RUN curl -sSL https://install.python-poetry.org | python3 -
22
-
23
- # Set work directory
24
- WORKDIR /app
25
-
26
- # Copy Poetry files with explicit file listing
27
- COPY ["pyproject.toml", "poetry.lock", "./"]
28
-
29
- # Install all dependencies (including dev)
30
- RUN poetry install
31
-
32
- # Create non-root user
33
- RUN useradd --create-home --shell /bin/bash app \
34
- && chown -R app:app /app
35
- USER app
36
-
37
- # Expose port
38
- EXPOSE 8000
39
-
40
- # Run the application with reload
41
- CMD ["poetry", "run", "uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
docker-compose.dev.yml DELETED
@@ -1,24 +0,0 @@
1
- version: '3.8'
2
-
3
- services:
4
- multiutility-server:
5
- build:
6
- context: .
7
- dockerfile: Dockerfile.dev
8
- ports:
9
- - "8000:8000"
10
- environment:
11
- - LOG_LEVEL=DEBUG
12
- - RELOAD=true
13
- env_file:
14
- - .env
15
- volumes:
16
- - .:/app
17
- - ./logs:/app/logs
18
- restart: unless-stopped
19
- healthcheck:
20
- test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
21
- interval: 30s
22
- timeout: 10s
23
- retries: 3
24
- start_period: 40s
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
docker-compose.prod.yml DELETED
@@ -1,32 +0,0 @@
1
- version: '3.8'
2
-
3
- services:
4
- multiutility-server:
5
- build:
6
- context: .
7
- dockerfile: Dockerfile
8
- ports:
9
- - "8000:8000"
10
- environment:
11
- - LOG_LEVEL=INFO
12
- - RELOAD=false
13
- env_file:
14
- - .env
15
- volumes:
16
- - ./logs:/app/logs
17
- restart: unless-stopped
18
- healthcheck:
19
- test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
20
- interval: 30s
21
- timeout: 10s
22
- retries: 3
23
- start_period: 40s
24
- # Production optimizations
25
- deploy:
26
- resources:
27
- limits:
28
- cpus: '1.0'
29
- memory: 1G
30
- reservations:
31
- cpus: '0.5'
32
- memory: 512M
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
docker-compose.yml CHANGED
@@ -18,4 +18,13 @@ services:
18
  interval: 30s
19
  timeout: 10s
20
  retries: 3
21
- start_period: 40s
 
 
 
 
 
 
 
 
 
 
18
  interval: 30s
19
  timeout: 10s
20
  retries: 3
21
+ start_period: 40s
22
+ # Production optimizations
23
+ deploy:
24
+ resources:
25
+ limits:
26
+ cpus: '1.0'
27
+ memory: 1G
28
+ reservations:
29
+ cpus: '0.5'
30
+ memory: 512M
scripts/run_docker.bat CHANGED
@@ -2,6 +2,9 @@
2
  echo Building and running Multi-Utility Server with Docker...
3
  echo.
4
 
 
 
 
5
  REM Check if .env file exists
6
  if not exist .env (
7
  echo Warning: .env file not found. Copying from .env.example...
 
2
  echo Building and running Multi-Utility Server with Docker...
3
  echo.
4
 
5
+ REM Change to project root directory
6
+ cd /d "%~dp0\.."
7
+
8
  REM Check if .env file exists
9
  if not exist .env (
10
  echo Warning: .env file not found. Copying from .env.example...
scripts/run_docker.sh CHANGED
@@ -3,6 +3,9 @@
3
  echo "Building and running Multi-Utility Server with Docker..."
4
  echo
5
 
 
 
 
6
  # Check if .env file exists
7
  if [ ! -f .env ]; then
8
  echo "Warning: .env file not found. Copying from .env.example..."
 
3
  echo "Building and running Multi-Utility Server with Docker..."
4
  echo
5
 
6
+ # Change to project root directory
7
+ cd "$(dirname "$0")/.."
8
+
9
  # Check if .env file exists
10
  if [ ! -f .env ]; then
11
  echo "Warning: .env file not found. Copying from .env.example..."
troubleshoot_docker.bat DELETED
@@ -1,39 +0,0 @@
1
- @echo off
2
- echo Docker Build Troubleshooting Script
3
- echo ===================================
4
- echo.
5
-
6
- echo Checking for required files...
7
- echo.
8
-
9
- if exist "pyproject.toml" (
10
- echo βœ“ pyproject.toml found
11
- ) else (
12
- echo βœ— pyproject.toml not found
13
- )
14
-
15
- if exist "poetry.lock" (
16
- echo βœ“ poetry.lock found
17
- ) else (
18
- echo βœ— poetry.lock not found
19
- )
20
-
21
- if exist "Dockerfile" (
22
- echo βœ“ Dockerfile found
23
- ) else (
24
- echo βœ— Dockerfile not found
25
- )
26
-
27
- echo.
28
- echo File sizes:
29
- for %%f in (pyproject.toml poetry.lock Dockerfile) do if exist "%%f" echo %%f: %%~zf bytes
30
-
31
- echo.
32
- echo Attempting Docker build...
33
- echo.
34
-
35
- docker build -t multiutility-server .
36
-
37
- echo.
38
- echo Build completed. Check output above for any errors.
39
- pause
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
troubleshoot_docker.sh DELETED
@@ -1,44 +0,0 @@
1
- #!/bin/bash
2
-
3
- echo "Docker Build Troubleshooting Script"
4
- echo "==================================="
5
- echo
6
-
7
- echo "Checking for required files..."
8
- echo
9
-
10
- if [ -f "pyproject.toml" ]; then
11
- echo "βœ“ pyproject.toml found"
12
- else
13
- echo "βœ— pyproject.toml not found"
14
- fi
15
-
16
- if [ -f "poetry.lock" ]; then
17
- echo "βœ“ poetry.lock found"
18
- else
19
- echo "βœ— poetry.lock not found"
20
- fi
21
-
22
- if [ -f "Dockerfile" ]; then
23
- echo "βœ“ Dockerfile found"
24
- else
25
- echo "βœ— Dockerfile not found"
26
- fi
27
-
28
- echo
29
- echo "File sizes:"
30
- for file in pyproject.toml poetry.lock Dockerfile; do
31
- if [ -f "$file" ]; then
32
- size=$(stat -f%z "$file" 2>/dev/null || stat -c%s "$file" 2>/dev/null || echo "unknown")
33
- echo "$file: $size bytes"
34
- fi
35
- done
36
-
37
- echo
38
- echo "Attempting Docker build..."
39
- echo
40
-
41
- docker build -t multiutility-server .
42
-
43
- echo
44
- echo "Build completed. Check output above for any errors."