enable docker DB migrations
This commit is contained in:
10
Dockerfile
10
Dockerfile
@@ -6,6 +6,7 @@ WORKDIR /app
|
||||
RUN apt-get update && apt-get install -y \
|
||||
gcc \
|
||||
postgresql-client \
|
||||
netcat-traditional \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Copy requirements first to leverage Docker cache
|
||||
@@ -15,12 +16,15 @@ RUN pip install --no-cache-dir -r requirements.txt
|
||||
# Copy the rest of the application
|
||||
COPY . .
|
||||
|
||||
# Make entrypoint script executable
|
||||
RUN chmod +x entrypoint.sh
|
||||
|
||||
# Set environment variables
|
||||
ENV FLASK_APP=app.py
|
||||
ENV FLASK_ENV=development
|
||||
ENV FLASK_ENV=production
|
||||
|
||||
# Expose the port the app runs on
|
||||
EXPOSE 5000
|
||||
|
||||
# Command to run the application
|
||||
CMD ["gunicorn", "--bind", "0.0.0.0:5000", "app:app"]
|
||||
# Use the entrypoint script
|
||||
ENTRYPOINT ["./entrypoint.sh"]
|
||||
23
entrypoint.sh
Normal file
23
entrypoint.sh
Normal file
@@ -0,0 +1,23 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Wait for the database to be ready
|
||||
echo "Waiting for database to be ready..."
|
||||
while ! nc -z db 5432; do
|
||||
sleep 0.1
|
||||
done
|
||||
echo "Database is ready!"
|
||||
|
||||
# Initialize the database
|
||||
flask db upgrade
|
||||
|
||||
# Create default site settings if they don't exist
|
||||
python3 -c "
|
||||
from app import create_app
|
||||
from models import SiteSettings, db
|
||||
app = create_app()
|
||||
with app.app_context():
|
||||
SiteSettings.get_settings()
|
||||
"
|
||||
|
||||
# Start the application
|
||||
exec gunicorn --bind 0.0.0.0:5000 app:app
|
||||
Reference in New Issue
Block a user