Skip to content

Commit

Permalink
docker: add static build examples
Browse files Browse the repository at this point in the history
Signed-off-by: deadprogram <[email protected]>
  • Loading branch information
deadprogram committed Sep 19, 2024
1 parent a20f413 commit 5e89541
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
13 changes: 7 additions & 6 deletions Dockerfile-static
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
# to build this docker image:
# docker build -f Dockerfile-static -t gocv-static .
# docker buildx build -f Dockerfile-static -t gocv-static --platform=linux/amd64,linux/arm64 .
#
FROM ghcr.io/hybridgroup/opencv:4.10.0-static AS gocv-build
FROM --platform=$BUILDPLATFORM ghcr.io/hybridgroup/opencv:4.10.0-static AS gocv-build

ENV GOPATH /go

COPY . /go/src/gocv.io/x/gocv/

WORKDIR /go/src/gocv.io/x/gocv

RUN ls -la /usr/local/lib/opencv4/3rdparty/
RUN --mount=target=. \
--mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod \
go build -tags static -o /build/gocv_version ./cmd/version/

RUN go build -tags static -o /build/gocv_version ./cmd/version/

FROM ubuntu:latest AS final
FROM debian:bullseye AS final

COPY --from=gocv-build /build/gocv_version /run/gocv_version

Expand Down
4 changes: 3 additions & 1 deletion Dockerfile-static-builder
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# to build this docker image:
# docker build -f Dockerfile-static-builder -t gocv-static-builder .
# or for multi-arch builds:
# docker buildx build -f Dockerfile-static-builder -t gocv-static-builder --platform=linux/amd64,linux/arm64 .
#
# to use this docker image:
# cd /path/to/my/project
# docker run --rm -e "BINARYNAME=myapp" -e "SRCPATH=./cmd/mycmd" -v $(pwd):/src -v $(pwd)/build:/build -a stdout -a stderr gocv-static-builder
# docker run --rm -e "BINARYNAME=myapp" -e "SRCPATH=./cmd/mycmd" -v $(pwd):/src -v $(pwd)/build:/build -a stdout -a stderr --platform=linux/arm64 gocv-static-builder
#
# NOTE that you cannot use highgui from the static build!
#
Expand Down

0 comments on commit 5e89541

Please sign in to comment.