backend container works

This commit is contained in:
Hubert Dwornik 2024-05-12 19:14:07 +02:00
parent ff722f72bf
commit 8f4b8a5494
3 changed files with 40 additions and 26 deletions

View File

@ -1,14 +1,25 @@
FROM python:3.11-bullseye
# Use an official Python runtime as a parent image
FROM python:3.10-slim
WORKDIR /code
# Set the working directory to /app
WORKDIR /app
COPY ./connector/Include/*.* .
COPY ./connector/Include/init_scripts/*.* ./init_scripts/*.*
# Install necessary OS packages
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
libpq-dev \
&& rm -rf /var/lib/apt/lists/*
ENV PIP_DISABLE_PIP_VERSION_CHECK 1
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# Copy the Python script, requirements, and constants.ini file into the container at /app
COPY connector/Include/frontend_AI_connector.py /app/
COPY connector/Include/requirements.txt /app/
COPY connector/Include/init_scripts/constants.ini /app/init_scripts/
RUN pip install -r requirements.txt
# Modify requirements.txt to use psycopg2-binary
RUN sed -i 's/psycopg2==2.9.9/psycopg2-binary==2.9.9/' requirements.txt
COPY . .
# Install any needed packages specified in requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
# Run frontend_AI_connector.py when the container launches
CMD ["python", "./frontend_AI_connector.py"]

View File

@ -69,13 +69,20 @@ if __name__ == "__main__":
config = ConfigParser()
config.read("init_scripts/constants.ini")
conn = psycopg2.connect(
host=config["postgres"]["host"],
database=config["postgres"]["database"],
user=config["postgres"]["user"],
password=config["postgres"]["password"],
port=int(config["postgres"]["port"])
)
while True:
try:
conn = psycopg2.connect(
host=config["postgres"]["host"],
database=config["postgres"]["database"],
user=config["postgres"]["user"],
password=config["postgres"]["password"],
port=int(config["postgres"]["port"])
)
except Exception:
print("Trying to connect with database")
continue
else:
break
movie_list = pandas.read_csv(config["movie"]["csv_path"])

View File

@ -1,29 +1,25 @@
version: "3.8"
version: '3.8'
services:
connector:
container_name: connector_container
app:
build: .
volumes:
- .:/code
- ./connector/Include:/app
ports:
- 8090:8090
- "8090:8090" # Adjust if your app uses a different port
depends_on:
- db
command:
- python3 ./frontend_AI_connector.py
db:
container_name: db_container
image: postgres:13
environment:
POSTGRES_DB: test_db
POSTGRES_USER: root
POSTGRES_PASSWORD: root
POSTGRES_DB: test_db
ports:
- 5432:5432
volumes:
- postgres_data:/var/lib/postgresql/data
- ./database/init.sql:/docker-entrypoint-initdb.d/init.sql
- postgres_data:/var/lib/postgresql/data/
pgadmin:
container_name: admin_container
image: dpage/pgadmin4