|
| 1 | +FROM elasticsearch:8.15.1 as build |
| 2 | +USER root |
| 3 | +RUN apt-get update && \ |
| 4 | + apt-get install -y bzip2 make procps httping curl && \ |
| 5 | + rm -rf /var/lib/apt/lists/* |
| 6 | +COPY --from=ghcr.io/astral-sh/uv:0.9.13 /uv /uvx /bin/ |
| 7 | + |
| 8 | +RUN mkdir -p /srv |
| 9 | +COPY pyproject.toml uv.lock Makefile /srv/ |
| 10 | +COPY indexer /srv/indexer |
| 11 | +COPY extractor /srv/extractor |
| 12 | +COPY definitions /srv/definitions |
| 13 | +COPY catalan-dict-tools /srv/catalan-dict-tools |
| 14 | +WORKDIR /srv |
| 15 | +COPY .python-version /srv/ |
| 16 | + |
| 17 | +RUN uv python install $(cat .python-version) && \ |
| 18 | + uv sync |
| 19 | + |
| 20 | +ENV discovery.type=single-node |
| 21 | +ENV xpack.security.enabled=false |
| 22 | +ENV ES_JAVA_OPTS="-Xms512m -Xmx512m" |
| 23 | + |
| 24 | +# Start Elasticsearch, wait for health, run indexing, then stop |
| 25 | +RUN set -e && \ |
| 26 | + runuser -u elasticsearch -- /usr/share/elasticsearch/bin/elasticsearch -d -p /tmp/es.pid && \ |
| 27 | + echo "Waiting for Elasticsearch to be ready..." && \ |
| 28 | + for i in $(seq 1 180); do \ |
| 29 | + if curl -s http://localhost:9200/_cluster/health 2>/dev/null | grep -q '"status":"green\|yellow"'; then \ |
| 30 | + echo "Elasticsearch is ready!"; \ |
| 31 | + break; \ |
| 32 | + fi; \ |
| 33 | + if [ $i -eq 180 ]; then \ |
| 34 | + echo "Elasticsearch failed to start"; \ |
| 35 | + exit 1; \ |
| 36 | + fi; \ |
| 37 | + echo "Waiting... ($i/180)"; \ |
| 38 | + sleep 2; \ |
| 39 | + done && \ |
| 40 | + make generate-data; \ |
| 41 | + MAKE_EXIT_CODE=$?; \ |
| 42 | + echo "Flushing data to disk..." && \ |
| 43 | + curl -X POST "http://localhost:9200/_flush" 2>/dev/null || true && \ |
| 44 | + sleep 2 && \ |
| 45 | + echo "Shutting down Elasticsearch..." && \ |
| 46 | + if [ -f /tmp/es.pid ]; then \ |
| 47 | + ES_PID=$(cat /tmp/es.pid); \ |
| 48 | + kill -TERM $ES_PID 2>/dev/null || true; \ |
| 49 | + for i in $(seq 1 60); do \ |
| 50 | + if ! kill -0 $ES_PID 2>/dev/null; then \ |
| 51 | + echo "Elasticsearch stopped cleanly"; \ |
| 52 | + break; \ |
| 53 | + fi; \ |
| 54 | + if [ $i -eq 60 ]; then \ |
| 55 | + echo "Force killing Elasticsearch"; \ |
| 56 | + kill -9 $ES_PID 2>/dev/null || true; \ |
| 57 | + fi; \ |
| 58 | + sleep 1; \ |
| 59 | + done; \ |
| 60 | + fi && \ |
| 61 | + sleep 3 && \ |
| 62 | + echo "Removing lock files..." && \ |
| 63 | + find /usr/share/elasticsearch/data -name "*.lock" -type f -delete && \ |
| 64 | + find /usr/share/elasticsearch/data -name "write.lock" -type f -delete && \ |
| 65 | + if [ $MAKE_EXIT_CODE -ne 0 ]; then \ |
| 66 | + echo "ERROR: make generate-data failed with exit code $MAKE_EXIT_CODE"; \ |
| 67 | + exit $MAKE_EXIT_CODE; \ |
| 68 | + fi && \ |
| 69 | + echo "Indexing complete!" |
| 70 | + |
| 71 | +FROM elasticsearch:8.15.1 |
| 72 | +USER root |
| 73 | +COPY --from=build /usr/share/elasticsearch/data /usr/share/elasticsearch/data |
| 74 | +RUN chown -R elasticsearch:elasticsearch /usr/share/elasticsearch/data |
| 75 | +ENV discovery.type=single-node |
| 76 | +ENV xpack.security.enabled=false |
| 77 | +ENV ES_JAVA_OPTS="-Xms512m -Xmx512m" |
| 78 | +USER elasticsearch |
0 commit comments