Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nextcloud 32: HaRP support #11

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM python:3.11-slim-bookworm

RUN apt-get update && apt-get install -y curl iputils-ping && \
RUN apt-get update && apt-get install -y curl iputils-ping netcat-traditional && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

Expand All @@ -14,6 +14,23 @@ ADD /ex_app/l10[n] /ex_app/l10n
ADD /ex_app/li[b] /ex_app/lib

COPY --chmod=775 healthcheck.sh /
COPY --chmod=775 start.sh /

# Download and install FRP client
RUN set -ex; \
ARCH=$(uname -m); \
if [ "$ARCH" = "aarch64" ]; then \
FRP_URL="https://raw.githubusercontent.com/cloud-py-api/HaRP/main/exapps_dev/frp_0.61.1_linux_arm64.tar.gz"; \
else \
FRP_URL="https://raw.githubusercontent.com/cloud-py-api/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

# Installing PyTorch based on BUILD_TYPE
RUN ARCH=$(uname -m) && \
Expand All @@ -32,5 +49,5 @@ RUN \
python3 -m pip install -r requirements.txt && rm -rf ~/.cache && rm requirements.txt

WORKDIR /ex_app/lib
ENTRYPOINT ["python3", "main.py"]
ENTRYPOINT ["/start.sh"]
HEALTHCHECK --interval=2s --timeout=2s --retries=300 CMD /healthcheck.sh
7 changes: 2 additions & 5 deletions appinfo/info-latest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<description>
<![CDATA[Application to test the Docker AppAPI deployment process]]>
</description>
<version>1.1.0</version>
<version>2.0.0</version>
<licence>MIT</licence>
<author mail="[email protected]" homepage="https://github.com/andrey18106">Andrey Borysenko</author>
<author mail="[email protected]" homepage="https://github.com/bigcat88">Alexander Piskun</author>
Expand All @@ -17,16 +17,13 @@
<bugs>https://github.com/nextcloud/app_api/issues</bugs>
<repository type="git">https://github.com/nextcloud/test-deploy</repository>
<dependencies>
<nextcloud min-version="28" max-version="32"/>
<nextcloud min-version="32" max-version="32"/>
</dependencies>
<external-app>
<docker-install>
<registry>ghcr.io</registry>
<image>nextcloud/test-deploy</image>
<image-tag>latest</image-tag>
</docker-install>
<scopes>
</scopes>
<system>false</system>
</external-app>
</info>
8 changes: 7 additions & 1 deletion healthcheck.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#!/bin/bash

exit 0
if [ -f /frpc.toml ] && [ -n "$HP_SHARED_KEY" ]; then
if pgrep -x "frpc" > /dev/null; then
exit 0
else
exit 1
fi
fi
56 changes: 56 additions & 0 deletions start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/bash
set -e

# Check if the configuration file already exists
if [ -f /frpc.toml ]; then
echo "/frpc.toml already exists, skipping creation."
else
# 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 <<EOF > /frpc.toml
serverAddr = "$HP_FRP_ADDRESS"
serverPort = $HP_FRP_PORT
metadatas.token = "$HP_SHARED_KEY"
transport.tls.certFile = "/certs/frp/client.crt"
transport.tls.keyFile = "/certs/frp/client.key"
transport.tls.trustedCaFile = "/certs/frp/ca.crt"

[[proxies]]
name = "exapp"
type = "tcp"
localIP = "127.0.0.1"
localPort = $APP_PORT
remotePort = $APP_PORT
EOF
else
echo "Directory /certs/frp not found. Creating configuration without TLS certificates."
cat <<EOF > /frpc.toml
serverAddr = "$HP_FRP_ADDRESS"
serverPort = $HP_FRP_PORT
metadatas.token = "$HP_SHARED_KEY"

[[proxies]]
name = "exapp"
type = "tcp"
localIP = "127.0.0.1"
localPort = $APP_PORT
remotePort = $APP_PORT
EOF
fi
else
echo "HP_SHARED_KEY is not set. Skipping FRP configuration."
fi
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 Python application
echo "Starting main application..."
exec python3 main.py