diff --git a/Dockerfile b/Dockerfile index c31a96d..1561982 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,25 +1,74 @@ -FROM debian:bullseye-slim -LABEL maintainer="otiai10 " +# make base image. +FROM debian:bullseye-slim AS base +LABEL maintainer="otiai10 " \ + updatedBy="RocSun " -ARG LOAD_LANG=jpn +RUN apt-get update \ + && apt-get install -y ca-certificates \ + apt-transport-https \ + # this setting local apt mirrors + && cp -a /etc/apt/sources.list /etc/apt/sources.list.bak \ + && sed -i "s@http://deb.debian.org@https://repo.huaweicloud.com@g" /etc/apt/sources.list \ + && sed -i "s@http://security.debian.org@https://repo.huaweicloud.com@g" /etc/apt/sources.list \ + && apt-get update \ + && apt-get install -y libtesseract-dev=4.1.1-2.1 \ + tesseract-ocr=4.1.1-2.1 -RUN apt update \ - && apt install -y \ - ca-certificates \ - libtesseract-dev=4.1.1-2.1 \ - tesseract-ocr=4.1.1-2.1 \ - golang=2:1.15~1 +# build source. +FROM base AS build + +RUN apt install -y golang=2:1.15~1 ENV GO111MODULE=on -ENV GOPATH=${HOME}/go +ENV GOPROXY="https://goproxy.cn,direct" +ENV GOPATH=/go ENV PATH=${PATH}:${GOPATH}/bin -ADD . $GOPATH/src/github.com/otiai10/ocrserver -WORKDIR $GOPATH/src/github.com/otiai10/ocrserver +ADD . $GOPATH/src/ocrserver +WORKDIR $GOPATH/src/ocrserver RUN go get -v ./... && go install . -# Load languages -RUN if [ -n "${LOAD_LANG}" ]; then apt-get install -y tesseract-ocr-${LOAD_LANG}; fi - +# make run env. This is build image. +FROM base AS OS ENV PORT=8080 -CMD ["ocrserver"] +COPY --from=build /go /go + +ARG LOAD_LANG=chi-sim +RUN if [ -n "${LOAD_LANG}" ]; then apt-get install -y tesseract-ocr-${LOAD_LANG}; fi \ + && apt-get clean +CMD [ "/go/bin/ocrserver" ] + +# ################################################################################ +# # debian:bullseye-slim image size of is about 220M. # +# # if use alpine. image size of is about 160M. Here's the alpine-based code # +# # min image in dockerhub rocsun/ocr-server # +# ################################################################################ + +# FROM alpine:3.14 as base +#LABEL maintainer="otiai10 " \ +# updatedBy="RocSun " + +# RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories \ +# && apk add tesseract-ocr \ +# && apk add tesseract-ocr-dev \ +# && apk add tesseract-ocr-data-chi_sim + +# FROM base AS build + +# RUN apk add go \ +# g++ + +# ENV GO111MODULE=on +# ENV GOPROXY="https://goproxy.cn,direct" +# ENV GOPATH=/go +# ENV PATH=${PATH}:${GOPATH}/bin + +# ADD . $GOPATH/src/ocrserver +# WORKDIR $GOPATH/src/ocrserver +# RUN go get -v ./... && go install . + +# FROM base AS OS +# RUN apk add bash +# COPY --from=build /go /go +# ENV PORT=8080 +# CMD ["/go/bin/ocrserver"] diff --git a/docker-compose.yml b/docker-compose.yml index e0e558a..aff107e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,10 +1,16 @@ version: "3.7" services: - web: - build: + ocr-web: + build: context: . - # dockerfile: Dockerfile + dockerfile: Dockerfile ports: - "8080:8080" environment: PORT: 8080 + # container_name: ocr-server + # command: + # - /bin/bash + # - -c + # - | + # /go/bin/ocrserver \ No newline at end of file