-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
97 lines (64 loc) · 2.67 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
FROM ubuntu:latest AS build-stage
# 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
# 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 . .
ENV GOPATH=$HOME/go
ENV PATH=$PATH:$GOPATH/bin
RUN go install github.com/bufbuild/buf/cmd/buf@latest
RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
RUN go install connectrpc.com/connect/cmd/protoc-gen-connect-go@latest
RUN buf generate
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
FROM alpine:latest AS user-stage
# Setup user and group
ENV UID=1000
ENV GID=1000
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
# 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"]