From c71c1568d21bcb4e1d4f4850e19974e6f7cee44b Mon Sep 17 00:00:00 2001 From: Albrecht Lohofener Date: Wed, 19 Mar 2025 21:16:48 +0100 Subject: [PATCH] Add angular web ui to Docker image --- Dockerfile | 27 +++++++++++++++------ web-frontend/angular.json | 4 ++-- web-frontend/nginx.conf.generic | 40 +------------------------------- web-frontend/nginx.conf.u-os-app | 26 +-------------------- 4 files changed, 24 insertions(+), 73 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4c18ece..f0e16da 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ # Build stage for rust backend ######################################################################################################################## -FROM rust:alpine AS builder +FROM rust:alpine AS build-backend ARG TARGETPLATFORM @@ -30,12 +30,24 @@ RUN if [ "$TARGETPLATFORM" = "linux/arm64" ]; then \ cp /usr/src/qemu-backend/target/x86_64-unknown-linux-musl/release/qemu-openwrt-web-backend /usr/local/bin; \ fi +######################################################################################################################## +# Build stage for angular frontend +######################################################################################################################## + +FROM node:latest as build-frontend + +WORKDIR /usr/local/app +COPY ./web-frontend /usr/local/app/ + +RUN npm install +RUN npm run build + ######################################################################################################################## # OpenWrt image ######################################################################################################################## FROM alpine:latest -ARG NOVNC_VERSION="1.5.0" +ARG NOVNC_VERSION="1.5.0" ARG OPENWRT_VERSION="24.10.0" ARG TARGETPLATFORM ARG OPENWRT_ROOTFS_IMG @@ -140,14 +152,14 @@ RUN echo "Building for platform '$TARGETPLATFORM'" \ \ # OpenWrt master uses apk insted of opkg \ && if [ "$OPENWRT_VERSION" = "master" ]; then \ - PACKAGE_UPDATE="apk update"; \ + PACKAGE_UPDATE="apk update"; \ PACKAGE_INSTALL="apk add"; \ PACKAGE_REMOVE="apk del"; \ PACKAGE_EXTRA="libudev-zero"; \ else \ PACKAGE_UPDATE="opkg update"; \ PACKAGE_INSTALL="opkg install"; \ - PACKAGE_REMOVE="opkg remove"; \ + PACKAGE_REMOVE="opkg remove"; \ PACKAGE_EXTRA=""; \ fi \ \ @@ -163,7 +175,7 @@ RUN echo "Building for platform '$TARGETPLATFORM'" \ && ssh root@localhost -p $SSH_PORT "${PACKAGE_INSTALL} hostapd wpa-supplicant kmod-mt7921u" \ # Download celluar network support \ && ssh root@localhost -p $SSH_PORT "${PACKAGE_INSTALL} modemmanager kmod-usb-net-qmi-wwan luci-proto-modemmanager qmi-utils" \ - # Download basic GPS support \ + # Download basic GPS support \ && ssh root@localhost -p $SSH_PORT "${PACKAGE_INSTALL} kmod-usb-serial minicom gpsd" \ # Add Wireguard support \ && ssh root@localhost -p $SSH_PORT "${PACKAGE_INSTALL} wireguard-tools luci-proto-wireguard" \ @@ -191,9 +203,10 @@ RUN echo "Building for platform '$TARGETPLATFORM'" \ && echo "OPENWRT_CPU_ARCH=\"${TARGETPLATFORM}\"" >> /var/vm/openwrt_metadata.conf \ && echo "CONTAINER_CREATE_DATETIME=\"`date`\"" >> /var/vm/openwrt_metadata.conf -COPY --from=builder /usr/local/bin/qemu-openwrt-web-backend /usr/local/bin/qemu-openwrt-web-backend +COPY --from=build-backend /usr/local/bin/qemu-openwrt-web-backend /usr/local/bin/qemu-openwrt-web-backend +COPY --from=build-frontend /usr/local/app/dist/openwrt-docker-web-gui /var/www/ +COPY ./web-frontend/nginx* /var/www/ COPY ./src /run/ -COPY ./web-frontend /var/www/ RUN chmod +x /run/*.sh diff --git a/web-frontend/angular.json b/web-frontend/angular.json index 156a9bf..0dd21a6 100644 --- a/web-frontend/angular.json +++ b/web-frontend/angular.json @@ -45,8 +45,8 @@ "budgets": [ { "type": "initial", - "maximumWarning": "500kB", - "maximumError": "1MB" + "maximumWarning": "4MB", + "maximumError": "8MB" }, { "type": "anyComponentStyle", diff --git a/web-frontend/nginx.conf.generic b/web-frontend/nginx.conf.generic index dff6913..8c2349d 100644 --- a/web-frontend/nginx.conf.generic +++ b/web-frontend/nginx.conf.generic @@ -26,45 +26,7 @@ server { add_header Cache-Control "no-cache"; location / { - root /var/www; - } - - location /novnc { - index vnc.html; - alias /usr/share/novnc; - try_files $uri $uri/ /vnc.html; - - if ($request_uri = "/novnc/") { - return 301 ?resize=scale&autoconnect=true&reconnect_delay=2000&reconnect=true; - } - } - - location /websockify { - - proxy_http_version 1.1; - - proxy_set_header Connection 'upgrade'; - proxy_set_header Upgrade $http_upgrade; - - proxy_buffering off; - proxy_read_timeout 3600s; - proxy_send_timeout 3600s; - - proxy_pass http://127.0.0.1:5700/; - } - - location /script-server/ { - proxy_pass_header Server; - proxy_set_header Host $proxy_host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_pass http://127.0.0.1:5000/; - - # needed for websockets - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "upgrade"; - proxy_set_header Origin http://$proxy_host; + root /var/www/browser; } location /api/ { diff --git a/web-frontend/nginx.conf.u-os-app b/web-frontend/nginx.conf.u-os-app index 9b3c107..25a63c0 100644 --- a/web-frontend/nginx.conf.u-os-app +++ b/web-frontend/nginx.conf.u-os-app @@ -26,31 +26,7 @@ server { add_header Cache-Control "no-cache"; location / { - root /var/www; - } - - location /novnc { - index vnc.html; - alias /usr/share/novnc; - try_files $uri $uri/ /vnc.html; - - if ($request_uri = "/novnc/") { - return 301 ?resize=scale&autoconnect=true&reconnect_delay=2000&reconnect=true&path=u-os-app-openwrt/websockify; - } - } - - location /websockify { - - proxy_http_version 1.1; - - proxy_set_header Connection 'upgrade'; - proxy_set_header Upgrade $http_upgrade; - - proxy_buffering off; - proxy_read_timeout 3600s; - proxy_send_timeout 3600s; - - proxy_pass http://127.0.0.1:5700/; + root /var/www/browser; } location /api/ {