Skip to content

Commit

Permalink
Merge pull request #7 from emqx/refactor-mount-dict-at-runtime
Browse files Browse the repository at this point in the history
refactor: mount dict files and add at runtime
  • Loading branch information
zmstone authored Sep 12, 2022
2 parents bc855e2 + ff57737 commit 666ba42
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 268 deletions.
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ USER root
RUN apk add git erlang-dev
RUN wget https://s3.amazonaws.com/rebar3/rebar3 && chmod +x ./rebar3

COPY dict/en_spelling_additions.txt .
COPY rebar.config .
COPY src/* src/

RUN ./rebar3 escriptize && cp -p _build/default/bin/emqx_schema_validate . && \
rm -rf rebar3 src _build && \
(echo; cat en_spelling_additions.txt) >> org/languagetool/resource/en/hunspell/spelling.txt
RUN ./rebar3 escriptize && cp -p _build/default/bin/emqx_schema_validate /usr/bin && \
rm -rf rebar3 src _build

USER languagetool
RUN mkdir /dicts
COPY run.sh /run.sh
ENTRYPOINT ["/run.sh"]
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Check EMQX Schema Spelling

`emqx_schema_validate path/to/schema.json`

# Run in docker

Mount dict files (.txt suffix) to `/dicts/` dir.

```
docker run --rm -v path/to/dicts:/dicts \
-v path/to/schema.json:/schema.json \
ghcr.io/emqx/emqx-schema-validate:0.4.0 /scehma.json
```
263 changes: 0 additions & 263 deletions dict/en_spelling_additions.txt

This file was deleted.

35 changes: 35 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash

set -euo pipefail

for dict in /dicts/*.txt; do
echo "Adding $dict"
cat "$dict" >> org/languagetool/resource/en/hunspell/spelling.txt
done

ARGS="$*"

if [ -z "${ARGS}" ]; then
echo "Missing schema file"
exit 1
fi

## LT is Web server, start it in the background.
echo "Starting LanguageTool server..."
bash /LanguageTool/start.sh >/dev/null &

# health-check the server
attempts=0
limit=10
while ! curl --fail --data "language=en-US&text=a simple test" http://localhost:8010/v2/check >/dev/null 2>&1; do
attempts=$(( attempts + 1 ))
if [ $attempts -gt $limit ]; then
echo "Failed to start LanguageTool in $limit seconds"
exit 1
fi
sleep 1
done

echo "Checking $ARGS..."

emqx_schema_validate "$ARGS"

0 comments on commit 666ba42

Please sign in to comment.