Skip to content

Commit ea408a8

Browse files
authored
Add Docker compose settings. (#121)
* Remove psutil version limit * Update docling and chonkie version. * Bump version to 1.0.14 * Update docling core version. * wip * Fix the docker file path. * wip * Fix dockerfile path. * wip * Add docker-compose files. * Add document home to docker mount. * Add start and stop scripts. * Fix white spaces.
1 parent 4bba669 commit ea408a8

File tree

9 files changed

+186
-12
lines changed

9 files changed

+186
-12
lines changed

.github/workflows/build_llmeds_app.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ jobs:
6464
uses: docker/build-push-action@v5
6565
with:
6666
context: ./
67+
file: docker/Dockerfile
6768
push: true
6869
tags: ${{ env.DOCKER_USERNAME }}/${{ env.APP_NAME }}:latest
6970
platforms: linux/amd64,linux/arm64

docker/README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Run LeetTools Docker containers
2+
3+
We can use Docker Compose to start the LeetTools service and web UI.
4+
5+
## Usage
6+
7+
To build the Docker images, you can run the following command:
8+
```bash
9+
docker/build.sh
10+
```
11+
12+
If you do not want to build the Docker images, you can pull the latest images from the
13+
Docker Hub by running the following command:
14+
```bash
15+
docker compose --profile full pull
16+
```
17+
18+
To start the LeetTools service
19+
```bash
20+
docker/start.sh
21+
```
22+
23+
Now you can go [http://localhost:3000](http://localhost:3000) to access the LeetTools web UI.
24+
25+
By default this command will mount $LEET_HOME directory as read-write volume and
26+
$DOCUMENETS_HOME directory as read-only volume to the Docker containers. The $DOCUMENETS_HOME
27+
is ~/Documents directory on Linux and macOS and C:\Users\<username>\Documents on Windows.
28+
29+
If you need to change these behaviors, you can change the settings in the
30+
[docker/.env](docker/.env) file.
31+
32+
To stop the LeetTools service, you can run the following command:
33+
```bash
34+
docker/stop.sh
35+
```
36+
37+
Note that the leettols-web application is currently under development and not open sourced
38+
yet. We plan to open source it in the near future.

docker/build.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ set -e -u
55
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
66
BASE_DIR="$(cd "$DIR"/.. && pwd)"
77

8+
org_name="leettools"
9+
app_name="leettools"
810
# read the version number project.toml file and use in the docker image
911
version=$(grep "^version = " "$BASE_DIR"/pyproject.toml | cut -d'"' -f2)
1012

@@ -23,9 +25,9 @@ cd "$BASE_DIR"
2325
cp "$DIR"/dockerignore.template "$BASE_DIR"/.dockerignore
2426
cat "$BASE_DIR"/.gitignore >> "$BASE_DIR"/.dockerignore
2527

26-
docker build -t leettools-dev/leettools:"${version}" -f "$DIR"/Dockerfile "$BASE_DIR"
28+
docker build -t "${org_name}/${app_name}":"${version}" -f "$DIR"/Dockerfile "$BASE_DIR"
2729

2830
# tag the image with the latest version
29-
docker tag leettools-dev/leettools:"${version}" leettools-dev/leettools:latest
31+
docker tag "${org_name}/${app_name}":"${version}" "${org_name}/${app_name}":latest
3032

3133
popd > /dev/null

docker/docker-compose.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
version: "3.8"
2+
3+
x-logging: &default-logging # Define a reusable anchor for logging configuration
4+
driver: json-file
5+
options:
6+
max-size: "50m"
7+
max-file: "10"
8+
9+
services:
10+
leettools:
11+
image: leettools/leettools:${LEETTOOLS_VERSION}
12+
logging: *default-logging
13+
container_name: leettools
14+
restart: always
15+
ports:
16+
- "8000:8000"
17+
volumes:
18+
- ${LEET_HOME}:/leettools
19+
# mount any extra directories that have documents need to be processed
20+
- ${DOCUMENETS_HOME}:/leettools/web/incoming/documents:ro
21+
22+
environment:
23+
- LEET_HOME=/leettools
24+
env_file:
25+
- ${LEETTOOLS_ENV_FILE}
26+
profiles: ["full", "compact"]
27+
28+
llmeds-web:
29+
image: leettools/leettools-web:${LEETTOOLS_WEB_VERSION}
30+
logging: *default-logging
31+
restart: always
32+
depends_on:
33+
- leettools
34+
ports:
35+
- "3000:3000"
36+
volumes:
37+
- ${LEET_HOME}/web:/leettools/web
38+
# mount any extra directories that have documents need to be processed
39+
- ${DOCUMENETS_HOME}:/leettools/web/incoming/documents:ro
40+
41+
environment:
42+
- LEET_HOME=/leettools
43+
- SERVICE_DOMAIN=http://leettools:8000
44+
- DEFAULT_LANGUAGE=${DEFAULT_LANGUAGE}
45+
profiles: ["full", "compact"]

docker/env.template

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# env variables for docker-compose.yml
2+
3+
# fix to a stable version if needed
4+
LEETTOOLS_VERSION=latest
5+
LEETTOOLS_WEB_VERSION=latest
6+
7+
LEETTOOLS_ENV_FILE=../.env
8+
DEFAULT_LANGUAGE=en
9+
# specify the DOCUMENETS_HOME variable if you want to use a different directory
10+
# DOCUMENETS_HOME=~/documents

docker/start.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/bash
2+
3+
set -e -u
4+
5+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
6+
7+
# check if the .env file exists in the DIR
8+
env_file="$DIR/.env"
9+
if [ ! -f "$env_file" ]; then
10+
echo "Error: .env file not found in $DIR. Please create one from $DIR/.env.template"
11+
exit 1
12+
fi
13+
14+
# load the .env file into the environment by exporting the variables
15+
while IFS='=' read -r name value; do
16+
if [[ ! $name =~ ^\# ]] && [[ -n $name ]]; then
17+
# we only export the variables that are not set in the environment
18+
current_env_value="${!name:-}"
19+
if [ -z "${current_env_value}" ]; then
20+
export "$name=$value";
21+
else
22+
# print a warning message if the two values are different
23+
if [ "${current_env_value}" != "${value}" ]; then
24+
echo "[start.sh warning] $name is set to $current_env_value in the current environment, but the $env_file file has a different value: $value"
25+
fi;
26+
fi;
27+
fi;
28+
done < "${env_file}"
29+
30+
# set DOCUMENETS_HOME to the Documents directory on different OS
31+
# windows: C:\Users\<username>\Documents
32+
# mac: ~/Documents
33+
# linux: ~/Documents
34+
35+
# if no DOCUMENETS_HOME is set in the .env file, set it to the Documents directory on different OS
36+
if [ -z "${DOCUMENETS_HOME:-}" ]; then
37+
case "$(uname -s)" in
38+
Darwin|Linux)
39+
export DOCUMENETS_HOME=~/Documents
40+
;;
41+
CYGWIN*|MINGW*|MSYS*)
42+
export DOCUMENETS_HOME="$USERPROFILE/Documents"
43+
;;
44+
*)
45+
echo "Unsupported operating system, using the value from .env file"
46+
;;
47+
esac
48+
fi
49+
50+
pushd . > /dev/null
51+
52+
cd "$DIR"
53+
54+
docker compose --profile full down
55+
docker compose --profile full up -d
56+
57+
popd > /dev/null
58+
59+
echo "LeetTools Docker containers started."

docker/start_docker.sh

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

3+
# this program is used to start the docker container for the leettools service
4+
35
set -e -u
46

57
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
@@ -53,7 +55,9 @@ if [ ${#MOUNT_DIRS[@]} -gt 0 ]; then
5355
done
5456
fi
5557

56-
container_name="leettools-svc"
58+
org_name="leettools"
59+
app_name="leettools"
60+
container_name="leettools"
5761

5862
# If force remove is enabled, stop and remove existing container
5963
if [ "$FORCE_REMOVE" = true ]; then
@@ -86,10 +90,10 @@ if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
8690
fi
8791

8892
# check if the docker image exists
89-
if ! docker images leettools-dev/leettools:"${version}" | grep -q "${version}"; then
90-
echo "Docker image leettools-dev/leettools:${version} does not exist"
93+
if ! docker images "${org_name}/${app_name}":"${version}" | grep -q "${version}"; then
94+
echo "Docker image ${org_name}/${app_name}:${version} does not exist"
9195
version="latest"
92-
if ! docker images leettools-dev/leettools:"${version}" | grep -q "${version}"; then
96+
if ! docker images "${org_name}/${app_name}":"${version}" | grep -q "${version}"; then
9397
echo "Docker image leettools-dev/leettools:${version} does not exist"
9498
exit 1
9599
fi
@@ -143,7 +147,7 @@ echo "docker run -d ${envfile_opt} ${mount_opts} \\
143147
-v \"$LEET_HOME\":\"$leet_home_in_docker\" \\
144148
-v \"$EDS_DATA_DIR\":\"$leet_home_in_docker/data\" \\
145149
-v \"$EDS_LOG_DIR\":\"$leet_home_in_docker/logs\" \\
146-
leettools-dev/leettools:\"${version}\""
150+
${org_name}/${app_name}:\"${version}\""
147151

148152
# run the docker container
149153
# shellcheck disable=SC2086
@@ -154,4 +158,4 @@ docker run -d ${envfile_opt} ${mount_opts} \
154158
-v "$LEET_HOME":"$leet_home_in_docker" \
155159
-v "$EDS_DATA_DIR":"$leet_home_in_docker/data" \
156160
-v "$EDS_LOG_DIR":"$leet_home_in_docker/logs" \
157-
leettools-dev/leettools:"${version}"
161+
${org_name}/${app_name}:"${version}"

docker/stop.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
set -e -u
4+
5+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
6+
7+
pushd . > /dev/null
8+
cd "$DIR"
9+
10+
docker compose --profile full down
11+
12+
popd > /dev/null
13+
14+
echo "LeetTools Docker containers stopped."
15+

scripts/run.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ if [ -f "${env_file}" ]; then
3434
while IFS='=' read -r name value; do
3535
if [[ ! $name =~ ^\# ]] && [[ -n $name ]]; then
3636
# we only export the variables that are not set in the environment
37-
current_value="${!name:-}"
38-
if [ -z "${current_value}" ]; then
37+
current_env_value="${!name:-}"
38+
if [ -z "${current_env_value}" ]; then
3939
export "$name=$value";
4040
else
4141
# print a warning message if the two values are different
42-
if [ "${current_value}" != "${value}" ]; then
43-
echo "[run.sh warning] Variable $name is already set to $current_value, but the $env_file file has a different value: $value"
42+
if [ "${current_env_value}" != "${value}" ]; then
43+
echo "[run.sh warning] $name is set to $current_env_value in the current environment, but the $env_file file has a different value: $value"
4444
fi;
4545
fi;
4646
fi;

0 commit comments

Comments
 (0)