Update build-tesseract.yml #3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: build-tesseract-static | |
| on: | |
| workflow_dispatch: {} | |
| push: | |
| paths: | |
| - .github/workflows/build-tesseract.yml | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Write Dockerfile (Alpine + static build) | |
| run: | | |
| cat > Dockerfile <<'EOF' | |
| FROM alpine:3.20 AS build | |
| # Toolchain + deps | |
| RUN apk add --no-cache \ | |
| build-base autoconf automake libtool pkgconfig bash coreutils \ | |
| zlib-dev libjpeg-turbo-dev libpng-dev tiff-dev icu-dev curl | |
| WORKDIR /src | |
| # -------- Build Leptonica (static) -------- | |
| ENV LEPT_VER=1.84.1 | |
| RUN curl -L -o leptonica.tar.gz \ | |
| https://github.com/DanBloomberg/leptonica/archive/refs/tags/${LEPT_VER}.tar.gz \ | |
| && tar xf leptonica.tar.gz \ | |
| && cd leptonica-${LEPT_VER} \ | |
| && ( [ -x ./autogen.sh ] && ./autogen.sh || autoreconf -fi ) \ | |
| && ./configure --enable-static --disable-shared \ | |
| && make -j"$(nproc)" \ | |
| && make install | |
| # -------- Build Tesseract (static) -------- | |
| ENV TESS_VER=5.3.3 | |
| RUN curl -L -o tesseract.tar.gz \ | |
| https://github.com/tesseract-ocr/tesseract/archive/refs/tags/${TESS_VER}.tar.gz \ | |
| && tar xf tesseract.tar.gz \ | |
| && cd tesseract-${TESS_VER} \ | |
| && ./autogen.sh \ | |
| && PKG_CONFIG="pkg-config --static" ./configure --enable-static --disable-shared \ | |
| && make -j"$(nproc)" \ | |
| && make install \ | |
| && strip /usr/local/bin/tesseract | |
| # Output | |
| RUN mkdir -p /out && cp /usr/local/bin/tesseract /out/tesseract | |
| FROM scratch AS export | |
| COPY --from=build /out/tesseract /tesseract | |
| EOF | |
| - name: Build (plain logs) | |
| env: | |
| DOCKER_BUILDKIT: "1" | |
| run: docker build --progress=plain -t tess-static:latest . | |
| - name: Extract binary | |
| run: | | |
| cid=$(docker create tess-static:latest) | |
| docker cp "$cid:/tesseract" ./tesseract | |
| docker rm "$cid" | |
| chmod +x ./tesseract | |
| - name: Verify static-ness | |
| run: | | |
| file ./tesseract || true | |
| # ldd SHOULD fail for a truly static binary (no shared libs) | |
| (ldd ./tesseract && exit 1) || echo "ldd failed as expected for a static binary" | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: tesseract-linux-x86_64-static | |
| path: ./tesseract |