Skip to content

Commit d9b74df

Browse files
committed
feat: added HaRP support (Nextcloud 32+)
Signed-off-by: Oleksander Piskun <[email protected]>
1 parent bc85383 commit d9b74df

File tree

5 files changed

+102
-2
lines changed

5 files changed

+102
-2
lines changed

Dockerfile

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,34 @@
11
FROM python:3.12-bookworm
22

3+
RUN \
4+
apt update && \
5+
apt-get install -y curl && \
6+
apt-get autoclean
7+
8+
# Download and install FRP client into /usr/local/bin.
9+
RUN set -ex; \
10+
ARCH=$(uname -m); \
11+
if [ "$ARCH" = "aarch64" ]; then \
12+
FRP_URL="https://raw.githubusercontent.com/nextcloud/HaRP/main/exapps_dev/frp_0.61.1_linux_arm64.tar.gz"; \
13+
else \
14+
FRP_URL="https://raw.githubusercontent.com/nextcloud/HaRP/main/exapps_dev/frp_0.61.1_linux_amd64.tar.gz"; \
15+
fi; \
16+
echo "Downloading FRP client from $FRP_URL"; \
17+
curl -L "$FRP_URL" -o /tmp/frp.tar.gz; \
18+
tar -C /tmp -xzf /tmp/frp.tar.gz; \
19+
mv /tmp/frp_0.61.1_linux_* /tmp/frp; \
20+
cp /tmp/frp/frpc /usr/local/bin/frpc; \
21+
chmod +x /usr/local/bin/frpc; \
22+
rm -rf /tmp/frp /tmp/frp.tar.gz
23+
324
COPY requirements.txt /
25+
COPY healthcheck.sh /
26+
COPY --chmod=775 start.sh /
427
ADD /src/ /app/
528

629
RUN \
730
python3 -m pip install -r requirements.txt && rm -rf ~/.cache && rm requirements.txt
831

932
WORKDIR /app
10-
ENTRYPOINT ["python3", "main.py"]
33+
ENTRYPOINT ["/start.sh", "python3", "main.py"]
34+
HEALTHCHECK --interval=5s --timeout=2s --retries=300 CMD /healthcheck.sh

appinfo/info.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ The bot is capable of answering questions in chat depending on the model set by
1717
<author mail="[email protected]" homepage="https://github.com/bigcat88">Alexander Piskun</author>
1818
<author mail="[email protected]" homepage="https://github.com/edward-ly">Edward Ly</author>
1919
<namespace>AssistantTalkBot</namespace>
20+
<category>ai</category>
2021
<category>tools</category>
2122
<screenshot>https://raw.githubusercontent.com/nextcloud/talk_bot_ai/main/screenshots/talk_bot_ai.png</screenshot>
2223
<website>https://github.com/nextcloud/talk_bot_ai</website>

healthcheck.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#! /bin/bash
2+
# SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
3+
# SPDX-License-Identifier: AGPL-3.0-or-later
4+
if [ -f /frpc.toml ] && [ -n "$HP_SHARED_KEY" ]; then
5+
if pgrep -x "frpc" > /dev/null; then
6+
exit 0
7+
else
8+
exit 1
9+
fi
10+
fi

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
nc_py_api[app]>=0.16.0
1+
nc_py_api[app]>=0.19.2

start.sh

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/bash
2+
# SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
3+
# SPDX-License-Identifier: AGPL-3.0-or-later
4+
5+
set -e
6+
7+
# Only create a config file if HP_SHARED_KEY is set.
8+
if [ -n "$HP_SHARED_KEY" ]; then
9+
echo "HP_SHARED_KEY is set, creating /frpc.toml configuration file..."
10+
if [ -d "/certs/frp" ]; then
11+
echo "Found /certs/frp directory. Creating configuration with TLS certificates."
12+
cat <<EOF > /frpc.toml
13+
serverAddr = "$HP_FRP_ADDRESS"
14+
serverPort = $HP_FRP_PORT
15+
loginFailExit = false
16+
17+
transport.tls.enable = true
18+
transport.tls.certFile = "/certs/frp/client.crt"
19+
transport.tls.keyFile = "/certs/frp/client.key"
20+
transport.tls.trustedCaFile = "/certs/frp/ca.crt"
21+
transport.tls.serverName = "harp.nc"
22+
23+
metadatas.token = "$HP_SHARED_KEY"
24+
25+
[[proxies]]
26+
remotePort = $APP_PORT
27+
type = "tcp"
28+
name = "$APP_ID"
29+
[proxies.plugin]
30+
type = "unix_domain_socket"
31+
unixPath = "/tmp/exapp.sock"
32+
EOF
33+
else
34+
echo "Directory /certs/frp not found. Creating configuration without TLS certificates."
35+
cat <<EOF > /frpc.toml
36+
serverAddr = "$HP_FRP_ADDRESS"
37+
serverPort = $HP_FRP_PORT
38+
loginFailExit = false
39+
40+
transport.tls.enable = false
41+
42+
metadatas.token = "$HP_SHARED_KEY"
43+
44+
[[proxies]]
45+
remotePort = $APP_PORT
46+
type = "tcp"
47+
name = "$APP_ID"
48+
[proxies.plugin]
49+
type = "unix_domain_socket"
50+
unixPath = "/tmp/exapp.sock"
51+
EOF
52+
fi
53+
else
54+
echo "HP_SHARED_KEY is not set. Skipping FRP configuration."
55+
fi
56+
57+
# If we have a configuration file and the shared key is present, start the FRP client
58+
if [ -f /frpc.toml ] && [ -n "$HP_SHARED_KEY" ]; then
59+
echo "Starting frpc in the background..."
60+
frpc -c /frpc.toml &
61+
fi
62+
63+
# Start the main application (launch cmd for ExApp is an argument for this script)
64+
echo "Starting application: $@"
65+
exec "$@"

0 commit comments

Comments
 (0)