diff --git a/.DS_Store b/.DS_Store index bb29be06..e07f5f73 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/mih_ui/Dockerfile b/mih_ui/Dockerfile index 1664c3c1..fe4435fc 100644 --- a/mih_ui/Dockerfile +++ b/mih_ui/Dockerfile @@ -1,48 +1,36 @@ -# Install Operating system and dependencies -#FROM ubuntu:22.04 +# --- STAGE 1: The Builder --- FROM debian:latest AS build-env -#ENV DEBIAN_FRONTEND=noninteractive +# Install necessary dependencies for Flutter +RUN apt-get update && apt-get install -y \ + curl git wget unzip libglu1-mesa fonts-droid-fallback python3 \ + && rm -rf /var/lib/apt/lists/* -RUN apt-get update --fix-missing - -RUN apt-get install -y curl git wget unzip gdb libstdc++6 libglu1-mesa fonts-droid-fallback -# RUN apt-get install -y curl git wget unzip libgconf-2-4 gdb libstdc++6 libglu1-mesa fonts-droid-fallback -RUN apt-get install python3 -y - -# download Flutter SDK from Flutter Github repo +# Clone Flutter SDK RUN git clone -b flutter-3.32-candidate.0 https://github.com/flutter/flutter.git /usr/local/flutter -# RUN git clone -b stable https://github.com/flutter/flutter.git /usr/local/flutter - -# Set flutter environment path ENV PATH="/usr/local/flutter/bin:/usr/local/flutter/bin/cache/dart-sdk/bin:${PATH}" -#ENV PATH "$PATH:/home/developer/flutter/bin" - -RUN flutter doctor -v - -# Enable flutter web -RUN flutter channel flutter-3.32-candidate.0 -# RUN flutter channel stable -RUN flutter config --enable-web - -# Copy files to container and build -RUN mkdir /app/ -COPY . /app/ +# Build the Flutter web app WORKDIR /app -# RUN flutter upgrade +COPY . . +RUN flutter config --enable-web RUN flutter build web --release -t ./lib/main_prod.dart -# RUN flutter build web --release --web-renderer canvaskit -t ./lib/main_prod.dart +# --- STAGE 2: The Final Production Image --- +FROM nginx:alpine -# RUN cd .. +# Copy built files from the first stage +COPY --from=build-env /app/build/web /usr/share/nginx/html -# WORKDIR /app/build/web/ +# Create the Nginx config inside the Dockerfile to handle SPA routing +RUN echo 'server { \ + listen 83; \ + location / { \ + root /usr/share/nginx/html; \ + index index.html; \ + try_files $uri $uri/ /index.html; \ + } \ + }' > /etc/nginx/conf.d/default.conf EXPOSE 83 - -RUN ["chmod", "+x", "/app/server/server.sh"] - -ENTRYPOINT [ "/app/server/server.sh"] - -# RUN ["python3", "-u", "/app/server/MIH_web_server.py"] \ No newline at end of file +CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/mih_ui/server/MIH_web_server.py b/mih_ui/server/MIH_web_server.py deleted file mode 100644 index c4bd7eb0..00000000 --- a/mih_ui/server/MIH_web_server.py +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env python - -# Inspired by https://gist.github.com/jtangelder/e445e9a7f5e31c220be6 -# Python3 http.server for Single Page Application - -import urllib.parse -import http.server -import socketserver -import re -from pathlib import Path -port = 83 -HOST = ('', port) -pattern = re.compile('.png|.jpg|.jpeg|.js|.css|.ico|.gif|.svg|.ico', re.IGNORECASE) - - -class Handler(http.server.SimpleHTTPRequestHandler): - def do_GET(self): - url_parts = urllib.parse.urlparse(self.path) - request_file_path = Path(url_parts.path.strip("/")) - - ext = request_file_path.suffix - if not request_file_path.is_file() and not pattern.match(ext): - self.path = 'index.html' - - return http.server.SimpleHTTPRequestHandler.do_GET(self) - - -httpd = socketserver.TCPServer(HOST, Handler) -print(f"Starting Web App Server on pot: {port}") -httpd.serve_forever() diff --git a/mih_ui/server/server.sh b/mih_ui/server/server.sh deleted file mode 100644 index 2fb5d8b7..00000000 --- a/mih_ui/server/server.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -# Define the port -PORT=83 - -# Check if the port is in use and release it if necessary. -# echo "Checking if port $PORT is in use..." -# if [ "$(lsof -t -i :$PORT)" ]; then -# echo "Port $PORT is in use. Stopping the process on that port..." -# fuser -k -n tcp $PORT -# fi - -# Switch to the web construction directory -cd /app/build/web/ - -# Start the web server on the specified port -#python3 -m http.server 83 -python3 -u ../../server/MIH_web_server.py \ No newline at end of file