Update Dockerfile

This commit is contained in:
servdal
2025-07-17 06:31:35 +07:00
parent cedb72d57f
commit 3237dbf10c
7 changed files with 53 additions and 13 deletions

2
.env
View File

@@ -1 +1,3 @@
PG_PASS=guR8uchQhQFAGi4yXfHPrF2AHTgN15sOViDL7tu0bfoiPmdI
PG_USER=lismikro
PG_DB=lismikro

View File

@@ -36,20 +36,21 @@ services:
ports:
- "8088:8080"
depends_on:
- laravel-db
- postgresql
command: php artisan serve --host=0.0.0.0 --port=8080
networks:
- proxy
python-listener:
build:
context: ./htdocs/listenerlist
context: ./htdocs/listenerlis
dockerfile: Dockerfile
container_name: python-listener
restart: unless-stopped
volumes:
- ./htdocs/listenerlist:/app
- ./htdocs/listenerlis:/app
depends_on:
- laravel-db
postgresql:
condition: service_healthy
networks:
- proxy
networks:

View File

@@ -60,7 +60,10 @@ WORKDIR /var/www/html
# RUN composer create-project laravel/laravel:^10 /var/www/html
# Set permission
RUN chown -R www-data:www-data /var/www/html/storage /var/www/html/bootstrap/cache
# RUN chown -R www-data:www-data /var/www/html/htdocs/storage /var/www/html/htdocs/bootstrap/cache
EXPOSE 9000
CMD ["php-fpm"]
#CMD ["php-fpm"]
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]

19
htdocs/entrypoint.sh Normal file
View File

@@ -0,0 +1,19 @@
#!/bin/bash
# Tunggu database siap
until php artisan migrate:status > /dev/null 2>&1; do
echo "Waiting for database to be ready..."
sleep 3
done
# Cek apakah migration sudah pernah dijalankan
if php artisan migrate:status | grep -q "| Y"; then
echo "Database already migrated, skipping migration and seeding."
else
echo "Running migrations and seeders..."
php artisan migrate --force
php artisan db:seed --force
fi
# Jalankan Laravel server
exec php artisan serve --host=0.0.0.0 --port=8080

View File

@@ -2,10 +2,8 @@ FROM python:3.11-slim
WORKDIR /app
COPY app.py .
COPY . /app
# Jika ada requirements.txt, tambahkan:
# COPY requirements.txt .
# RUN pip install --no-cache-dir -r requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
CMD ["python", "app.py"]
CMD ["python", "app.py"]

View File

@@ -6,7 +6,8 @@ from flask import Flask, request, jsonify
from sqlalchemy import create_engine, Column, Integer, String, Text, ForeignKey, DateTime
from sqlalchemy.orm import declarative_base, sessionmaker
import datetime
import time
from sqlalchemy.exc import OperationalError
# Konfigurasi logging
logging.basicConfig(
filename='listener.log',
@@ -18,9 +19,21 @@ logging.basicConfig(
app = Flask(__name__)
# Konfigurasi Database dengan SQLAlchemy
DATABASE_URL = "postgresql://lismikro:lismikro@localhost:5432/lismikro"
DATABASE_URL = "postgresql://lismikro:lismikro@postgresql:5432/lismikro"
engine = create_engine(DATABASE_URL)
SessionLocal = sessionmaker(bind=engine)
for i in range(10):
try:
engine = create_engine(DATABASE_URL)
connection = engine.connect()
connection.close()
print("Database connected successfully.")
break
except OperationalError as e:
print(f"Database not ready yet ({i+1}/10): {e}")
time.sleep(5)
else:
raise Exception("Database not available after 10 attempts")
Base = declarative_base()
# Model Database

View File

@@ -0,0 +1,4 @@
flask
sqlalchemy
hl7
psycopg2-binary