-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
75 lines (60 loc) · 2.79 KB
/
Copy pathDockerfile
File metadata and controls
75 lines (60 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
ARG GO_IMAGE=golang:1.26
ARG RUNTIME_IMAGE=debian:bookworm-slim
FROM ${GO_IMAGE} AS builder
ARG INSPIREFACE_MODEL=Megatron
WORKDIR /src
RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends unzip; \
rm -rf /var/lib/apt/lists/*
COPY docker-assets/downloads /tmp/inspireface-downloads
RUN set -eux; \
mkdir -p /tmp/inspireface/extracted /opt/inspireface-sdk /opt/models; \
sdk_zip="$(find /tmp/inspireface-downloads -maxdepth 1 -type f -name '*.zip' -print -quit)"; \
model_file="/tmp/inspireface-downloads/${INSPIREFACE_MODEL}"; \
if [ -z "$sdk_zip" ]; then \
echo "cannot locate InspireFace SDK zip in docker-assets/downloads" >&2; \
find /tmp/inspireface-downloads -maxdepth 1 -type f | sort >&2; \
exit 1; \
fi; \
if [ ! -s "$model_file" ]; then \
echo "cannot locate InspireFace model file: ${INSPIREFACE_MODEL}" >&2; \
find /tmp/inspireface-downloads -maxdepth 1 -type f | sort >&2; \
exit 1; \
fi; \
unzip -q "$sdk_zip" -d /tmp/inspireface/extracted; \
include_dir="$(find /tmp/inspireface/extracted -type d -name include -print | while read -r dir; do if [ -f "$dir/inspireface.h" ] || [ -f "$dir/inspireface/inspireface.h" ]; then printf '%s\n' "$dir"; break; fi; done)"; \
lib_file="$(find /tmp/inspireface/extracted -type f -name 'libInspireFace.so*' -print -quit)"; \
if [ -z "$include_dir" ] || [ -z "$lib_file" ]; then \
echo "cannot locate InspireFace include/lib in SDK zip" >&2; \
find /tmp/inspireface/extracted -maxdepth 5 -type f | sort >&2; \
exit 1; \
fi; \
cp -a "$include_dir" /opt/inspireface-sdk/include; \
mkdir -p /opt/inspireface-sdk/lib; \
cp -a "$(dirname "$lib_file")"/. /opt/inspireface-sdk/lib/; \
cp -a "$model_file" "/opt/models/${INSPIREFACE_MODEL}"; \
test -s "/opt/models/${INSPIREFACE_MODEL}"; \
rm -rf /tmp/inspireface /tmp/inspireface-downloads
ENV CGO_ENABLED=1
ENV CGO_CFLAGS="-I/opt/inspireface-sdk/include -I/opt/inspireface-sdk/include/inspireface"
ENV CGO_LDFLAGS="-L/opt/inspireface-sdk/lib -lInspireFace"
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN go build -trimpath -ldflags="-s -w" -o /out/faced ./cmd/faced
FROM ${RUNTIME_IMAGE} AS runtime
RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends ca-certificates; \
rm -rf /var/lib/apt/lists/*
ENV TZ=Asia/Shanghai
ENV HTTP_ADDR=:5090
ENV DATABASE_URL=postgres://face:face@postgres:5432/face-data?sslmode=disable
ENV LD_LIBRARY_PATH=/opt/inspireface-sdk/lib
ENV INSPIREFACE_PACK_PATH=/opt/models/Megatron
COPY --from=builder /out/faced /usr/local/bin/faced
COPY --from=builder /opt/inspireface-sdk/lib /opt/inspireface-sdk/lib
COPY --from=builder /opt/models/Megatron /opt/models/Megatron
EXPOSE 5090
CMD ["faced"]