Kagami/go-face

Add Docker example with FAQ

romshark opened this issue · 0 comments

I suggest adding a well documented Docker example to avoid the situation I faced today.
I was trying to build the example in the following Docker container:

FROM golang:1.17-bullseye

# Install go-face dependencies
RUN apt-get update && apt-get -y install \
    build-essentials \
    libdlib-dev \
    libblas-dev \
    libatlas-base-dev \
    liblapack-dev \
    libjpeg62-turbo-dev

# Build app
WORKDIR /app
COPY ./go.mod .
COPY ./go.sum .
COPY ./*.go .
COPY ./testdata/ testdata/
RUN go mod download
RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -x -o app

CMD ["./app"]

But I wasn't able to build it. I received g++: fatal error: Killed signal terminated program cc1plus instead:

#13 [9/9] RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -x -o app
#13 sha256:231bad7fb338adee9a431ceebb81dd9089b9d33ad91e14cb252320b9c0476e4a
#13 0.237 WORK=/tmp/go-build3645608083
#13 0.599 mkdir -p $WORK/b038/
#13 0.600 cd /go/pkg/mod/github.com/!kagami/go-face@v0.0.0-20210630145111-0c14797b4d0e
#13 0.600 TERM='dumb' CGO_LDFLAGS='"-g" "-O2" "-ldlib" "-lblas" "-lcblas" "-llapack" "-ljpeg"' /usr/local/go/pkg/tool/linux_amd64/cgo -objdir $WORK/b038/ -importpath github.com/Kagami/go-face -- -I $WORK/b038/ -g -O2 ./error.go ./face.go
#13 0.877 cd $WORK
#13 0.877 gcc -fno-caret-diagnostics -c -x c - -o /dev/null || true
#13 0.889 gcc -Qunused-arguments -c -x c - -o /dev/null || true
#13 0.898 gcc -fdebug-prefix-map=a=b -c -x c - -o /dev/null || true
#13 0.910 gcc -gno-record-gcc-switches -c -x c - -o /dev/null || true
#13 0.922 cd $WORK/b038
#13 0.922 TERM='dumb' gcc -I /go/pkg/mod/github.com/!kagami/go-face@v0.0.0-20210630145111-0c14797b4d0e -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b038=/tmp/go-build -gno-record-gcc-switches -I ./ -g -O2 -o ./_x001.o -c _cgo_export.c
#13 0.975 TERM='dumb' gcc -I /go/pkg/mod/github.com/!kagami/go-face@v0.0.0-20210630145111-0c14797b4d0e -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b038=/tmp/go-build -gno-record-gcc-switches -I ./ -g -O2 -o ./_x002.o -c error.cgo2.c
#13 1.006 TERM='dumb' gcc -I /go/pkg/mod/github.com/!kagami/go-face@v0.0.0-20210630145111-0c14797b4d0e -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b038=/tmp/go-build -gno-record-gcc-switches -I ./ -g -O2 -o ./_x003.o -c face.cgo2.c
#13 1.052 cd $WORK
#13 1.052 g++ -fno-caret-diagnostics -c -x c - -o /dev/null || true
#13 1.064 g++ -Qunused-arguments -c -x c - -o /dev/null || true
#13 1.073 g++ -fdebug-prefix-map=a=b -c -x c - -o /dev/null || true
#13 1.085 g++ -gno-record-gcc-switches -c -x c - -o /dev/null || true
#13 1.103 cd /go/pkg/mod/github.com/!kagami/go-face@v0.0.0-20210630145111-0c14797b4d0e
#13 1.103 TERM='dumb' g++ -I . -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b038=/tmp/go-build -gno-record-gcc-switches -I $WORK/b038/ -g -O2 -std=c++1z -Wall -O3 -DNDEBUG -march=native -o $WORK/b038/_x004.o -c classify.cc
#13 3.309 TERM='dumb' g++ -I . -fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b038=/tmp/go-build -gno-record-gcc-switches -I $WORK/b038/ -g -O2 -std=c++1z -Wall -O3 -DNDEBUG -march=native -o $WORK/b038/_x005.o -c facerec.cc
#13 120.7 # github.com/Kagami/go-face
#13 120.7 g++: fatal error: Killed signal terminated program cc1plus
#13 120.7 compilation terminated.
#13 ERROR: executor failed running [/bin/sh -c CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -x -o app]: exit code: 2

Solution

The solution was actually quite simple. The compiler simply ran out of memory so I just needed to increase the default 2 GB ram limit of Docker for Mac to 4 GB. So I suggest adding this to the FAQ of the Docker example to save other people's time.