Skip to content

Commit

Permalink
Merge branch 'add_mandarin_to_docker_image' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
jzohrab committed May 30, 2024
2 parents 350b7d4 + fb6ecf3 commit 39c4644
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ jobs:
- run: pip install -r requirements.txt
- name: Test docker build
run: |
docker build -f docker/Dockerfile --build-arg INSTALL_MECAB=false -t lute3 .
docker build -f docker/Dockerfile --build-arg INSTALL_EVERYTHING=false -t lute3 .
# Run container in the background, and check.
docker run -d -p 5000:5000 -v ./my_data:/lute_data -v ./my_backups:/lute_backup --name my-lute lute3:latest
sleep 10 # Give it a moment to start.
Expand Down
39 changes: 19 additions & 20 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
# The Dockerfile can be used to create two variants
# by using "--build-arg INSTALL_MECAB=[true|false]":
# - "true": with mecab and dictionary (800+ MB)
# - "false": without (300 MB)
# by using "--build-arg INSTALL_EVERYTHING=[true|false]":
# - "true": with mecab and dictionary, mandarin parser (800+ MB)
# - "false": without (230 MB)
#
# e.g. docker build --build-arg INSTALL_EVERYTHING=true -t lute3 .

# Official python base image.
FROM python:3.11-slim-bookworm

# Define a build argument with a default value.
ARG INSTALL_MECAB=false
WORKDIR /lute

# Install mecab for Japanese support if INSTALL_MECAB is true, e.g.
# docker build --build-arg INSTALL_MECAB=true -t lute3 .
RUN if [ "$INSTALL_MECAB" = "true" ]; then \
apt-get update -y && \
apt-get install -y mecab mecab-ipadic-utf8 && \
apt-get clean && rm -rf /var/lib/apt/lists/*; \
fi

# Lute code and config.
COPY requirements.txt .
# Install base.
ENV PIP_ROOT_USER_ACTION=ignore
RUN pip install -r requirements.txt
COPY lute /lute
RUN mv /lute/config/config.yml.docker /lute/config/config.yml
RUN pip install lute3
COPY lute/config/config.yml.docker ./config.yml

# Build arg, defaults to false.
ARG INSTALL_EVERYTHING=false

COPY docker/Dockerfile_scripts/install_everything.sh ./install_all.sh
RUN chmod +x ./install_all.sh

RUN if [ "$INSTALL_EVERYTHING" = "true" ]; then ./install_all.sh; fi

EXPOSE 5000

# Start script.
COPY docker/check_mounts_and_start.sh /lute/start.sh
RUN chmod +x /lute/start.sh
COPY docker/Dockerfile_scripts/start.sh ./start.sh
RUN chmod +x ./start.sh
ENTRYPOINT ["/lute/start.sh"]
12 changes: 12 additions & 0 deletions docker/Dockerfile_scripts/install_everything.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh
#
# Install all the extra stuff when using INSTALL_EVERYTHING
# in the Dockerfile.

# Mecab
apt-get update -y
apt-get install -y mecab mecab-ipadic-utf8
apt-get clean && rm -rf /var/lib/apt/lists/*

# Mandarin.
pip install lute3-mandarin
File renamed without changes.
4 changes: 2 additions & 2 deletions docker/build_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ docker buildx build \
--push \
--platform linux/amd64,linux/arm64 \
-f docker/Dockerfile "$@" \
--build-arg INSTALL_MECAB=true \
--build-arg INSTALL_EVERYTHING=true \
-t $TAG -t $LATEST .

echo
Expand All @@ -57,7 +57,7 @@ docker buildx build \
--push \
--platform linux/amd64,linux/arm64 \
-f docker/Dockerfile "$@" \
--build-arg INSTALL_MECAB=false \
--build-arg INSTALL_EVERYTHING=false \
-t $LEANTAG -t $LEANLATEST .

echo
Expand Down
4 changes: 3 additions & 1 deletion docker/build_test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

docker build -f docker/Dockerfile --build-arg INSTALL_MECAB=true -t lute3 .
docker build -f docker/Dockerfile --build-arg INSTALL_EVERYTHING=true -t lute3 .

docker build -f docker/Dockerfile --build-arg INSTALL_EVERYTHING=false -t lute3-lean .
2 changes: 1 addition & 1 deletion docker/try_build_multi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ docker buildx build \
--push \
--platform linux/amd64,linux/arm64 \
-f docker/Dockerfile "$@" \
--build-arg INSTALL_MECAB=true \
--build-arg INSTALL_EVERYTHING=true \
-t $TAG .

# Remove the current builder
Expand Down
4 changes: 3 additions & 1 deletion utils/findstring.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ SEARCHFOR="$@"

function runsearch() {
echo "# $1 ---------------"
find $1 -name "*.*" -maxdepth $2 -print0 | xargs -0 grep "$SEARCHFOR" 2>/dev/null | grep -v findstring.sh | grep -v Binary | grep -v js/jquery | grep -v docs/archive | grep -v lute/static/vendor
find $1 -name "*" -maxdepth $2 -print0 | xargs -0 grep "$SEARCHFOR" 2>/dev/null | grep -v findstring.sh | grep -v Binary | grep -v js/jquery | grep -v docs/archive | grep -v lute/static/vendor
}

runsearch . 1
runsearch lute 8
runsearch tests 8
runsearch utils 8
runsearch .github 8
runsearch docker 8
runsearch plugins 8

# Script sometimes returned w/ non-zero exit code,
# breaking testing.
Expand Down

0 comments on commit 39c4644

Please sign in to comment.