fix: use script file instead of heredoc in Dockerfile
This commit is contained in:
@@ -12,32 +12,7 @@ COPY requirements.txt .
|
|||||||
RUN pip install --no-cache-dir -r requirements.txt
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
RUN chmod +x /app/start.sh
|
||||||
# Create startup script
|
|
||||||
RUN cat > /start.sh << 'EOF'
|
|
||||||
#!/bin/bash
|
|
||||||
set -e
|
|
||||||
echo "Waiting for database..."
|
|
||||||
until python -c "
|
|
||||||
import psycopg2, os
|
|
||||||
try:
|
|
||||||
conn = psycopg2.connect(os.environ.get('DATABASE_URL', 'postgresql://servesync:servesync@db:5432/servesync'))
|
|
||||||
conn.close()
|
|
||||||
print('DB ready')
|
|
||||||
except Exception as e:
|
|
||||||
print(f'DB not ready: {e}')
|
|
||||||
exit(1)
|
|
||||||
"; do
|
|
||||||
sleep 2
|
|
||||||
done
|
|
||||||
|
|
||||||
echo "Running seed..."
|
|
||||||
python seed.py || echo "Seed already ran or error (continuing)"
|
|
||||||
|
|
||||||
echo "Starting server..."
|
|
||||||
exec uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload
|
|
||||||
EOF
|
|
||||||
RUN chmod +x /start.sh
|
|
||||||
|
|
||||||
EXPOSE 8000
|
EXPOSE 8000
|
||||||
CMD ["/start.sh"]
|
CMD ["/app/start.sh"]
|
||||||
|
|||||||
21
backend/start.sh
Normal file
21
backend/start.sh
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
echo "Waiting for database..."
|
||||||
|
until python -c "
|
||||||
|
import psycopg2, os
|
||||||
|
try:
|
||||||
|
conn = psycopg2.connect(os.environ.get('DATABASE_URL', 'postgresql://servesync:servesync@db:5432/servesync'))
|
||||||
|
conn.close()
|
||||||
|
print('DB ready')
|
||||||
|
except Exception as e:
|
||||||
|
print(f'DB not ready: {e}')
|
||||||
|
exit(1)
|
||||||
|
"; do
|
||||||
|
sleep 2
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "Running seed..."
|
||||||
|
python seed.py || echo "Seed already ran or error (continuing)"
|
||||||
|
|
||||||
|
echo "Starting server..."
|
||||||
|
exec uvicorn app.main:app --host 0.0.0.0 --port 8000
|
||||||
Reference in New Issue
Block a user