fixed errors
Browse files- Dockerfile +3 -3
- README.md +23 -0
- docker-compose.yml +4 -4
- start.sh +36 -0
Dockerfile
CHANGED
|
@@ -44,7 +44,7 @@ RUN echo '#!/bin/sh\npython -c "import flask, flask_sqlalchemy, redis, celery; p
|
|
| 44 |
COPY --chown=appuser:appuser . .
|
| 45 |
|
| 46 |
# Make scripts executable
|
| 47 |
-
RUN chmod +x /app/prestart.sh /app/healthcheck.sh
|
| 48 |
|
| 49 |
# Switch to non-root user
|
| 50 |
USER appuser
|
|
@@ -52,5 +52,5 @@ USER appuser
|
|
| 52 |
# Expose the port
|
| 53 |
EXPOSE 5000
|
| 54 |
|
| 55 |
-
# Run the
|
| 56 |
-
CMD ["/
|
|
|
|
| 44 |
COPY --chown=appuser:appuser . .
|
| 45 |
|
| 46 |
# Make scripts executable
|
| 47 |
+
RUN chmod +x /app/prestart.sh /app/healthcheck.sh /app/start.sh
|
| 48 |
|
| 49 |
# Switch to non-root user
|
| 50 |
USER appuser
|
|
|
|
| 52 |
# Expose the port
|
| 53 |
EXPOSE 5000
|
| 54 |
|
| 55 |
+
# Run the startup script
|
| 56 |
+
CMD ["/app/start.sh"]
|
README.md
CHANGED
|
@@ -92,6 +92,8 @@ For production deployment, use Docker Compose:
|
|
| 92 |
docker-compose up -d
|
| 93 |
```
|
| 94 |
|
|
|
|
|
|
|
| 95 |
## Troubleshooting
|
| 96 |
|
| 97 |
### Missing Dependencies
|
|
@@ -123,6 +125,27 @@ Warnings about missing PyTorch, TensorFlow, or Flax are normal if you don't need
|
|
| 123 |
pip install torch==2.0.1
|
| 124 |
```
|
| 125 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
## Testing
|
| 127 |
Run the test suite:
|
| 128 |
```bash
|
|
|
|
| 92 |
docker-compose up -d
|
| 93 |
```
|
| 94 |
|
| 95 |
+
If you don't have a .env file, default development values will be used, but you should create one for production.
|
| 96 |
+
|
| 97 |
## Troubleshooting
|
| 98 |
|
| 99 |
### Missing Dependencies
|
|
|
|
| 125 |
pip install torch==2.0.1
|
| 126 |
```
|
| 127 |
|
| 128 |
+
#### Docker Startup Issues
|
| 129 |
+
If you encounter issues with Docker startup:
|
| 130 |
+
|
| 131 |
+
1. Check if the scripts are executable:
|
| 132 |
+
```bash
|
| 133 |
+
chmod +x prestart.sh start.sh healthcheck.sh
|
| 134 |
+
```
|
| 135 |
+
|
| 136 |
+
2. Verify the Docker logs:
|
| 137 |
+
```bash
|
| 138 |
+
docker-compose logs web
|
| 139 |
+
```
|
| 140 |
+
|
| 141 |
+
3. Try rebuilding the Docker image:
|
| 142 |
+
```bash
|
| 143 |
+
docker-compose build --no-cache web
|
| 144 |
+
docker-compose up -d
|
| 145 |
+
```
|
| 146 |
+
|
| 147 |
+
4. If you see syntax errors with parentheses, ensure the start.sh script is properly formatted and executable.
|
| 148 |
+
|
| 149 |
## Testing
|
| 150 |
Run the test suite:
|
| 151 |
```bash
|
docker-compose.yml
CHANGED
|
@@ -11,8 +11,8 @@ services:
|
|
| 11 |
- CELERY_BROKER_URL=redis://redis:6379/0
|
| 12 |
- CELERY_RESULT_BACKEND=redis://redis:6379/0
|
| 13 |
- INSTANCE_PATH=/tmp/instance
|
| 14 |
-
- SECRET_KEY=${SECRET_KEY}
|
| 15 |
-
- OPENAI_API_KEY=${OPENAI_API_KEY}
|
| 16 |
volumes:
|
| 17 |
- ./app:/app/app
|
| 18 |
- ./app/models:/app/models
|
|
@@ -37,8 +37,8 @@ services:
|
|
| 37 |
- CELERY_BROKER_URL=redis://redis:6379/0
|
| 38 |
- CELERY_RESULT_BACKEND=redis://redis:6379/0
|
| 39 |
- INSTANCE_PATH=/tmp/instance
|
| 40 |
-
- SECRET_KEY=${SECRET_KEY}
|
| 41 |
-
- OPENAI_API_KEY=${OPENAI_API_KEY}
|
| 42 |
volumes:
|
| 43 |
- ./app:/app/app
|
| 44 |
depends_on:
|
|
|
|
| 11 |
- CELERY_BROKER_URL=redis://redis:6379/0
|
| 12 |
- CELERY_RESULT_BACKEND=redis://redis:6379/0
|
| 13 |
- INSTANCE_PATH=/tmp/instance
|
| 14 |
+
- SECRET_KEY=${SECRET_KEY:-default-dev-key-change-in-production}
|
| 15 |
+
- OPENAI_API_KEY=${OPENAI_API_KEY:-sk-mock-key-for-development}
|
| 16 |
volumes:
|
| 17 |
- ./app:/app/app
|
| 18 |
- ./app/models:/app/models
|
|
|
|
| 37 |
- CELERY_BROKER_URL=redis://redis:6379/0
|
| 38 |
- CELERY_RESULT_BACKEND=redis://redis:6379/0
|
| 39 |
- INSTANCE_PATH=/tmp/instance
|
| 40 |
+
- SECRET_KEY=${SECRET_KEY:-default-dev-key-change-in-production}
|
| 41 |
+
- OPENAI_API_KEY=${OPENAI_API_KEY:-sk-mock-key-for-development}
|
| 42 |
volumes:
|
| 43 |
- ./app:/app/app
|
| 44 |
depends_on:
|
start.sh
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# start.sh - Application startup script
|
| 3 |
+
|
| 4 |
+
set -e # Exit immediately if a command exits with a non-zero status
|
| 5 |
+
|
| 6 |
+
echo "===== Starting Application at $(date -u '+%Y-%m-%d %H:%M:%S') ====="
|
| 7 |
+
|
| 8 |
+
# Run prestart script to check dependencies
|
| 9 |
+
if [ -f /app/prestart.sh ]; then
|
| 10 |
+
echo "Running prestart script..."
|
| 11 |
+
/app/prestart.sh
|
| 12 |
+
if [ $? -ne 0 ]; then
|
| 13 |
+
echo "Error: Prestart script failed. Exiting."
|
| 14 |
+
exit 1
|
| 15 |
+
fi
|
| 16 |
+
else
|
| 17 |
+
echo "Warning: Prestart script not found."
|
| 18 |
+
fi
|
| 19 |
+
|
| 20 |
+
# Check if gunicorn is installed
|
| 21 |
+
if ! command -v gunicorn &> /dev/null; then
|
| 22 |
+
echo "Error: gunicorn is not installed. Installing..."
|
| 23 |
+
pip install --no-cache-dir gunicorn
|
| 24 |
+
fi
|
| 25 |
+
|
| 26 |
+
# Check if gunicorn config exists
|
| 27 |
+
if [ ! -f ./gunicorn.conf.py ]; then
|
| 28 |
+
echo "Warning: gunicorn.conf.py not found. Using default configuration."
|
| 29 |
+
GUNICORN_OPTS="--workers=2 --bind=0.0.0.0:5000"
|
| 30 |
+
else
|
| 31 |
+
GUNICORN_OPTS="--config=./gunicorn.conf.py --workers=2"
|
| 32 |
+
fi
|
| 33 |
+
|
| 34 |
+
# Start gunicorn
|
| 35 |
+
echo "Starting gunicorn..."
|
| 36 |
+
exec gunicorn $GUNICORN_OPTS "app:create_app()"
|