Skip to content

Commit 5dda92a

Browse files
authored
feat: Added a script to run OO locally for local dev (#4680)
2 parents 90d8205 + c2dd926 commit 5dda92a

6 files changed

Lines changed: 122 additions & 158 deletions

File tree

docs/docker.md

Lines changed: 65 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,23 +62,79 @@ docker run --rm -it -p 8080:8080 -v "$(pwd)/build":/data/cozy-app/***my-app*** c
6262

6363
## Only-Office document server
6464

65-
The `cozy/onlyoffice-dev` docker image can be used for local development on
66-
Linux (the `--net=host` option doesn't work on macOS). Just start it with:
65+
### Option 1: With Helper Script
66+
67+
Use the helper script that works on both Linux and macOS:
68+
69+
```bash
70+
./scripts/start-oo.sh
71+
```
72+
73+
The script automatically:
74+
- Collects all instance hostnames from cozy-stack
75+
- Starts OnlyOffice with proper `--add-host` mappings
76+
- Waits for OnlyOffice to be ready
77+
78+
### Option 2: Manual Docker Command
79+
80+
**For macOS and Linux (port mapping):**
6781

6882
```bash
69-
$ docker run -it --rm --name=oodev --net=host cozy/onlyoffice-dev
83+
docker run -d --name onlyoffice-ds \
84+
-p 8000:80 \
85+
-e JWT_ENABLED=false \
86+
-e ALLOW_PRIVATE_IP_ADDRESS=true \
87+
-e ALLOW_META_IP_ADDRESS=true \
88+
--add-host=cozy.localhost:host-gateway \
89+
onlyoffice/documentserver:latest
7090
```
7191

72-
and run the stack with:
92+
**For Linux only (`--net=host`):**
7393

7494
```bash
75-
$ cozy-stack serve --disable-csp --onlyoffice-url=http://localhost:8000 --onlyoffice-inbox-secret=inbox_secret --onlyoffice-outbox-secret=outbox_secret
76-
$ cozy-stack features defaults '{"drive.office": {"enabled": true, "write": true}}'
95+
docker run -d --name onlyoffice-ds \
96+
--net=host \
97+
-e JWT_ENABLED=false \
98+
-e ALLOW_PRIVATE_IP_ADDRESS=true \
99+
-e ALLOW_META_IP_ADDRESS=true \
100+
-e DS_PORT=8000 \
101+
onlyoffice/documentserver:latest
102+
```
103+
104+
### Configure cozy-stack
105+
106+
Add to your `~/.cozy/cozy.yaml`:
107+
108+
```yaml
109+
contexts:
110+
default:
111+
onlyoffice_url: http://localhost:8000/
112+
113+
office:
114+
default:
115+
onlyoffice_url: http://localhost:8000/
116+
onlyoffice_inbox_secret: ""
117+
onlyoffice_outbox_secret: ""
77118
```
78119
79-
If you need to rebuild it, you can do that with:
120+
### Enable Feature Flag
80121
81122
```bash
82-
$ cd scripts/onlyoffice-dev
83-
$ docker build -t "cozy/onlyoffice-dev" .
123+
cozy-stack features defaults '{"drive.office": {"enabled": true, "write": true}}'
84124
```
125+
126+
### Troubleshooting
127+
128+
**OnlyOffice can't download the document:**
129+
- Check OnlyOffice logs: `docker logs onlyoffice-ds`
130+
- Look for DNS errors like `ENOTFOUND cozy.localhost`
131+
- Ensure `--add-host` flag was applied: `docker exec onlyoffice-ds cat /etc/hosts | grep cozy`
132+
- Ensure `ALLOW_PRIVATE_IP_ADDRESS=true` is set
133+
134+
**"Download failed" error in editor:**
135+
- The Document Server can't reach cozy-stack
136+
- Verify connectivity: `docker exec onlyoffice-ds wget -qO- http://cozy.localhost:8080/`
137+
138+
**No "Open with OnlyOffice" option in Drive:**
139+
- Check feature flag: `cozy-stack features show`
140+
- Verify context has `onlyoffice_url`: check `/settings/context` endpoint

docs/office.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ Reference: https://api.onlyoffice.com/editors/save
3131

3232
## Routes
3333

34+
> **Note:** For local development setup, see [Docker - OnlyOffice Document Server](docker.md#onlyoffice-document-server).
35+
3436
### GET /office/:id/open
3537

3638
This route returns the parameters to open an office document. There are two

scripts/onlyoffice-dev/Dockerfile

Lines changed: 0 additions & 68 deletions
This file was deleted.

scripts/onlyoffice-dev/docker-entrypoint.sh

Lines changed: 0 additions & 38 deletions
This file was deleted.

scripts/onlyoffice-dev/local.json

Lines changed: 0 additions & 43 deletions
This file was deleted.

scripts/start-oo.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash
2+
#
3+
# Start OnlyOffice Document Server for local development
4+
#
5+
# This script:
6+
# 1. Stops and removes any existing onlyoffice-ds container
7+
# 2. Collects all instance hostnames from cozy-stack
8+
# 3. Starts OnlyOffice with proper host mappings so it can reach cozy-stack
9+
#
10+
# Usage: ./scripts/start-oo.sh
11+
#
12+
# See docs/docker.md for more information
13+
14+
set -e
15+
16+
CONTAINER_NAME="onlyoffice-ds"
17+
PORT="${OO_PORT:-8000}"
18+
19+
echo "Stopping existing OnlyOffice container..."
20+
docker stop $CONTAINER_NAME 2>/dev/null || true
21+
docker rm $CONTAINER_NAME 2>/dev/null || true
22+
23+
echo "Collecting instance hostnames..."
24+
HOSTS=""
25+
for domain in $(go run . instances ls 2>/dev/null | awk '{print $1}' | sed 's/:8080//'); do
26+
HOSTS="$HOSTS --add-host=$domain:host-gateway"
27+
done
28+
29+
if [ -z "$HOSTS" ]; then
30+
echo "Warning: No instances found. Adding default cozy.localhost"
31+
HOSTS="--add-host=cozy.localhost:host-gateway"
32+
fi
33+
34+
echo "Starting OnlyOffice Document Server on port $PORT..."
35+
docker run -d --name $CONTAINER_NAME \
36+
-p $PORT:80 \
37+
-e JWT_ENABLED=false \
38+
-e ALLOW_PRIVATE_IP_ADDRESS=true \
39+
-e ALLOW_META_IP_ADDRESS=true \
40+
$HOSTS \
41+
onlyoffice/documentserver:latest
42+
43+
echo "Waiting for OnlyOffice to be ready..."
44+
for i in {1..60}; do
45+
if curl -s http://localhost:$PORT/healthcheck 2>/dev/null | grep -q "true"; then
46+
echo "OnlyOffice is ready at http://localhost:$PORT"
47+
exit 0
48+
fi
49+
sleep 2
50+
echo -n "."
51+
done
52+
53+
echo ""
54+
echo "Warning: OnlyOffice did not become ready in time. Check logs with:"
55+
echo " docker logs $CONTAINER_NAME"

0 commit comments

Comments
 (0)