1- FROM alpine:3.12 AS camera-binaries
1+ # Version 3.13 on Raspberry Pi is not able to access network and the
2+ # easiest workaround is to use 3.12.
3+ # https://gitlab.alpinelinux.org/alpine/aports/-/issues/12091
4+ ARG ALPINE_VERSION=3.12
5+
6+ # Build raspistill as part of the Raspberry PI userland binaries. We
7+ # build use alpine to do this to ensure that references to mtrace and
8+ # execinfo aren't included in the final binaries. mtrace and execinfo
9+ # aren't easily available on alpine.
10+ FROM alpine:${ALPINE_VERSION} AS camera-binaries
211
312RUN mkdir /build
413WORKDIR /build
@@ -16,31 +25,50 @@ RUN git clone https://github.com/raspberrypi/userland.git . && \
1625
1726RUN mkdir build && \
1827 cd build && \
19- CXX=g++ cmake -DHAVE_MTRACE=false -DSKIP_TAINTED_CHECK=true -DCMAKE_BUILD_TYPE=armv71 -DARM64=OFF ../ && \
20- make && \
28+ CXX=g++ cmake \
29+ -DSKIP_TAINTED_CHECK=true \
30+ -DCMAKE_BUILD_TYPE=armv71 \
31+ -DARM64=OFF \
32+ --target raspistill \
33+ ../ && \
34+ make -j4 --output-sync=recurse && \
2135 make install
2236
23- FROM golang:alpine3.12
2437
25- RUN apk add --update --no-cache \
26- libc6-compat \
27- musl \
28- psmisc
38+ # Build the timelapse binary.
39+ FROM golang:alpine${ALPINE_VERSION} as go-build
2940
30- COPY --from=camera-binaries /opt/vc /opt/vc
31- ENV PATH="${PATH}:/opt/vc/bin"
32- ENV LD_LIBRARY_PATH="/opt/vc/lib"
41+ RUN apk add --update --no-cache \
42+ g++
3343
3444RUN mkdir /app
3545WORKDIR /app
46+
3647COPY go.* ./
3748RUN go mod download
3849
3950COPY src/ src/
4051
41- RUN go vet *.go
52+ RUN go vet src/*.go
53+ RUN go build -o timelapse src/*.go
4254
43- VOLUME /data
4455
45- CMD go run src/*.go
56+ # Build the web application image
57+ FROM alpine:${ALPINE_VERSION}
58+
59+ WORKDIR /app
60+
61+ RUN apk add --update --no-cache \
62+ libc6-compat \
63+ musl \
64+ psmisc
65+
66+ COPY --from=camera-binaries /opt/vc /opt/vc
67+ ENV PATH="${PATH}:/opt/vc/bin"
68+ ENV LD_LIBRARY_PATH="/opt/vc/lib"
69+
70+ COPY --from=go-build /app/timelapse /app
71+
72+ VOLUME /data
4673
74+ CMD ./timelapse
0 commit comments