From 22d8ea1e49ee3e750dc8cd430831b9a8f40a38e3 Mon Sep 17 00:00:00 2001 From: Oleksander Piskun Date: Tue, 15 Apr 2025 10:02:25 +0300 Subject: [PATCH] feat: added HaRP support for Nextcloud 32 Signed-off-by: Oleksander Piskun --- Dockerfile | 19 ++++++++++++++- healthcheck.sh | 8 ++++++- start.sh | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 start.sh diff --git a/Dockerfile b/Dockerfile index a6e3985..f1b973b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,6 +9,22 @@ RUN apt-get update --fix-missing RUN apt install -y pipx build-essential git vim RUN pipx install poetry +# Download and install FRP client into /usr/local/bin. +RUN set -ex; \ + ARCH=$(uname -m); \ + if [ "$ARCH" = "aarch64" ]; then \ + FRP_URL="https://raw.githubusercontent.com/nextcloud/HaRP/main/exapps_dev/frp_0.61.1_linux_arm64.tar.gz"; \ + else \ + FRP_URL="https://raw.githubusercontent.com/nextcloud/HaRP/main/exapps_dev/frp_0.61.1_linux_amd64.tar.gz"; \ + fi; \ + echo "Downloading FRP client from $FRP_URL"; \ + curl -L "$FRP_URL" -o /tmp/frp.tar.gz; \ + tar -C /tmp -xzf /tmp/frp.tar.gz; \ + mv /tmp/frp_0.61.1_linux_* /tmp/frp; \ + cp /tmp/frp/frpc /usr/local/bin/frpc; \ + chmod +x /usr/local/bin/frpc; \ + rm -rf /tmp/frp /tmp/frp.tar.gz + ENV DEBIAN_FRONTEND=dialog ENV PATH="/root/.local/bin:${PATH}" ENV CMAKE_ARGS="-DGGML_CUDA=on" @@ -19,6 +35,7 @@ WORKDIR /app COPY pyproject.toml . COPY poetry.lock . COPY healthcheck.sh . +COPY --chmod=775 start.sh / RUN poetry install RUN ln -s /usr/local/cuda/compat/libcuda.so.1 /usr/lib/x86_64-linux-gnu/ @@ -28,7 +45,7 @@ ADD model[s] /app/models ADD default_confi[g] /app/default_config WORKDIR /app/lib -ENTRYPOINT ["poetry", "run", "python3", "main.py"] +ENTRYPOINT ["/start.sh", "poetry", "run", "python3", "main.py"] LABEL org.opencontainers.image.source=https://github.com/nextcloud/llm2 HEALTHCHECK --interval=2s --timeout=2s --retries=300 CMD /app/healthcheck.sh diff --git a/healthcheck.sh b/healthcheck.sh index a3c2fde..12584f6 100755 --- a/healthcheck.sh +++ b/healthcheck.sh @@ -1,4 +1,10 @@ #! /bin/bash # SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors # SPDX-License-Identifier: AGPL-3.0-or-later -exit 0 \ No newline at end of file +if [ -f /frpc.toml ] && [ -n "$HP_SHARED_KEY" ]; then + if pgrep -x "frpc" > /dev/null; then + exit 0 + else + exit 1 + fi +fi diff --git a/start.sh b/start.sh new file mode 100644 index 0000000..82eaeb3 --- /dev/null +++ b/start.sh @@ -0,0 +1,65 @@ +#!/bin/bash +# SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors +# SPDX-License-Identifier: AGPL-3.0-or-later + +set -e + +# Only create a config file if HP_SHARED_KEY is set. +if [ -n "$HP_SHARED_KEY" ]; then + echo "HP_SHARED_KEY is set, creating /frpc.toml configuration file..." + if [ -d "/certs/frp" ]; then + echo "Found /certs/frp directory. Creating configuration with TLS certificates." + cat < /frpc.toml +serverAddr = "$HP_FRP_ADDRESS" +serverPort = $HP_FRP_PORT +loginFailExit = false + +transport.tls.enable = true +transport.tls.certFile = "/certs/frp/client.crt" +transport.tls.keyFile = "/certs/frp/client.key" +transport.tls.trustedCaFile = "/certs/frp/ca.crt" +transport.tls.serverName = "harp.nc" + +metadatas.token = "$HP_SHARED_KEY" + +[[proxies]] +remotePort = $APP_PORT +type = "tcp" +name = "$APP_ID" +[proxies.plugin] +type = "unix_domain_socket" +unixPath = "/tmp/exapp.sock" +EOF + else + echo "Directory /certs/frp not found. Creating configuration without TLS certificates." + cat < /frpc.toml +serverAddr = "$HP_FRP_ADDRESS" +serverPort = $HP_FRP_PORT +loginFailExit = false + +transport.tls.enable = false + +metadatas.token = "$HP_SHARED_KEY" + +[[proxies]] +remotePort = $APP_PORT +type = "tcp" +name = "$APP_ID" +[proxies.plugin] +type = "unix_domain_socket" +unixPath = "/tmp/exapp.sock" +EOF + fi +else + echo "HP_SHARED_KEY is not set. Skipping FRP configuration." +fi + +# If we have a configuration file and the shared key is present, start the FRP client +if [ -f /frpc.toml ] && [ -n "$HP_SHARED_KEY" ]; then + echo "Starting frpc in the background..." + frpc -c /frpc.toml & +fi + +# Start the main application (launch cmd for ExApp is an argument for this script) +echo "Starting application: $@" +exec "$@"