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
|
# Set working directory
|
||||||
WORKDIR /app
|
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
|
# Set environment variables
|
||||||
ENV PYTHONDONTWRITEBYTECODE 1
|
ENV PYTHONDONTWRITEBYTECODE=1 \
|
||||||
ENV PYTHONUNBUFFERED 1
|
PYTHONUNBUFFERED=1 \
|
||||||
ENV FLASK_APP=app.py
|
FLASK_APP=${FLASK_APP} \
|
||||||
ENV FLASK_ENV=production
|
FLASK_ENV=${FLASK_ENV} \
|
||||||
|
STORAGE_URL=${STORAGE_URL}
|
||||||
|
|
||||||
# Install system dependencies
|
# Install system dependencies
|
||||||
RUN apt-get update \
|
RUN apt-get update \
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
import os
|
import os
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
# Load environment variables from .env file
|
# Only load .env file if we're in development
|
||||||
load_dotenv()
|
if os.environ.get('FLASK_ENV') != 'production':
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
BASE_DIR = os.path.abspath(os.path.dirname(__file__))
|
BASE_DIR = os.path.abspath(os.path.dirname(__file__))
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,22 @@
|
||||||
#!/bin/bash
|
#!/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)
|
# 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
|
# until PGPASSWORD=$DATABASE_PASSWORD psql -h "$DATABASE_HOST" -U "$DATABASE_USER" -d "$DATABASE_NAME" -c '\q'; do
|
||||||
# echo "Waiting for database..."
|
# echo "Waiting for database..."
|
||||||
|
@ -9,5 +26,9 @@
|
||||||
# Apply database migrations
|
# Apply database migrations
|
||||||
flask db upgrade
|
flask db upgrade
|
||||||
|
|
||||||
# Start gunicorn
|
# Start gunicorn with proper environment handling
|
||||||
exec gunicorn --bind 0.0.0.0:5000 app:app
|
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