-
-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add instruction and docker example for static build
- Loading branch information
1 parent
8aa85a7
commit 9476e32
Showing
2 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
##### | ||
# This is an example to showcase how to build a statically linked binary | ||
# of your go project which uses gosseract. | ||
# The below steps only support the use of PNG files, read the instruction | ||
# on each step to use other formats. | ||
##### | ||
|
||
FROM ubuntu:latest AS build-stage | ||
|
||
# Build tools and dependencies | ||
|
||
# To use other file types, you need to include their library. | ||
# Example: PNG requires libpng-dev and xz-utils. | ||
|
||
# To use other languages than English, add their traineddata below. | ||
RUN apt-get update | ||
RUN apt-get install -y \ | ||
g++-10 autoconf make git golang libtool pkg-config \ | ||
xz-utils libpng-dev \ | ||
tesseract-ocr-eng | ||
|
||
|
||
# Leptonica static build ( required for tesseract ) | ||
|
||
# To use other file types, you need to remove the disable flag | ||
# for that filetype. Example: remove '--without-jpeg' to use JPEG images. | ||
WORKDIR /build/leptonica | ||
RUN git clone --depth 1 https://github.com/DanBloomberg/leptonica.git . | ||
RUN ./autogen.sh | ||
RUN ./configure '--with-pic' '--disable-shared' '--without-zlib' '--without-jpeg' '--without-libtiff' '--without-giflib' '--without-libwebp' '--without-libwebpmux' '--without-libopenjpeg' '--disable-programs' 'CXX=g++-10' 'CFLAGS=-D DEFAULT_SEVERITY=L_SEVERITY_ERROR -g0 -O3' | ||
RUN make | ||
RUN make install | ||
|
||
|
||
# Tesseract static build | ||
WORKDIR /build/tesseract | ||
RUN git clone --depth 1 https://github.com/tesseract-ocr/tesseract.git . | ||
RUN ./autogen.sh | ||
RUN ./configure '--with-pic' '--disable-shared' '--disable-legacy' '--disable-graphics' '--disable-openmp' '--without-curl' '--without-archive' '--disable-doc' 'CXX=g++-10' 'CXXFLAGS=-DTESS_EXPORTS -g0 -O3 -ffast-math' | ||
RUN make | ||
RUN make install | ||
|
||
|
||
# App static build | ||
WORKDIR /build/app | ||
COPY . . | ||
|
||
# To user other file types, add their library flags. | ||
# Example: PNG requires -lpng and -lz. | ||
RUN CGO_ENABLED=1 GOOS=linux \ | ||
go build -a -tags netgo -ldflags '-extldflags "-static -L/usr/local/lib -ltesseract -lleptonica -lpng -lz"' ./app.go | ||
|
||
|
||
FROM scratch | ||
|
||
# Binaries | ||
COPY --from=build-stage /build/app/app /app | ||
|
||
# Tesseract traineddata | ||
|
||
# To use other language, include their traineddata below | ||
COPY --from=build-stage /usr/share/tesseract-ocr/5/tessdata/eng.traineddata /usr/local/share/tessdata/eng.traineddata | ||
|
||
|
||
CMD ["/app"] |
This file contains 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