gocv icon indicating copy to clipboard operation
gocv copied to clipboard

question: build Dockerfile with multi-stage

Open saartamir opened this issue 3 years ago • 7 comments

I'm trying to build multi-stage Dockerfile so I can reduce the image size from current size (2GB). I'm using gocv/opencv:4.5.2 to build the binary file on first stage and debian:buster for the second stage (I saw that you use buster for the gocv image, so I'm using it also). I'm copying /usr/local into the second-stage image, since this is what configured in the cmake prefix configuration. When I'm running the docker image I get an error that dependent files are missing... I can find them but then it keeps happening over and over with different files... Has anyone managed to use multi-stage approach here?

saartamir avatar Apr 27 '21 10:04 saartamir

I have the same question. Did you end up finding a solution?

bryanmcgrane avatar Jun 08 '21 18:06 bryanmcgrane

I have the same question. Did you end up finding a solution?

opvexe avatar Nov 03 '21 01:11 opvexe

Nope.. I'm still using one step instead.

saartamir avatar Nov 03 '21 07:11 saartamir

Can I ask, your OpencV made arm dockerfile ?

opvexe avatar Nov 03 '21 07:11 opvexe

This is my current Dockerfile:

FROM gocv/opencv:4.5.2 AS build-stage


WORKDIR $GOPATH/src/github.com/Anzu-Team/anzu_go
COPY go.mod go.sum ./

RUN go env -w GO111MODULE=on
RUN go mod download
RUN go mod verify

COPY . .

RUN GOOS=linux GOARCH=amd64 go build -a -ldflags='-w -s' -tags matprofile -o /go/bin/anzu_go/anzu_image_processor/anzu_image_processor ./anzu_image_processor/main.go

saartamir avatar Nov 03 '21 07:11 saartamir

This dockerfile only supports AMD64 and not ARM64.

This is my test dockerfile

FROM --platform=$BUILDPLATFORM gocv/opencv:4.5.3 as builder
ENV TZ=Asia/Shanghai LANG="C.UTF-8"
ARG TARGETARCH
ARG TARGETOS

WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
ENV GO111MODULE=on
ENV GOPROXY=https://goproxy.io,direct

# Copy the go source
COPY video video

# Build
RUN CGO_ENABLED=1 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -a -o videod video/cmd/main.go

FROM gocv/opencv:4.5.3
WORKDIR /
COPY --from=builder /workspace/videod .
COPY --from=builder /workspace/video/net /etc/
ENTRYPOINT ["/videod"]

opvexe avatar Nov 03 '21 08:11 opvexe

This is my current Dockerfile:

FROM gocv/opencv:4.5.2 AS build-stage


WORKDIR $GOPATH/src/github.com/Anzu-Team/anzu_go
COPY go.mod go.sum ./

RUN go env -w GO111MODULE=on
RUN go mod download
RUN go mod verify

COPY . .

RUN GOOS=linux GOARCH=amd64 go build -a -ldflags='-w -s' -tags matprofile -o /go/bin/anzu_go/anzu_image_processor/anzu_image_processor ./anzu_image_processor/main.go

This only supports THE AMD64 architecture and does not support the ARM64 architecture ...

opvexe avatar Nov 03 '21 09:11 opvexe