-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathDockerfile
93 lines (75 loc) · 2.79 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
ARG TFLITE_LIB_DIR=/usr/lib
ARG TENSORFLOW_VERSION=2.17.1
ARG TARGETPLATFORM=linux/amd64 # Default to linux/amd64 for local builds
ARG VERSION=unknown
FROM --platform=$TARGETPLATFORM golang:1.23.5-bookworm AS build
# Pass VERSION through to the build stage
ARG VERSION
ENV VERSION=$VERSION
# Install Task and other dependencies
RUN apt-get update && apt-get install -y \
curl \
git \
sudo \
zip \
npm \
gcc-aarch64-linux-gnu \
&& rm -rf /var/lib/apt/lists/* \
&& 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 . ./
# Now run the tasks with VERSION env var
RUN task check-tensorflow && \
task download-assets && \
task generate-tailwindcss
# Compile BirdNET-Go
ARG TARGETPLATFORM
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 \
TARGET=$(echo ${TARGETPLATFORM} | tr '/' '_') && \
DOCKER_LIB_DIR=/home/dev-user/lib VERSION=${VERSION} task ${TARGET}
# Create final image using a multi-platform base image
FROM debian:bookworm-slim
# Install ALSA library and SOX
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
libasound2 \
ffmpeg \
sox \
&& 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"]