From 1ac5ddbf33077d2ca907d1c9d3a735e1bc7ddd44 Mon Sep 17 00:00:00 2001 From: Kostas Drakontidis Date: Fri, 29 May 2026 23:45:50 +0300 Subject: [PATCH] cross compile files for extract embeddings exec --- .../extractEmbeddings/Dockerfile | 55 +++++++++++++++++++ .../extractEmbeddings/Makefile | 10 ++++ .../extractEmbeddings/go.mod | 8 +++ .../extractEmbeddings/go.sum | 4 ++ 4 files changed, 77 insertions(+) create mode 100644 src/officesense_vision/extractEmbeddings/Dockerfile create mode 100644 src/officesense_vision/extractEmbeddings/Makefile create mode 100644 src/officesense_vision/extractEmbeddings/go.mod create mode 100644 src/officesense_vision/extractEmbeddings/go.sum diff --git a/src/officesense_vision/extractEmbeddings/Dockerfile b/src/officesense_vision/extractEmbeddings/Dockerfile new file mode 100644 index 0000000..f7e4fd3 --- /dev/null +++ b/src/officesense_vision/extractEmbeddings/Dockerfile @@ -0,0 +1,55 @@ +ARG BUILDPLATFORM=linux/amd64 +FROM --platform=$BUILDPLATFORM golang:1.26-bookworm AS builder + +# Install dlib deps +RUN dpkg --add-architecture arm64 && \ + apt-get update && apt-get install -y \ + g++-aarch64-linux-gnu \ + libdlib-dev:arm64 \ + libjpeg-dev:arm64 \ + libblas-dev:arm64 \ + libopenblas-dev:arm64 \ + libatlas-base-dev:arm64 \ + liblapack-dev:arm64 \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /app + +# Compiler wrapper for arm64 +RUN printf '#!/bin/bash\nexec aarch64-linux-gnu-gcc "${@//-march=native/-march=armv8-a}"\n' \ + > /usr/local/bin/arm64-gcc && \ + printf '#!/bin/bash\nexec aarch64-linux-gnu-g++ "${@//-march=native/-march=armv8-a}"\n' \ + > /usr/local/bin/arm64-g++ && \ + chmod +x /usr/local/bin/arm64-gcc /usr/local/bin/arm64-g++ + +# Compiler variables for cross-compile to arm64 +ENV CGO_ENABLED=1 \ + GOOS=linux \ + GOARCH=arm64 \ + CC=/usr/local/bin/arm64-gcc \ + CXX=/usr/local/bin/arm64-g++ \ + PKG_CONFIG_PATH=/usr/lib/aarch64-linux-gnu/pkgconfig + +COPY go.mod go.sum ./ +RUN go mod download + +# Pre-compile all CGO deps into cache +RUN go build -v ./... 2>/dev/null || \ + go list -m all && \ + CGO_ENABLED=1 GOOS=linux GOARCH=arm64 \ + go build -gcflags="-trimpath" -v \ + $(go list -f '{{if .CgoFiles}}{{.ImportPath}}{{end}}' ./...) 2>/dev/null; exit 0 + +RUN --mount=type=cache,target=/root/.cache/go-build \ + --mount=type=cache,target=/go/pkg \ + go mod download + +COPY . . + +# Build - reuse CGO cache +RUN --mount=type=cache,target=/root/.cache/go-build \ + --mount=type=cache,target=/go/pkg \ + go build -o extractEmbeddings + +FROM scratch AS export +COPY --from=builder /app/extractEmbeddings /extractEmbeddings \ No newline at end of file diff --git a/src/officesense_vision/extractEmbeddings/Makefile b/src/officesense_vision/extractEmbeddings/Makefile new file mode 100644 index 0000000..f87430d --- /dev/null +++ b/src/officesense_vision/extractEmbeddings/Makefile @@ -0,0 +1,10 @@ +all: + docker buildx build --platform linux/amd64 --cache-from type=local,src=./.docker-cache --cache-to type=local,dest=./.docker-cache --target export --output type=local,dest=./output . + +models: + wget https://github.com/Kagami/go-face-testdata/raw/master/models/shape_predictor_5_face_landmarks.dat + wget https://github.com/Kagami/go-face-testdata/raw/master/models/dlib_face_recognition_resnet_model_v1.dat + wget https://github.com/Kagami/go-face-testdata/raw/master/models/mmod_human_face_detector.dat + +clean: + rm -r output/ diff --git a/src/officesense_vision/extractEmbeddings/go.mod b/src/officesense_vision/extractEmbeddings/go.mod new file mode 100644 index 0000000..11258c0 --- /dev/null +++ b/src/officesense_vision/extractEmbeddings/go.mod @@ -0,0 +1,8 @@ +module OfficeSense/extractEmbeddings + +go 1.26.3 + +require ( + github.com/Kagami/go-face v0.0.0-20210630145111-0c14797b4d0e + golang.org/x/image v0.41.0 +) diff --git a/src/officesense_vision/extractEmbeddings/go.sum b/src/officesense_vision/extractEmbeddings/go.sum new file mode 100644 index 0000000..8164ae0 --- /dev/null +++ b/src/officesense_vision/extractEmbeddings/go.sum @@ -0,0 +1,4 @@ +github.com/Kagami/go-face v0.0.0-20210630145111-0c14797b4d0e h1:lqIUFzxaqyYqUn4MhzAvSAh4wIte/iLNcIEWxpT/qbc= +github.com/Kagami/go-face v0.0.0-20210630145111-0c14797b4d0e/go.mod h1:9wdDJkRgo3SGTcFwbQ7elVIQhIr2bbBjecuY7VoqmPU= +golang.org/x/image v0.41.0 h1:8wS72eGJMJaBxK6okTzd4WaXumUlTVlb753MlsSvTCo= +golang.org/x/image v0.41.0/go.mod h1:uIc348UZMSvS5Z65CVZ7iDPaNobNFEPeJ4kbqTOszmA=