Skip to content

Commit b4daf8c

Browse files
Nextcloud 32: HaRP support (#11)
* Nextcloud 32: HaRP support Signed-off-by: Oleksander Piskun <[email protected]> * add deploy test Signed-off-by: Anupam Kumar <[email protected]> --------- Signed-off-by: Oleksander Piskun <[email protected]> Signed-off-by: Anupam Kumar <[email protected]> Co-authored-by: Anupam Kumar <[email protected]>
1 parent fba77fb commit b4daf8c

File tree

6 files changed

+221
-9
lines changed

6 files changed

+221
-9
lines changed

.github/workflows/test-deploy.yml

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
2+
# SPDX-License-Identifier: MIT
3+
name: Test Deploy
4+
5+
on:
6+
pull_request:
7+
branches: [main]
8+
push:
9+
branches: [main]
10+
workflow_dispatch:
11+
12+
permissions:
13+
contents: read
14+
15+
concurrency:
16+
group: tests-deploy-${{ github.head_ref || github.run_id }}
17+
cancel-in-progress: true
18+
19+
jobs:
20+
nc-host-app-docker:
21+
runs-on: ubuntu-22.04
22+
name: NC In Host
23+
24+
services:
25+
postgres:
26+
image: ghcr.io/nextcloud/continuous-integration-postgres-14:latest
27+
ports:
28+
- 4444:5432/tcp
29+
env:
30+
POSTGRES_USER: root
31+
POSTGRES_PASSWORD: rootpassword
32+
POSTGRES_DB: nextcloud
33+
options: --health-cmd pg_isready --health-interval 5s --health-timeout 2s --health-retries 5
34+
35+
steps:
36+
- name: Set app env
37+
run: echo "APP_NAME=${GITHUB_REPOSITORY##*/}" >> $GITHUB_ENV
38+
39+
- name: Checkout server
40+
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
41+
with:
42+
submodules: true
43+
repository: nextcloud/server
44+
ref: master
45+
46+
- name: Checkout Test Deploy
47+
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
48+
with:
49+
path: apps/${{ env.APP_NAME }}
50+
51+
- name: Set up php
52+
uses: shivammathur/setup-php@4bd44f22a98a19e0950cbad5f31095157cc9621b # v2
53+
with:
54+
php-version: '8.3'
55+
extensions: bz2, ctype, curl, dom, fileinfo, gd, iconv, intl, json, libxml, mbstring, openssl, pcntl, posix, session, simplexml, xmlreader, xmlwriter, zip, zlib, pgsql, pdo_pgsql
56+
coverage: none
57+
ini-file: development
58+
ini-values:
59+
apc.enabled=on, apc.enable_cli=on, disable_functions=
60+
env:
61+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
62+
63+
- name: Set up Nextcloud
64+
env:
65+
DB_PORT: 4444
66+
run: |
67+
mkdir data
68+
./occ maintenance:install --verbose --database=pgsql --database-name=nextcloud --database-host=127.0.0.1 \
69+
--database-port=$DB_PORT --database-user=root --database-pass=rootpassword \
70+
--admin-user admin --admin-pass admin
71+
./occ config:system:set loglevel --value=0 --type=integer
72+
./occ config:system:set debug --value=true --type=boolean
73+
./occ app:enable --force app_api
74+
75+
- name: Test deploy
76+
run: |
77+
PHP_CLI_SERVER_WORKERS=2 php -S 127.0.0.1:8080 &
78+
./occ app_api:daemon:register docker_local_sock Docker docker-install http /var/run/docker.sock http://127.0.0.1:8080/index.php
79+
./occ app_api:app:register ${{ env.APP_NAME }} docker_local_sock \
80+
--info-xml apps/${{ env.APP_NAME }}/appinfo/info.xml
81+
./occ app_api:app:enable ${{ env.APP_NAME }}
82+
./occ app_api:app:disable ${{ env.APP_NAME }}
83+
84+
- name: Save container info & logs
85+
if: always()
86+
run: |
87+
docker inspect nc_app_${{ env.APP_NAME }} | json_pp > container.json
88+
docker logs nc_app_${{ env.APP_NAME }} > container.log 2>&1
89+
90+
- name: Check logs
91+
run: |
92+
grep -q 'Started' container.log || error
93+
grep -q 'Connect to Nextcloud was successful' container.log || error
94+
grep -q 'enabled_handler: enabled=True' container.log || error
95+
grep -q 'enabled_handler: enabled=False' container.log || error
96+
grep -q 'Running on CPU' container.log || error
97+
98+
- name: Unregister App & Daemon
99+
run: |
100+
./occ app_api:app:unregister ${{ env.APP_NAME }}
101+
./occ app_api:daemon:unregister docker_local_sock
102+
103+
- name: Upload Container info
104+
if: always()
105+
uses: actions/upload-artifact@v4
106+
with:
107+
name: nc_host_app_docker_container.json
108+
path: container.json
109+
if-no-files-found: warn
110+
111+
- name: Upload Container logs
112+
if: always()
113+
uses: actions/upload-artifact@v4
114+
with:
115+
name: nc_host_app_docker_container.log
116+
path: container.log
117+
if-no-files-found: warn
118+
119+
- name: Upload NC logs
120+
if: always()
121+
uses: actions/upload-artifact@v4
122+
with:
123+
name: nc_host_app_docker_nextcloud.log
124+
path: data/nextcloud.log
125+
if-no-files-found: warn
126+
127+
tests-deploy-success:
128+
permissions:
129+
contents: none
130+
runs-on: ubuntu-22.04
131+
needs: [nc-host-app-docker]
132+
name: Tests-Deploy-OK
133+
steps:
134+
- run: echo "Tests-Deploy passed successfully"

Dockerfile

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM python:3.11-slim-bookworm
22

3-
RUN apt-get update && apt-get install -y curl iputils-ping && \
3+
RUN apt-get update && apt-get install -y curl procps iputils-ping netcat-traditional && \
44
apt-get clean && \
55
rm -rf /var/lib/apt/lists/*
66

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

1616
COPY --chmod=775 healthcheck.sh /
17+
COPY --chmod=775 start.sh /
18+
19+
# Download and install FRP client
20+
RUN set -ex; \
21+
ARCH=$(uname -m); \
22+
if [ "$ARCH" = "aarch64" ]; then \
23+
FRP_URL="https://raw.githubusercontent.com/cloud-py-api/HaRP/main/exapps_dev/frp_0.61.1_linux_arm64.tar.gz"; \
24+
else \
25+
FRP_URL="https://raw.githubusercontent.com/cloud-py-api/HaRP/main/exapps_dev/frp_0.61.1_linux_amd64.tar.gz"; \
26+
fi; \
27+
echo "Downloading FRP client from $FRP_URL"; \
28+
curl -L "$FRP_URL" -o /tmp/frp.tar.gz; \
29+
tar -C /tmp -xzf /tmp/frp.tar.gz; \
30+
mv /tmp/frp_0.61.1_linux_* /tmp/frp; \
31+
cp /tmp/frp/frpc /usr/local/bin/frpc; \
32+
chmod +x /usr/local/bin/frpc; \
33+
rm -rf /tmp/frp /tmp/frp.tar.gz
1734

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

3451
WORKDIR /ex_app/lib
35-
ENTRYPOINT ["python3", "main.py"]
52+
ENTRYPOINT ["/start.sh"]
3653
HEALTHCHECK --interval=2s --timeout=2s --retries=300 CMD /healthcheck.sh

appinfo/info-latest.xml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<description>
77
<![CDATA[Application to test the Docker AppAPI deployment process]]>
88
</description>
9-
<version>1.1.0</version>
9+
<version>2.0.0</version>
1010
<licence>MIT</licence>
1111
<author mail="[email protected]" homepage="https://github.com/andrey18106">Andrey Borysenko</author>
1212
<author mail="[email protected]" homepage="https://github.com/bigcat88">Alexander Piskun</author>
@@ -17,16 +17,13 @@
1717
<bugs>https://github.com/nextcloud/app_api/issues</bugs>
1818
<repository type="git">https://github.com/nextcloud/test-deploy</repository>
1919
<dependencies>
20-
<nextcloud min-version="28" max-version="32"/>
20+
<nextcloud min-version="32" max-version="32"/>
2121
</dependencies>
2222
<external-app>
2323
<docker-install>
2424
<registry>ghcr.io</registry>
2525
<image>nextcloud/test-deploy</image>
2626
<image-tag>latest</image-tag>
2727
</docker-install>
28-
<scopes>
29-
</scopes>
30-
<system>false</system>
3128
</external-app>
3229
</info>

healthcheck.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
#!/bin/bash
22

3-
exit 0
3+
if [ -f /frpc.toml ] && [ -n "$HP_SHARED_KEY" ]; then
4+
if pgrep -x "frpc" > /dev/null; then
5+
exit 0
6+
else
7+
exit 1
8+
fi
9+
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.18.2
1+
nc_py_api[app]>=0.19.0

start.sh

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

0 commit comments

Comments
 (0)