-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to scratch baseimage for docker
- Loading branch information
1 parent
c91f219
commit 7936bfb
Showing
1 changed file
with
84 additions
and
20 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 |
---|---|---|
@@ -1,32 +1,96 @@ | ||
FROM alpine:latest | ||
FROM ubuntu:latest AS build-stage | ||
|
||
RUN apk add --no-cache \ | ||
go \ | ||
tesseract-ocr \ | ||
tesseract-ocr-dev \ | ||
leptonica-dev \ | ||
g++ \ | ||
tesseract-ocr-data-eng \ | ||
ffmpeg | ||
|
||
WORKDIR /src | ||
# Build tools and dependencies | ||
RUN apt-get update | ||
RUN apt-get install -y \ | ||
g++-10 autoconf make git golang libtool pkg-config wget xz-utils libpng-dev \ | ||
tesseract-ocr-eng \ | ||
protobuf-compiler | ||
|
||
COPY go.mod go.sum ./ | ||
RUN go mod download && go mod verify | ||
# FFmpeg static build | ||
WORKDIR /build/ffmpeg | ||
RUN wget https://johnvansickle.com/ffmpeg/builds/ffmpeg-git-amd64-static.tar.xz | ||
RUN tar -xvf ffmpeg-git-amd64-static.tar.xz | ||
RUN mkdir bin | ||
RUN cp ffmpeg-git-*-amd64-static/ffmpeg bin/ffmpeg | ||
RUN cp ffmpeg-git-*-amd64-static/ffprobe bin/ffprobe | ||
|
||
|
||
# Leptonica static build ( required for tesseract ) | ||
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 | ||
|
||
|
||
# Subtle static build | ||
WORKDIR /build/subtle | ||
COPY . . | ||
RUN go build -o /bin/subtle ./cmd/subtle | ||
|
||
RUN apk del go | ||
ENV GOPATH=$HOME/go | ||
ENV PATH=$PATH:$GOPATH/bin | ||
|
||
RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@latest | ||
RUN go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest | ||
|
||
RUN make proto | ||
|
||
RUN CGO_ENABLED=1 GOOS=linux \ | ||
go build -a -tags netgo -ldflags '-extldflags "-static -L/usr/local/lib -ltesseract -lleptonica -lpng -lz"' ./cmd/subtle | ||
|
||
|
||
# Empty volume mount points | ||
RUN mkdir /volumes | ||
RUN mkdir /volumes/media | ||
RUN mkdir /volumes/config | ||
|
||
|
||
|
||
WORKDIR /media | ||
FROM alpine:latest AS user-stage | ||
|
||
ARG UID=1000 | ||
ARG GID=1000 | ||
# Setup user and group | ||
ENV UID=1000 | ||
ENV GID=1000 | ||
|
||
RUN addgroup -g ${GID} docker && \ | ||
adduser -D -u ${UID} -G docker subtle | ||
RUN addgroup -g $GID docker | ||
RUN adduser -S -u $UID -G docker subtle | ||
|
||
|
||
|
||
FROM scratch | ||
|
||
# User and group | ||
COPY --from=user-stage /etc/passwd /etc/passwd | ||
COPY --from=user-stage /etc/group /etc/group | ||
|
||
USER subtle:docker | ||
|
||
CMD ["/bin/subtle"] | ||
|
||
# Binaries | ||
COPY --from=build-stage /build/subtle/subtle /subtle | ||
|
||
COPY --from=build-stage /build/ffmpeg/bin/ffmpeg /usr/local/bin/ffmpeg | ||
COPY --from=build-stage /build/ffmpeg/bin/ffprobe /usr/local/bin/ffprobe | ||
|
||
|
||
# OCR Language data | ||
COPY --from=build-stage /usr/share/tesseract-ocr/5/tessdata/eng.traineddata /usr/local/share/tessdata/eng.traineddata | ||
|
||
|
||
# Volume mounts | ||
COPY --from=build-stage /volumes/media /media | ||
COPY --from=build-stage /volumes/config /config | ||
|
||
CMD ["/subtle"] |