wjbmattingly commited on
Commit
e031063
·
verified ·
1 Parent(s): 726ed47

Create Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +156 -0
Dockerfile ADDED
@@ -0,0 +1,156 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Browser-Only Version (No User Authentication)
2
+ # Use Python 3.11 slim image for better compatibility
3
+ FROM python:3.11-slim
4
+
5
+ # Set environment variables
6
+ ENV PYTHONUNBUFFERED=1
7
+ ENV DEBIAN_FRONTEND=noninteractive
8
+ ENV PORT=7860
9
+
10
+ # Install system dependencies
11
+ RUN apt-get update && apt-get install -y \
12
+ git \
13
+ libmagic1 \
14
+ libmagic-dev \
15
+ file \
16
+ gcc \
17
+ g++ \
18
+ libc6-dev \
19
+ libffi-dev \
20
+ libjpeg-dev \
21
+ libpng-dev \
22
+ libtiff-dev \
23
+ libwebp-dev \
24
+ zlib1g-dev \
25
+ && rm -rf /var/lib/apt/lists/*
26
+
27
+ # Set work directory
28
+ WORKDIR /app
29
+
30
+ # Clone the repository
31
+ RUN git clone https://github.com/wjbmattingly/VLAMy.git .
32
+
33
+ # Install Python dependencies
34
+ RUN pip install --no-cache-dir -r requirements.txt
35
+
36
+ # Create necessary directories
37
+ RUN mkdir -p /app/media/imports /app/staticfiles /app/logs
38
+
39
+ # Create custom settings for no-auth mode
40
+ RUN echo 'from .settings import *\n\
41
+ \n\
42
+ # Disable authentication requirements\n\
43
+ REST_FRAMEWORK = {\n\
44
+ "DEFAULT_AUTHENTICATION_CLASSES": [],\n\
45
+ "DEFAULT_PERMISSION_CLASSES": [\n\
46
+ "rest_framework.permissions.AllowAny",\n\
47
+ ],\n\
48
+ "DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.PageNumberPagination",\n\
49
+ "PAGE_SIZE": 20,\n\
50
+ }\n\
51
+ \n\
52
+ # Use in-memory database for simplicity\n\
53
+ DATABASES = {\n\
54
+ "default": {\n\
55
+ "ENGINE": "django.db.backends.sqlite3",\n\
56
+ "NAME": ":memory:",\n\
57
+ }\n\
58
+ }\n\
59
+ \n\
60
+ # Enhanced cache settings for browser-only mode\n\
61
+ CACHES = {\n\
62
+ "default": {\n\
63
+ "BACKEND": "django.core.cache.backends.locmem.LocMemCache",\n\
64
+ "LOCATION": "vlamy-cache",\n\
65
+ "TIMEOUT": 86400, # 24 hours\n\
66
+ "OPTIONS": {\n\
67
+ "MAX_ENTRIES": 1000,\n\
68
+ }\n\
69
+ }\n\
70
+ }\n\
71
+ \n\
72
+ # Disable user-related middleware\n\
73
+ MIDDLEWARE = [\n\
74
+ "corsheaders.middleware.CorsMiddleware",\n\
75
+ "django.middleware.security.SecurityMiddleware",\n\
76
+ "django.contrib.sessions.middleware.SessionMiddleware",\n\
77
+ "django.middleware.common.CommonMiddleware",\n\
78
+ "django.middleware.csrf.CsrfViewMiddleware",\n\
79
+ "django.contrib.messages.middleware.MessageMiddleware",\n\
80
+ "django.middleware.clickjacking.XFrameOptionsMiddleware",\n\
81
+ ]\n\
82
+ \n\
83
+ # Remove auth-related apps\n\
84
+ INSTALLED_APPS = [\n\
85
+ "django.contrib.contenttypes",\n\
86
+ "django.contrib.sessions",\n\
87
+ "django.contrib.messages",\n\
88
+ "django.contrib.staticfiles",\n\
89
+ "rest_framework",\n\
90
+ "corsheaders",\n\
91
+ "ocr_app",\n\
92
+ ]\n\
93
+ \n\
94
+ # Allow all CORS origins for browser-only mode\n\
95
+ CORS_ALLOW_ALL_ORIGINS = True\n\
96
+ CORS_ALLOW_CREDENTIALS = False\n\
97
+ \n\
98
+ # Session settings for browser storage\n\
99
+ SESSION_ENGINE = "django.contrib.sessions.backends.cache"\n\
100
+ SESSION_CACHE_ALIAS = "default"\n\
101
+ SESSION_COOKIE_AGE = 86400 # 24 hours\n\
102
+ \n\
103
+ ' > /app/vlamy_ocr/settings_no_auth.py
104
+
105
+ # Create a custom URL configuration for no-auth mode
106
+ RUN echo 'from django.urls import path, include\n\
107
+ from django.conf import settings\n\
108
+ from django.conf.urls.static import static\n\
109
+ from django.views.generic import TemplateView\n\
110
+ from django.contrib.staticfiles.urls import staticfiles_urlpatterns\n\
111
+ \n\
112
+ urlpatterns = [\n\
113
+ # API endpoints (no auth required)\n\
114
+ path("api/", include("ocr_app.urls")),\n\
115
+ \n\
116
+ # Frontend routes (single-page application)\n\
117
+ path("", TemplateView.as_view(template_name="index.html"), name="home"),\n\
118
+ path("app/", TemplateView.as_view(template_name="index.html"), name="app"),\n\
119
+ ]\n\
120
+ \n\
121
+ # Serve media and static files\n\
122
+ if settings.DEBUG:\n\
123
+ urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)\n\
124
+ urlpatterns += staticfiles_urlpatterns()\n\
125
+ ' > /app/vlamy_ocr/urls_no_auth.py
126
+
127
+ # Set proper permissions
128
+ RUN chmod -R 755 /app
129
+
130
+ # Collect static files
131
+ RUN DJANGO_SETTINGS_MODULE=vlamy_ocr.settings_no_auth python manage.py collectstatic --noinput
132
+
133
+ # Create a startup script for no-auth mode
134
+ RUN echo '#!/bin/bash\n\
135
+ \n\
136
+ # Set the custom settings module\n\
137
+ export DJANGO_SETTINGS_MODULE=vlamy_ocr.settings_no_auth\n\
138
+ \n\
139
+ # Replace the main urls.py with no-auth version\n\
140
+ cp /app/vlamy_ocr/urls_no_auth.py /app/vlamy_ocr/urls.py\n\
141
+ \n\
142
+ # Start the Django development server\n\
143
+ python manage.py runserver 0.0.0.0:$PORT\n\
144
+ ' > /app/start.sh && chmod +x /app/start.sh
145
+
146
+ # Environment variables for production (no-auth mode)
147
+ ENV DEBUG=False
148
+ ENV SECRET_KEY="browser-only-key-no-sensitive-data"
149
+ ENV ALLOWED_HOSTS="*"
150
+ ENV DJANGO_SETTINGS_MODULE="vlamy_ocr.settings_no_auth"
151
+
152
+ # Expose port
153
+ EXPOSE 7860
154
+
155
+ # Start the application
156
+ CMD ["/app/start.sh"]