From 140ea9637833cf11722221911331ed1693f3df1d Mon Sep 17 00:00:00 2001 From: lucca93 Date: Sun, 29 Oct 2023 11:02:25 +0100 Subject: [PATCH] Update Dockerfile --- backend/pyproject.toml | 2 +- docker/Dockerfile | 2 +- docker/Dockerfile_GitConnect | 59 ++++++++++++++++++++++++++++++++++++ docker/README.md | 19 ++++++++++-- 4 files changed, 78 insertions(+), 4 deletions(-) create mode 100644 docker/Dockerfile_GitConnect diff --git a/backend/pyproject.toml b/backend/pyproject.toml index 401a5b1..e5d74dc 100644 --- a/backend/pyproject.toml +++ b/backend/pyproject.toml @@ -6,7 +6,7 @@ authors = ["Your Name "] readme = "README.md" [tool.poetry.dependencies] -python = ">=3.9" +python = ">=3.9,<4.0" pandas = "*" scikit-learn = "^1.3.2" supabase = "^1.2.0" diff --git a/docker/Dockerfile b/docker/Dockerfile index 3233e16..31a4025 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -11,7 +11,7 @@ COPY backend/pyproject.toml backend/poetry.lock /app/ # Install dependencies without creating a virtual environment RUN poetry config virtualenvs.create false \ - && poetry install --no-dev --no-interaction --no-ansi + && poetry install --only main --no-interaction --no-ansi # Install Gunicorn RUN pip install gunicorn diff --git a/docker/Dockerfile_GitConnect b/docker/Dockerfile_GitConnect new file mode 100644 index 0000000..2c97576 --- /dev/null +++ b/docker/Dockerfile_GitConnect @@ -0,0 +1,59 @@ +# --- Backend Build Stage --- +FROM python:3.9-slim as backend + +WORKDIR /app + +# Install git and Poetry +RUN apt-get update && apt-get install -y git \ + && pip install poetry + +# Clone the repository from GitHub +RUN git clone https://github.com/your-username/your-repo.git . + +# Change to the backend directory +WORKDIR /app/backend + +# Install dependencies without creating a virtual environment +RUN poetry config virtualenvs.create false \ + && poetry install --no-dev --no-interaction --no-ansi + +# --- Frontend Build Stage --- +FROM node:14 as frontend + +WORKDIR /app + +# Install git +RUN apt-get update && apt-get install -y git + +# Clone the repository from GitHub +RUN git clone https://github.com/TobiasSchaeuble-EH/LunchHeroes.git . + +# Change to the frontend directory +WORKDIR /app/frontend + +# Install dependencies +RUN npm install + +# Build the frontend +RUN npm run build + +# --- Nginx Stage --- +FROM nginx:alpine + +# Copy the built frontend files to the Nginx server +COPY --from=frontend /app/frontend/build /usr/share/nginx/html + +# Copy the backend app to a directory served by Gunicorn +COPY --from=backend /app/backend /app + +# Set up Gunicorn to serve the backend app +COPY docker/gunicorn.conf /etc/gunicorn/gunicorn.conf + +# Set up Nginx to proxy requests to Gunicorn +COPY docker/nginx.conf /etc/nginx/conf.d/default.conf + +# Expose the necessary ports +EXPOSE 80 + +# Start Gunicorn and Nginx +CMD ["sh", "-c", "gunicorn -c /etc/gunicorn/gunicorn.conf app:app & nginx -g 'daemon off;'"] diff --git a/docker/README.md b/docker/README.md index 97a0431..a169636 100644 --- a/docker/README.md +++ b/docker/README.md @@ -2,13 +2,22 @@ This Docker setup is designed to build the Docker image for the LunchHeroes application, which can then be pushed to a Docker registry and deployed on a server. +# Important Links + - The server is hosted on [Flow Swiss](https://my.flow.swiss/). + - Repo is on DockerHub: [Dockerhub]https://hub.docker.com/repository/docker/lucca93/lunchheroes + - Link to Live App: http://app.lunchhero.ch/ or https://env-9057938.appengine.flow.ch/ + ## Preliminary Steps 1. **Building the Docker Image** - To build the Docker image, navigate to the directory containing the Dockerfile and run the following command: + To build the Docker image, navigate to the LunchHeroes and run the following command: + ```bash + docker build -t lunchheroes -f docker/Dockerfile . + ``` + Build the Docker Image directly from the Git Repo. ```bash - docker push lucca93/lunchheroes:latest + docker build -t lunchheroes -f docker/Dockerfile_GitConnect . ``` 2. **Pushing Docker Image:** @@ -16,11 +25,17 @@ This Docker setup is designed to build the Docker image for the LunchHeroes appl ```bash docker push lucca93/lunchheroes:latest ``` +3. **Redeploy Container in FlowEngine** + - Application Server + - Redeploy Container +<<<<<<< HEAD **Server Hosting:** - The server is hosted on [Flow Swiss](https://my.flow.swiss/). +======= +>>>>>>> a34e2f1731ef7ab569e9b273a1195ab4729d2df9 ## File Descriptions ### Dockerfile