From acbb009e74ca8f63f789fee9f2b91f62fdc2cd89 Mon Sep 17 00:00:00 2001 From: Francisco Mendonca <francisco.mendonca@hesge.ch> Date: Mon, 9 Dec 2024 10:06:28 +0000 Subject: [PATCH] Dockerfiles - NOT TESTED!!!! --- Application/backend/{backend => }/app.log | 0 Application/backend/backend/.env | 4 -- Application/backend/{backend => }/main.py | 0 Application/backend/requirements.txt | 4 ++ Application/frontend/{frontend => }/main.py | 0 Application/frontend/requirements.txt | 2 + .../{frontend => }/views/dashboard.html | 0 .../frontend/{frontend => }/views/index.html | 0 .../frontend/{frontend => }/views/login.html | 0 .../frontend/{frontend => }/views/signup.html | 0 Docker/Dockerfile-backend | 37 +++++++++++++++++++ Docker/Dockerfile-frontend | 24 ++++++++++++ 12 files changed, 67 insertions(+), 4 deletions(-) rename Application/backend/{backend => }/app.log (100%) delete mode 100644 Application/backend/backend/.env rename Application/backend/{backend => }/main.py (100%) create mode 100644 Application/backend/requirements.txt rename Application/frontend/{frontend => }/main.py (100%) create mode 100644 Application/frontend/requirements.txt rename Application/frontend/{frontend => }/views/dashboard.html (100%) rename Application/frontend/{frontend => }/views/index.html (100%) rename Application/frontend/{frontend => }/views/login.html (100%) rename Application/frontend/{frontend => }/views/signup.html (100%) create mode 100644 Docker/Dockerfile-backend create mode 100644 Docker/Dockerfile-frontend diff --git a/Application/backend/backend/app.log b/Application/backend/app.log similarity index 100% rename from Application/backend/backend/app.log rename to Application/backend/app.log diff --git a/Application/backend/backend/.env b/Application/backend/backend/.env deleted file mode 100644 index e3d79b3..0000000 --- a/Application/backend/backend/.env +++ /dev/null @@ -1,4 +0,0 @@ -SWTICH_ACCESS_KEY_ID=4406dbe746a24614a9bc8f7ec864e59f -SWITCH_SECRET_ACCESS_KEY=cec6e60954b24a51923fe5aaea9fbb3b -SWTICH_ENDPOINT_URL=https://os.zhdk.cloud.switch.ch -S3_BUCKET_NAME=cloud-bach-proj \ No newline at end of file diff --git a/Application/backend/backend/main.py b/Application/backend/main.py similarity index 100% rename from Application/backend/backend/main.py rename to Application/backend/main.py diff --git a/Application/backend/requirements.txt b/Application/backend/requirements.txt new file mode 100644 index 0000000..e7c8192 --- /dev/null +++ b/Application/backend/requirements.txt @@ -0,0 +1,4 @@ +flask +flask-cors +boto3 +python-dotenv \ No newline at end of file diff --git a/Application/frontend/frontend/main.py b/Application/frontend/main.py similarity index 100% rename from Application/frontend/frontend/main.py rename to Application/frontend/main.py diff --git a/Application/frontend/requirements.txt b/Application/frontend/requirements.txt new file mode 100644 index 0000000..4e20788 --- /dev/null +++ b/Application/frontend/requirements.txt @@ -0,0 +1,2 @@ +Flask==2.0.1 +Werkzeug==2.0.1 \ No newline at end of file diff --git a/Application/frontend/frontend/views/dashboard.html b/Application/frontend/views/dashboard.html similarity index 100% rename from Application/frontend/frontend/views/dashboard.html rename to Application/frontend/views/dashboard.html diff --git a/Application/frontend/frontend/views/index.html b/Application/frontend/views/index.html similarity index 100% rename from Application/frontend/frontend/views/index.html rename to Application/frontend/views/index.html diff --git a/Application/frontend/frontend/views/login.html b/Application/frontend/views/login.html similarity index 100% rename from Application/frontend/frontend/views/login.html rename to Application/frontend/views/login.html diff --git a/Application/frontend/frontend/views/signup.html b/Application/frontend/views/signup.html similarity index 100% rename from Application/frontend/frontend/views/signup.html rename to Application/frontend/views/signup.html diff --git a/Docker/Dockerfile-backend b/Docker/Dockerfile-backend new file mode 100644 index 0000000..b2beaa8 --- /dev/null +++ b/Docker/Dockerfile-backend @@ -0,0 +1,37 @@ +# Use Python 3.11 slim image as base +FROM python:3.11-slim + +# Set working directory +WORKDIR /app + +# Set environment variables +ENV PYTHONDONTWRITEBYTECODE=1 \ + PYTHONUNBUFFERED=1 \ + FLASK_APP=backend/main.py \ + FLASK_ENV=development + +# Install system dependencies +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + gcc \ + python3-dev \ + && rm -rf /var/lib/apt/lists/* + +# Copy requirements first to leverage Docker cache +COPY requirements.txt . + +# Install Python dependencies +RUN pip install --no-cache-dir -r requirements.txt + +# Copy the rest of the application +COPY . . + +# Create a non-root user and switch to it +RUN useradd -m appuser && chown -R appuser:appuser /app +USER appuser + +# Expose the port the app runs on +EXPOSE 8000 + +# Command to run the application +CMD ["python3", "backend/main.py"] \ No newline at end of file diff --git a/Docker/Dockerfile-frontend b/Docker/Dockerfile-frontend new file mode 100644 index 0000000..c238aa0 --- /dev/null +++ b/Docker/Dockerfile-frontend @@ -0,0 +1,24 @@ +# Use Python 3.9 slim image as base +FROM python:3.9-slim + +# Set working directory in container +WORKDIR /app + +# Copy requirements first to leverage Docker cache +COPY requirements.txt . + +# Install dependencies +RUN pip install --no-cache-dir -r requirements.txt + +# Copy the rest of the application +COPY . . + +# Create a non-root user for security +RUN useradd -m myuser +USER myuser + +# Expose the port the app runs on +EXPOSE 3000 + +# Command to run the application +CMD ["python", "main.py"] \ No newline at end of file -- GitLab