Skip to content

Commit e1a5441

Browse files
authored
Merge pull request #75 from Euro-Office/feat/support-android-dev-ips
Feat/support android dev ips
2 parents 1557585 + 2b18260 commit e1a5441

4 files changed

Lines changed: 105 additions & 3 deletions

File tree

develop/Makefile

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,49 @@
11
PRODUCT_VERSION ?= $(shell cat ../VERSION)
22
export PRODUCT_VERSION
33

4+
# Detect host LAN IP for phones/emulators/LAN devices. Used by `make mobile`
5+
# and `make refresh-urls`.
6+
ifeq ($(shell uname -s),Darwin)
7+
DETECTED_HOST_LAN_IP := $(shell ipconfig getifaddr en0 2>/dev/null || ipconfig getifaddr en1 2>/dev/null)
8+
else
9+
# 1.1.1.1 is a dummy public target — `ip route get` just asks the kernel
10+
# which local source IP it would use, without actually sending packets.
11+
DETECTED_HOST_LAN_IP := $(shell ip route get 1.1.1.1 2>/dev/null | awk '{print $$7; exit}')
12+
endif
13+
14+
# Empty by default: `make local` runs on localhost (desktop browser + iOS sim).
15+
# `make mobile` sets this so Android emulators and LAN-connected devices can reach the editor.
16+
HOST_LAN_IP ?=
17+
export HOST_LAN_IP
18+
419
local:
5-
docker compose up -d && docker compose exec eo bash
20+
@echo ""
21+
@echo " ███████╗ ██████╗"
22+
@echo " ██╔════╝██╔═══██╗"
23+
@echo " █████╗ ██║ ██║"
24+
@echo " ██╔══╝ ██║ ██║"
25+
@echo " ███████╗╚██████╔╝"
26+
@echo " ╚══════╝ ╚═════╝"
27+
@echo ""
28+
@echo " Euro-Office Development Environment"
29+
@echo ""
30+
ifeq ($(HOST_LAN_IP),)
31+
@echo " Mode: localhost (desktop browser + iOS sim)"
32+
@echo " For Android / physical device testing: make mobile"
33+
else
34+
@echo " Mode: mobile / LAN"
35+
@echo " Host LAN IP: $(HOST_LAN_IP)"
36+
@echo " On IP change: make refresh-urls"
37+
endif
38+
@echo ""
39+
docker compose up -d
40+
@$(MAKE) --no-print-directory refresh-urls
41+
docker compose exec eo bash
42+
43+
# Like `make local`, but injects the detected HOST_LAN_IP so that Nextcloud
44+
# returns a DocumentServerUrl mobile/LAN clients can actually reach.
45+
mobile:
46+
@HOST_LAN_IP="$(DETECTED_HOST_LAN_IP)" $(MAKE) local
647

748
pull:
849
docker compose pull && docker compose up -d && docker compose exec eo bash
@@ -11,3 +52,29 @@ build:
1152
(cd ../build && docker buildx bake develop) && \
1253
(docker compose up -d) && \
1354
(docker compose exec eo bash)
55+
56+
# Align OnlyOffice URLs and trusted_domains with the current mode.
57+
# - If HOST_LAN_IP is set: mobile/LAN mode (DocumentServerUrl = http://<ip>:8080/, trusted_domains[2] = <ip>).
58+
# - If HOST_LAN_IP is empty: localhost mode (DocumentServerUrl = http://localhost:8080/, trusted_domains[2] cleared).
59+
# Waits for Nextcloud + OnlyOffice to finish installing on first boot, then applies idempotently.
60+
refresh-urls:
61+
@start=$$(date +%s); \
62+
while ! docker compose exec -T eo curl -sf http://localhost/healthcheck >/dev/null 2>&1; do \
63+
printf "\rWaiting for document server (%ds) " $$(($$(date +%s) - start)); \
64+
sleep 2; \
65+
done; \
66+
printf "\rDocument server ready (%ds). \n" $$(($$(date +%s) - start))
67+
@start=$$(date +%s); \
68+
while ! docker compose exec -T -u www-data nextcloud ./occ config:app:get onlyoffice DocumentServerUrl 2>/dev/null | grep -q "http"; do \
69+
printf "\rWaiting for Nextcloud setup (%ds) " $$(($$(date +%s) - start)); \
70+
sleep 2; \
71+
done; \
72+
printf "\rNextcloud setup ready (%ds). \n" $$(($$(date +%s) - start))
73+
@target="$${HOST_LAN_IP:-localhost}"; \
74+
echo "Setting DocumentServerUrl to http://$$target:8080/"; \
75+
docker compose exec -T -u www-data nextcloud ./occ config:app:set onlyoffice DocumentServerUrl --value="http://$$target:8080/" >/dev/null; \
76+
if [ "$$target" = "localhost" ]; then \
77+
docker compose exec -T -u www-data nextcloud ./occ config:system:delete trusted_domains 2 >/dev/null 2>&1 || true; \
78+
else \
79+
docker compose exec -T -u www-data nextcloud ./occ config:system:set trusted_domains 2 --value=$$target >/dev/null; \
80+
fi

