Fixing issues with env
All checks were successful
Build and Publish Docker Image / build (push) Successful in 3m33s
All checks were successful
Build and Publish Docker Image / build (push) Successful in 3m33s
This commit is contained in:
parent
90fd42782a
commit
88d4fc909a
3 changed files with 36 additions and 8 deletions
14
Dockerfile
14
Dockerfile
|
@ -4,11 +4,17 @@ FROM python:3.9-slim
|
|||
# Set working directory
|
||||
WORKDIR /app
|
||||
|
||||
# Set build-time arguments
|
||||
ARG FLASK_ENV=production
|
||||
ARG FLASK_APP=app.py
|
||||
ARG STORAGE_URL=file:///app/static/uploads
|
||||
|
||||
# Set environment variables
|
||||
ENV PYTHONDONTWRITEBYTECODE 1
|
||||
ENV PYTHONUNBUFFERED 1
|
||||
ENV FLASK_APP=app.py
|
||||
ENV FLASK_ENV=production
|
||||
ENV PYTHONDONTWRITEBYTECODE=1 \
|
||||
PYTHONUNBUFFERED=1 \
|
||||
FLASK_APP=${FLASK_APP} \
|
||||
FLASK_ENV=${FLASK_ENV} \
|
||||
STORAGE_URL=${STORAGE_URL}
|
||||
|
||||
# Install system dependencies
|
||||
RUN apt-get update \
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import os
|
||||
from dotenv import load_dotenv
|
||||
|
||||
# Load environment variables from .env file
|
||||
load_dotenv()
|
||||
# Only load .env file if we're in development
|
||||
if os.environ.get('FLASK_ENV') != 'production':
|
||||
load_dotenv()
|
||||
|
||||
BASE_DIR = os.path.abspath(os.path.dirname(__file__))
|
||||
|
||||
|
|
|
@ -1,5 +1,22 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Function to check required environment variables
|
||||
check_required_vars() {
|
||||
local missing_vars=0
|
||||
for var in "$@"; do
|
||||
if [ -z "${!var}" ]; then
|
||||
echo "Error: Required environment variable $var is not set"
|
||||
missing_vars=1
|
||||
fi
|
||||
done
|
||||
if [ $missing_vars -eq 1 ]; then
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Check required environment variables (add your required variables here)
|
||||
check_required_vars "FLASK_APP" "FLASK_ENV" "STORAGE_URL"
|
||||
|
||||
# Wait for database to be ready (if using PostgreSQL)
|
||||
# until PGPASSWORD=$DATABASE_PASSWORD psql -h "$DATABASE_HOST" -U "$DATABASE_USER" -d "$DATABASE_NAME" -c '\q'; do
|
||||
# echo "Waiting for database..."
|
||||
|
@ -9,5 +26,9 @@
|
|||
# Apply database migrations
|
||||
flask db upgrade
|
||||
|
||||
# Start gunicorn
|
||||
exec gunicorn --bind 0.0.0.0:5000 app:app
|
||||
# Start gunicorn with proper environment handling
|
||||
exec gunicorn --bind 0.0.0.0:5000 \
|
||||
--env FLASK_APP=${FLASK_APP} \
|
||||
--env FLASK_ENV=${FLASK_ENV} \
|
||||
--env STORAGE_URL=${STORAGE_URL} \
|
||||
app:app
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue