1+ # We are building a static acpid binary from source because the linuxkit/acpid image
2+ # does not work
3+ FROM alpine:3.22 AS alpine
4+
5+ # Install build dependencies
6+ RUN apk add --no-cache \
7+ gcc \
8+ musl-dev \
9+ make \
10+ git \
11+ autoconf \
12+ automake \
13+ libtool \
14+ linux-headers \
15+ wget \
16+ xz \
17+ patch \
18+ busybox-static \
19+ # Install the dynamically built acpid so that we can get the handler script and event files
20+ acpid
21+
22+ # Download and build acpid
23+ ENV ACPID_VERSION=2.0.34
24+ RUN wget https://sourceforge.net/projects/acpid2/files/acpid-${ACPID_VERSION}.tar.xz/download -O acpid-${ACPID_VERSION}.tar.xz && \
25+ tar -xf acpid-${ACPID_VERSION}.tar.xz
26+
27+ WORKDIR /acpid-${ACPID_VERSION}
28+
29+ # Fix musl compatibility - replace stat64/fstat64 with stat/fstat
30+ RUN sed -i 's/struct stat64/struct stat/g' sock.c && \
31+ sed -i 's/fstat64/fstat/g' sock.c
32+
33+ # Build static binary with musl-compatible flags
34+ RUN ./configure \
35+ --enable-static \
36+ --disable-shared \
37+ CFLAGS="-D_GNU_SOURCE -Os" \
38+ LDFLAGS="-static" && \
39+ make && \
40+ strip acpid && \
41+ cp acpid /usr/bin/
42+
43+ # Verify it's statically linked
44+ RUN ldd /usr/bin/acpid 2>&1 | grep -q "not a dynamic executable" || echo "Warning: not statically linked"
45+
46+ # Copy BusyBox static binary and create poweroff symlink
47+ RUN mkdir -p /stage/bin && cp /bin/busybox.static /bin/busybox && \
48+ ln -s /bin/busybox /stage/bin/poweroff && \
49+ ln -s /bin/busybox /stage/bin/logger && \
50+ # This is needed for the acpid handler scripts (/etc/acpi/handler.sh, /etc/acpi/events/anything) to work
51+ ln -s /bin/busybox /stage/bin/sh
52+
53+ FROM scratch
54+ WORKDIR /
55+ ENTRYPOINT []
56+ COPY --from=alpine /usr/bin/acpid /usr/bin/
57+ COPY --from=alpine /etc/acpi/events/anything /etc/acpi/events/anything
58+ COPY --from=alpine /etc/acpi/handler.sh /etc/acpi/handler.sh
59+ COPY --from=alpine /bin/busybox /bin/busybox
60+ COPY --from=alpine /stage/ /
61+ CMD ["/usr/bin/acpid" , "-f" , "-d" ]
0 commit comments