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/*.* . # Install necessary OS packages
COPY ./connector/Include/init_scripts/*.* ./init_scripts/*.* 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 # Copy the Python script, requirements, and constants.ini file into the container at /app
ENV PYTHONDONTWRITEBYTECODE 1 COPY connector/Include/frontend_AI_connector.py /app/
ENV PYTHONUNBUFFERED 1 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 = ConfigParser()
config.read("init_scripts/constants.ini") config.read("init_scripts/constants.ini")
conn = psycopg2.connect( while True:
host=config["postgres"]["host"], try:
database=config["postgres"]["database"], conn = psycopg2.connect(
user=config["postgres"]["user"], host=config["postgres"]["host"],
password=config["postgres"]["password"], database=config["postgres"]["database"],
port=int(config["postgres"]["port"]) 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"]) movie_list = pandas.read_csv(config["movie"]["csv_path"])

View File

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