-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDockerfile
84 lines (65 loc) · 2.8 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
# Use the official Golang image as the base image
FROM golang:latest as builder
# Install required dependencies
RUN apt-get update && apt-get install -y \
wget \
git \
gcc \
unzip \
build-essential
RUN apt-get install -y -qq libtesseract-dev libleptonica-dev
# Install protobuf compiler and gRPC plugins
RUN apt-get install -y protobuf-compiler
RUN go install google.golang.org/protobuf/cmd/[email protected]
RUN go install google.golang.org/grpc/cmd/[email protected]
RUN mv /go/bin/protoc-gen-go* /usr/local/bin/
# Download and install TensorFlow C library
RUN wget https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-2.11.0.tar.gz && \
tar -C /usr -xzf libtensorflow-cpu-linux-x86_64-2.11.0.tar.gz && \
ldconfig && \
rm libtensorflow-cpu-linux-x86_64-2.11.0.tar.gz
# Set the environment variables to help the Go compiler find the TensorFlow C library
ENV LD_LIBRARY_PATH /usr/local/lib
ENV CGO_CFLAGS "-I/usr/local/include"
ENV CGO_LDFLAGS "-L/usr/local/lib"
# Create a working directory for your Go project
WORKDIR /app
# Copy the Go project files into the container
COPY . .
# Create the required directories
RUN mkdir -p grpcModels
RUN mkdir -p assets/temp
RUN mkdir -p assets/nsfw
RUN wget -q https://github.com/GantMan/nsfw_model/releases/download/1.2.0/mobilenet_v2_140_224.1.zip
RUN unzip mobilenet_v2_140_224.1.zip && mv mobilenet_v2_140_224/* /app/assets/nsfw/ && rm -r mobilenet_v2_140_224 mobilenet_v2_140_224.1.zip
# Compile the .proto files
RUN cd ./proto && \
protoc --go_out=../grpcModels --go_opt=paths=source_relative --go-grpc_out=../grpcModels --go-grpc_opt=paths=source_relative *.proto
# Build the Go project
RUN go mod tidy && \
go build -o main .
#Use the official TensorFlow image as the base image
FROM ubuntu:latest
# Install required dependencies
RUN apt-get update && \
apt-get install -y software-properties-common && \
rm -rf /var/lib/apt/lists/*
RUN add-apt-repository ppa:alex-p/tesseract-ocr5
RUN apt-get update -qq
RUN apt-get install -y -qq curl libtesseract-dev libleptonica-dev
RUN apt install -y tesseract-ocr
ENV TESSDATA_PREFIX=/usr/share/tesseract-ocr/4.00/tessdata/
RUN apt-get install -y -qq tesseract-ocr-eng tesseract-ocr
RUN ldconfig
COPY --from=builder /app/main .
COPY --from=builder /app/pic.jpg .
COPY --from=builder /app/bad_words_fallback.txt .
COPY --from=builder /app/assets/nsfw /assets/nsfw
COPY --from=builder /app/assets/temp /assets/temp
COPY --from=builder /app/labels.txt /assets/nsfw/labels.txt
COPY --from=builder /usr/lib/libtensorflow.so.2 /usr/local/lib/
COPY --from=builder /usr/lib/libtensorflow_framework.so.2 /usr/local/lib/
# Set the environment variables to help the runtime find the TensorFlow C library
ENV LD_LIBRARY_PATH /usr/local/lib
LABEL authors="M1chl"
CMD ["./main"]