-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathDockerfile
113 lines (92 loc) · 3.2 KB
/
Dockerfile
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
ARG TFLITE_LIB_DIR=/usr/lib
ARG TENSORFLOW_VERSION=2.17.1
FROM --platform=$BUILDPLATFORM golang:1.23.5-bookworm AS buildenv
# Pass BUILD_VERSION through to the build stage
ARG BUILD_VERSION
ENV BUILD_VERSION=${BUILD_VERSION:-unknown}
# Install Task and other dependencies
RUN apt-get update -q && apt-get install -q -y \
curl \
git \
sudo \
zip \
npm \
gcc-aarch64-linux-gnu && \
rm -rf /var/lib/apt/lists/*
# Install Task
RUN sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b /usr/local/bin
# Create dev-user for building and devcontainer usage
RUN groupadd --gid 10001 dev-user && \
useradd --uid 10001 --gid dev-user --shell /bin/bash --create-home dev-user && \
usermod -aG sudo dev-user && \
usermod -aG audio dev-user && \
echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers && \
mkdir -p /home/dev-user/src && \
mkdir -p /home/dev-user/lib && \
chown -R dev-user:dev-user /home/dev-user
USER dev-user
WORKDIR /home/dev-user/src/BirdNET-Go
# Copy all source files first to have Git information available
COPY --chown=dev-user . ./
# Enter Build stage
FROM --platform=$BUILDPLATFORM buildenv AS build
ARG BUILD_VERSION
ENV BUILD_VERSION=${BUILD_VERSION:-unknown}
ARG TARGETPLATFORM
# Build assets and compile BirdNET-Go
RUN --mount=type=cache,target=/go/pkg/mod,uid=10001,gid=10001 \
--mount=type=cache,target=/home/dev-user/.cache/go-build,uid=10001,gid=10001 \
task check-tensorflow && \
task download-assets && \
task generate-tailwindcss && \
TARGET=$(echo ${TARGETPLATFORM} | tr '/' '_') && \
echo "Building with BUILD_VERSION=${BUILD_VERSION}" && \
BUILD_VERSION="${BUILD_VERSION}" DOCKER_LIB_DIR=/home/dev-user/lib task ${TARGET}
# Create final image using a multi-platform base image
FROM --platform=$TARGETPLATFORM debian:bookworm-slim
# Install ALSA library and SOX for audio processing, and other system utilities for debugging
RUN apt-get update -q && apt-get install -q -y --no-install-recommends \
ca-certificates \
libasound2 \
ffmpeg \
sox \
procps \
iproute2 \
net-tools \
curl \
wget \
nano \
vim \
less \
tzdata \
jq \
strace \
lsof \
bash-completion
# Clean up apt cache
RUN rm -rf /var/lib/apt/lists/*
# Set TFLITE_LIB_DIR based on architecture
ARG TARGETPLATFORM
ARG TFLITE_LIB_DIR
RUN if [ "$TARGETPLATFORM" = "linux/arm64" ]; then \
export TFLITE_LIB_DIR=/usr/aarch64-linux-gnu/lib; \
else \
export TFLITE_LIB_DIR=/usr/lib; \
fi && \
echo "Using TFLITE_LIB_DIR=$TFLITE_LIB_DIR"
# Copy TensorFlow Lite library from build stage
COPY --from=build /home/dev-user/lib/libtensorflowlite_c.so* ${TFLITE_LIB_DIR}/
RUN ldconfig
# Include reset_auth tool from build stage
COPY --from=build /home/dev-user/src/BirdNET-Go/reset_auth.sh /usr/bin/
RUN chmod +x /usr/bin/reset_auth.sh
# Add symlink to /config directory where configs can be stored
VOLUME /config
RUN mkdir -p /root/.config && ln -s /config /root/.config/birdnet-go
VOLUME /data
WORKDIR /data
# Make port 8080 available to the world outside this container
EXPOSE 8080
COPY --from=build /home/dev-user/src/BirdNET-Go/bin /usr/bin/
ENTRYPOINT ["/usr/bin/birdnet-go"]
CMD ["realtime"]