Skip to content

Commit 2c401a2

Browse files
authored
Merge pull request #21 from nextcloud/feat/HaRP-support
feat(AppAPI): HaRP support(Nextcloud 32+)
2 parents 301bf7a + 65f0aca commit 2c401a2

File tree

3 files changed

+96
-3
lines changed

3 files changed

+96
-3
lines changed

Dockerfile

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,30 @@
22
# SPDX-License-Identifier: AGPL-3.0-or-later
33
FROM python:3.11-slim-bookworm
44

5-
COPY requirements.txt /
5+
ENV DEBIAN_FRONTEND noninteractive
6+
7+
RUN apt-get update && \
8+
apt-get install -y curl && \
9+
apt-get -y clean && \
10+
rm -rf /var/lib/apt/lists/*
611

12+
# Download and install FRP client into /usr/local/bin.
13+
RUN set -ex; \
14+
ARCH=$(uname -m); \
15+
if [ "$ARCH" = "aarch64" ]; then \
16+
FRP_URL="https://raw.githubusercontent.com/nextcloud/HaRP/main/exapps_dev/frp_0.61.1_linux_arm64.tar.gz"; \
17+
else \
18+
FRP_URL="https://raw.githubusercontent.com/nextcloud/HaRP/main/exapps_dev/frp_0.61.1_linux_amd64.tar.gz"; \
19+
fi; \
20+
echo "Downloading FRP client from $FRP_URL"; \
21+
curl -L "$FRP_URL" -o /tmp/frp.tar.gz; \
22+
tar -C /tmp -xzf /tmp/frp.tar.gz; \
23+
mv /tmp/frp_0.61.1_linux_* /tmp/frp; \
24+
cp /tmp/frp/frpc /usr/local/bin/frpc; \
25+
chmod +x /usr/local/bin/frpc; \
26+
rm -rf /tmp/frp /tmp/frp.tar.gz
727

28+
COPY requirements.txt /
829

930
RUN \
1031
python3 -m pip install -r requirements.txt && rm -rf ~/.cache && rm requirements.txt
@@ -16,8 +37,9 @@ ADD /ex_app/l10[n] /ex_app/l10n
1637
ADD /ex_app/li[b] /ex_app/lib
1738

1839
COPY --chmod=775 healthcheck.sh /
40+
COPY --chmod=775 start.sh /
1941

2042
WORKDIR /ex_app/lib
2143
ENV PYTHONPATH="/"
22-
ENTRYPOINT ["python3", "main.py"]
44+
ENTRYPOINT ["/start.sh", "python3", "main.py"]
2345
HEALTHCHECK --interval=2s --timeout=2s --retries=300 CMD /healthcheck.sh

healthcheck.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
#!/bin/bash
22
# SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
33
# SPDX-License-Identifier: AGPL-3.0-or-later
4-
exit 0
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

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)