mirror of
https://github.com/pablorevilla-meshtastic/meshview.git
synced 2026-03-04 23:27:46 +01:00
Container using slim/uv
This commit is contained in:
3
.dockerignore
Normal file
3
.dockerignore
Normal file
@@ -0,0 +1,3 @@
|
||||
# This keeps Docker from including hostOS virtual environment folders
|
||||
env/
|
||||
.venv/
|
||||
52
Containerfile
Normal file
52
Containerfile
Normal file
@@ -0,0 +1,52 @@
|
||||
# Build Image
|
||||
# Uses python:3.13-slim because no native dependencies are needed for meshview itself
|
||||
# (everything is available as a wheel)
|
||||
|
||||
FROM docker.io/python:3.13-slim AS meshview-build
|
||||
RUN apt-get update && \
|
||||
apt-get install -y --no-install-recommends curl patch && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Add a non-root user/group
|
||||
ARG APP_USER=app
|
||||
RUN useradd -m -u 10001 -s /bin/bash ${APP_USER}
|
||||
|
||||
# Install uv and put it on PATH system-wide
|
||||
RUN curl -LsSf https://astral.sh/uv/install.sh | sh \
|
||||
&& install -m 0755 /root/.local/bin/uv /usr/local/bin/uv
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy deps first for caching
|
||||
COPY --chown=${APP_USER}:${APP_USER} pyproject.toml uv.lock* requirements*.txt ./
|
||||
|
||||
# Optional: wheels-only to avoid slow source builds
|
||||
ENV UV_NO_BUILD=1
|
||||
RUN uv venv /opt/venv
|
||||
# RUN uv sync --frozen
|
||||
ENV VIRTUAL_ENV=/opt/venv
|
||||
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
|
||||
|
||||
RUN uv pip install --no-cache-dir --upgrade pip \
|
||||
&& if [ -f requirements.txt ]; then uv pip install --only-binary=:all: -r requirements.txt; fi
|
||||
|
||||
# Copy app code
|
||||
COPY --chown=${APP_USER}:${APP_USER} . .
|
||||
|
||||
# Created working directories with correct ownership/permissions
|
||||
RUN mkdir -p /etc/meshview /var/lib/meshview /var/log/meshview \
|
||||
&& chown -R ${APP_USER}:${APP_USER} /etc/meshview /var/lib/meshview /var/log/meshview
|
||||
|
||||
RUN patch sample.config.ini < container/config.patch
|
||||
RUN cp sample.config.ini /etc/meshview/config.ini
|
||||
RUN chown ${APP_USER}:${APP_USER} /etc/meshview/config.ini
|
||||
|
||||
# Drop privileges
|
||||
USER ${APP_USER}
|
||||
|
||||
ENTRYPOINT [ "uv", "run", "--active", "mvrun.py"]
|
||||
CMD ["--pid_dir", "/tmp", "--py_exec", "/opt/venv/bin/python", "--config", "/etc/meshview/config.ini" ]
|
||||
|
||||
EXPOSE 8081
|
||||
VOLUME [ "/etc/meshview", "/var/lib/meshview", "/var/log/meshview" ]
|
||||
|
||||
57
container/build-container.sh
Executable file
57
container/build-container.sh
Executable file
@@ -0,0 +1,57 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# build-container.sh
|
||||
#
|
||||
# Script to build MeshView container images
|
||||
|
||||
set -e
|
||||
|
||||
# Default values
|
||||
IMAGE_NAME="meshview"
|
||||
TAG="latest"
|
||||
CONTAINERFILE="Containerfile"
|
||||
|
||||
# Parse arguments
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
--tag|-t)
|
||||
TAG="$2"
|
||||
shift 2
|
||||
;;
|
||||
--name|-n)
|
||||
IMAGE_NAME="$2"
|
||||
shift 2
|
||||
;;
|
||||
--file|-f)
|
||||
CONTAINERFILE="$2"
|
||||
shift 2
|
||||
;;
|
||||
--help|-h)
|
||||
echo "Usage: $0 [OPTIONS]"
|
||||
echo ""
|
||||
echo "Options:"
|
||||
echo " -t, --tag TAG Tag for the image (default: latest)"
|
||||
echo " -n, --name NAME Image name (default: meshview)"
|
||||
echo " -f, --file FILE Containerfile path (default: Containerfile)"
|
||||
echo " -h, --help Show this help"
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "Unknown option: $1"
|
||||
echo "Use --help for usage information"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
echo "Building MeshView container image..."
|
||||
echo " Image: ${IMAGE_NAME}:${TAG}"
|
||||
echo " Containerfile: ${CONTAINERFILE}"
|
||||
echo ""
|
||||
|
||||
# Build the container
|
||||
docker build -f "${CONTAINERFILE}" -t "${IMAGE_NAME}:${TAG}" .
|
||||
|
||||
echo ""
|
||||
echo "Build complete!"
|
||||
echo "Run with: docker run --rm -p 8081:8081 ${IMAGE_NAME}:${TAG}"
|
||||
37
container/config.patch
Normal file
37
container/config.patch
Normal file
@@ -0,0 +1,37 @@
|
||||
diff --git a/sample.config.ini b/sample.config.ini
|
||||
index 0e64980..494685c 100644
|
||||
--- a/sample.config.ini
|
||||
+++ b/sample.config.ini
|
||||
@@ -3,7 +3,7 @@
|
||||
# -------------------------
|
||||
[server]
|
||||
# The address to bind the server to. Use * to listen on all interfaces.
|
||||
-bind = *
|
||||
+bind = 0.0.0.0
|
||||
|
||||
# Port to run the web server on.
|
||||
port = 8081
|
||||
@@ -64,7 +64,7 @@ net_tag = #BayMeshNet
|
||||
# -------------------------
|
||||
[mqtt]
|
||||
# MQTT server hostname or IP.
|
||||
-server = mqtt.bayme.sh
|
||||
+server = mqtt.meshtastic.org
|
||||
|
||||
# Topics to subscribe to (as JSON-like list, but still a string).
|
||||
topics = ["msh/US/bayarea/#", "msh/US/CA/mrymesh/#", "msh/US/CA/sacvalley"]
|
||||
@@ -82,7 +82,7 @@ password = large4cats
|
||||
# -------------------------
|
||||
[database]
|
||||
# SQLAlchemy connection string. This one uses SQLite with asyncio support.
|
||||
-connection_string = sqlite+aiosqlite:///packets.db
|
||||
+connection_string = sqlite+aiosqlite:////var/lib/meshview/packets.db
|
||||
|
||||
|
||||
# -------------------------
|
||||
@@ -110,4 +110,4 @@ vacuum = False
|
||||
# Set to True to enable, False to disable (default: False)
|
||||
access_log = False
|
||||
# Database cleanup logfile
|
||||
-db_cleanup_logfile = dbcleanup.log
|
||||
+db_cleanup_logfile = /var/log/meshview/dbcleanup.log
|
||||
Reference in New Issue
Block a user