Skip to content

Commit 83960b0

Browse files
committed
Create a local development stack
1 parent b89ac79 commit 83960b0

File tree

6 files changed

+201
-0
lines changed

6 files changed

+201
-0
lines changed

dev/README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
This is a docker-compose configuration to be used **only** for development purpose. There is
2+
almost zero security in the stack configuration.
3+
4+
It is composed of the Zimit frontend and API (of course), but also a local Zimfarm DB,
5+
API and UI, so that you can test the whole integration locally.
6+
7+
Zimit UI and API are not deployed as they would be in production to allow hot reload of
8+
most modifications done to the source code.
9+
10+
Zimfarm UI, API and DB are deployed with official production Docker images.
11+
12+
## List of containers
13+
14+
### zimit_ui
15+
16+
This container is Zimit frontend web server (UI only)
17+
18+
### zimit_api
19+
20+
This container is Zimit API server (API only)
21+
22+
## zimfarm_db
23+
24+
This container is a local Zimfarm database
25+
26+
## zimfarm_api
27+
28+
This container is a local Zimfarm API
29+
30+
## zimfarm_ui
31+
32+
This container is a local Zimfarm UI
33+
34+
## Instructions
35+
36+
First start the Docker-Compose stack:
37+
38+
```sh
39+
cd dev
40+
docker compose -p zimit up -d
41+
```
42+
43+
If it is your first execution of the dev stack, you need to create a "virtual" worker in Zimfarm DB:
44+
45+
```sh
46+
dev/create_worker.sh
47+
```
48+
49+
If you have requested a task via Zimit UI and want to simulate a worker starting this task to observe the consequence in Zimit UI, you might use the `dev/start_first_req_task.sh`.
50+
51+
## Restart the backend
52+
53+
Should the API process fail, you might restart it with:
54+
```sh
55+
docker restart zimit-zimit_ui-1
56+
```
57+
58+
## Browse the web UIs
59+
60+
You might open following URLs in your favorite browser:
61+
62+
- [Zimit UI](http://localhost:8001)
63+
- [Zimfarm API](http://localhost:8002)
64+
- [Zimfarm UI](http://localhost:8003)
65+
66+
You can login into Zimfarm UI with username `admin` and password `admin`.

dev/create_worker.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
echo "Retrieving access token"
2+
3+
ZF_ADMIN_TOKEN="$(curl -s -X 'POST' \
4+
'http://localhost:8002/v1/auth/authorize' \
5+
-H 'accept: application/json' \
6+
-H 'Content-Type: application/x-www-form-urlencoded' \
7+
-d 'username=admin&password=admin' \
8+
| jq -r '.access_token')"
9+
10+
echo "Worker check-in (will create if missing)"
11+
12+
curl -s -X 'PUT' \
13+
'http://localhost:8002/v1/workers/worker/check-in' \
14+
-H 'accept: */*' \
15+
-H 'Content-Type: application/json' \
16+
-H "Authorization: Bearer $ZF_ADMIN_TOKEN" \
17+
-d '{
18+
"username": "admin",
19+
"cpu": 3,
20+
"memory": 1024,
21+
"disk": 0,
22+
"offliners": [
23+
"zimit"
24+
]
25+
}'
26+
27+
echo "DONE"

dev/docker-compose.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
services:
2+
zimfarm_db:
3+
image: postgres:15.2-bullseye
4+
ports:
5+
- 127.0.0.1:5432:5432
6+
volumes:
7+
- zimfarm_data:/var/lib/postgresql/data
8+
environment:
9+
- POSTGRES_DB=zimfarm
10+
- POSTGRES_USER=zimfarm
11+
- POSTGRES_PASSWORD=zimpass
12+
zimfarm_api:
13+
image: ghcr.io/openzim/zimfarm-dispatcher:latest
14+
ports:
15+
- 127.0.0.1:8004:80
16+
environment:
17+
BINDING_HOST: 0.0.0.0
18+
JWT_SECRET: DH8kSxcflUVfNRdkEiJJCn2dOOKI3qfw
19+
POSTGRES_URI: postgresql+psycopg://zimfarm:zimpass@zimfarm_db:5432/zimfarm
20+
ALEMBIC_UPGRADE_HEAD_ON_START: "1"
21+
ZIMIT_USE_RELAXED_SCHEMA: "y"
22+
depends_on:
23+
- zimfarm_db
24+
zimfarm-ui:
25+
image: ghcr.io/openzim/zimfarm-ui:latest
26+
ports:
27+
- 127.0.0.1:8003:80
28+
environment:
29+
ZIMFARM_WEBAPI: http://localhost:8002/v1
30+
depends_on:
31+
- zimfarm_api
32+
zimit_api:
33+
build: ..
34+
volumes:
35+
- ../api/src:/app
36+
command: python main.py
37+
ports:
38+
- 127.0.0.1:8002:8000
39+
environment:
40+
BINDING_HOST: 0.0.0.0
41+
INTERNAL_ZIMFARM_WEBAPI: http://zimfarm_api:80/v1
42+
_ZIMFARM_USERNAME: admin
43+
_ZIMFARM_PASSWORD: admin
44+
TASK_WORKER: worker
45+
depends_on:
46+
- zimfarm_api
47+
zimit_ui:
48+
build:
49+
dockerfile: ../dev/zimit_ui_dev/Dockerfile
50+
context: ../ui
51+
volumes:
52+
- ../ui/src:/app/src
53+
- ../ui/public:/app/public
54+
- ../dev/zimit_ui_dev/environ.json:/app/public/environ.json
55+
ports:
56+
- 127.0.0.1:8001:80
57+
environment:
58+
ZIMIT_API_URL: http://localhost:8002
59+
depends_on:
60+
- zimit_api
61+
62+
volumes:
63+
zimfarm_data:

dev/start_first_req_task.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
echo "Retrieving access token"
2+
3+
ZF_ADMIN_TOKEN="$(curl -s -X 'POST' \
4+
'http://localhost:8002/v1/auth/authorize' \
5+
-H 'accept: application/json' \
6+
-H 'Content-Type: application/x-www-form-urlencoded' \
7+
-d 'username=admin&password=admin' \
8+
| jq -r '.access_token')"
9+
10+
echo "Get last requested task"
11+
12+
LAST_TASK_ID="$(curl -s -X 'GET' \
13+
'http://localhost:8002/v1/requested-tasks/' \
14+
-H 'accept: application/json' \
15+
-H "Authorization: Bearer $ZF_ADMIN_TOKEN" \
16+
| jq -r '.items[0]._id')"
17+
18+
if [ "$LAST_TASK_ID" = "null" ]; then
19+
echo "No pending requested task. Exiting script."
20+
exit 1
21+
fi
22+
23+
echo "Start task"
24+
25+
curl -s -X 'POST' \
26+
"http://localhost:8002/v1/tasks/$LAST_TASK_ID?worker_name=worker" \
27+
-H 'accept: application/json' \
28+
-H "Authorization: Bearer $ZF_ADMIN_TOKEN" \
29+
-d ''
30+
31+
echo "DONE"

dev/zimit_ui_dev/Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM node:14-alpine
2+
3+
RUN apk --no-cache add yarn
4+
WORKDIR /app
5+
COPY package.json yarn.lock /app/
6+
RUN yarn install && yarn cache clean
7+
COPY *.js /app/
8+
COPY public /app/public
9+
COPY src /app/src
10+
CMD ["yarn", "serve", "--host", "0.0.0.0", "--port", "80"]

dev/zimit_ui_dev/environ.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"ZIMFARM_WEBAPI": "http://localhost:8004/v1",
3+
"ZIMIT_API_URL": "http://localhost:8002/api/v1"
4+
}

0 commit comments

Comments
 (0)