develop/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ The docker compose environment in this directory allows to run document server b
88
- `make` to use the image that is currently available locally
99
- `make pull` to use the latest image from github
1010
- `make build` to build the image locally from scratch
11+
- `make mobile` for Android emulator / physical LAN device testing (see below)
1112

1213
You may need to generate a PAT first, as described in https://github.com/Euro-Office/DocumentServer/pkgs/container/documentserver
1314
- In docker-compose.yml, for the eo service, ensure that `target` is set to `develop`
@@ -24,6 +25,31 @@ The docker compose environment in this directory allows to run document server b
2425
- Secret key: `secret`
2526
- Navigate to Files `http://localhost:8081/apps/files/`, create a document, and try to open it
2627

28+
#### Testing from mobile devices and emulators
29+
30+
`make local` runs on `localhost` — enough for the desktop browser and iOS simulator. For Android emulators and physical devices on the LAN, use `make mobile` instead — it detects the host's LAN IP and injects it so the editor is reachable from off-desktop clients.
31+
32+
| Client | Target | Nextcloud URL |
33+
|---|---|---|
34+
| Desktop browser | `make local` or `make mobile` | `http://localhost:8081/` |
35+
| iOS simulator | `make local` or `make mobile` | `http://localhost:8081/` |
36+
| Android emulator | `make mobile` | `http://10.0.2.2:8081/` |
37+
| Physical LAN device | `make mobile` | `http://<HOST_LAN_IP>:8081/` |
38+
39+
IP detection uses `ipconfig` on macOS and `ip route` on Linux. On native Windows — or any machine where detection fails — pass it explicitly:
40+
41+
```sh
42+
make mobile HOST_LAN_IP=192.168.1.50
43+
```
44+
45+
When your LAN IP changes (new wifi, tethering, etc.), update the running stack without a full rebuild:
46+
47+
```sh
48+
make refresh-urls
49+
```
50+
51+
Switching between `make local` and `make mobile` on an already-started stack is supported — both targets re-apply the correct URLs and trusted domains on each run.
52+
2753
#### Building changes:
2854

2955
- Enter the container with `docker compose exec eo bash`

develop/docker-compose.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ services:
3131
- /var/www/html
3232
- ./setup/enable-office.sh:/docker-entrypoint-hooks.d/post-installation/enable-office.sh:ro
3333
environment:
34-
NEXTCLOUD_TRUSTED_DOMAINS: 172.18.0.1
34+
# 10.0.2.2 = Android emulator's alias for host. Mobile/LAN IPs are
35+
# applied post-boot by `make refresh-urls` so the container env stays
36+
# stable across mode switches (no recreation, no data loss).
37+
NEXTCLOUD_TRUSTED_DOMAINS: 10.0.2.2
3538
SQLITE_DATABASE: nextcloud
3639
NEXTCLOUD_ADMIN_USER: admin
3740
NEXTCLOUD_ADMIN_PASSWORD: admin

develop/setup/enable-office.sh

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

3-
php /var/www/html/occ config:system:set trusted_domains 1 --value=nextcloud
3+
php /var/www/html/occ config:system:set trusted_domains 10 --value=nextcloud
4+
5+
# Disable throttling for dev — mobile login retries trip the default
6+
# brute-force protection and rate limiter, blocking further requests.
7+
php /var/www/html/occ config:system:set auth.bruteforce.protection.enabled --value=false --type=boolean
8+
php /var/www/html/occ config:system:set ratelimit.protection.enabled --value=false --type=boolean
49

510
echo "Waiting for Euro-Office document server to be ready..."
611
until curl -sf http://eo/healthcheck > /dev/null 2>&1; do
@@ -9,6 +14,7 @@ until curl -sf http://eo/healthcheck > /dev/null 2>&1; do
914
done
1015
echo "Document server is ready!"
1116

17+
# Baseline URL; `make local` / `make mobile` rewrite this via `refresh-urls`.
1218
php /var/www/html/occ app:enable onlyoffice
1319
php /var/www/html/occ config:app:set onlyoffice DocumentServerUrl --value="http://localhost:8080/"
1420
php /var/www/html/occ config:app:set onlyoffice StorageUrl --value="http://nextcloud/"

0 commit comments

Comments
 (0)