Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize Dockerfile #29

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 65 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,74 @@
FROM debian:bullseye-slim
LABEL maintainer="otiai10 <[email protected]>"
# make base image.
FROM debian:bullseye-slim AS base
LABEL maintainer="otiai10 <[email protected]>" \
updatedBy="RocSun <[email protected]>"

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 <[email protected]>" \
# updatedBy="RocSun <[email protected]>"

# 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"]
12 changes: 9 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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