-
Notifications
You must be signed in to change notification settings - Fork 10
/
Dockerfile
86 lines (66 loc) · 3.37 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
FROM alpine:3.10.3 AS builder
# Build arguments
ARG LIBELL_VERSION=0.18
ARG JSONC_VERSION=0.14-20200419
ARG RABBITMQC_VERSION=v0.10.0
ARG KNOT_CLOUD_SDK_VERSION=1bdb2dd
ARG KNOT_PROTOCOL_VERSION=ead9e66
ARG LIBMODBUS_VERSION=3.1.4
WORKDIR /usr/local
# Install dependencies
RUN apk update && apk add --no-cache make gcc autoconf libtool automake pkgconfig wget file musl-dev linux-headers cmake openssl-dev git
# Install libell
RUN mkdir -p /usr/local/ell
RUN wget -q -O- https://mirrors.edge.kernel.org/pub/linux/libs/ell/ell-$LIBELL_VERSION.tar.gz | tar xz -C /usr/local/ell --strip-components=1
RUN cd ell && ./configure --prefix=/usr && make install
# Install json-c dependency
RUN mkdir -p /usr/local/json-c
RUN wget -q -O- https://github.com/json-c/json-c/archive/json-c-$JSONC_VERSION.tar.gz | tar xz -C /usr/local/json-c --strip-components=1
RUN mkdir -p json-c/build && cd json-c/build && cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_INSTALL_LIBDIR=lib .. && make && make install
# Install librabbitmq-c
RUN mkdir -p /usr/local/rabbitmq-c
RUN wget -q -O- https://github.com/alanxz/rabbitmq-c/archive/$RABBITMQC_VERSION.tar.gz | tar xz -C /usr/local/rabbitmq-c --strip-components=1
RUN cd rabbitmq-c && mkdir build && cd build && cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_INSTALL_LIBDIR=lib .. && make install
# Install knot-protocol
RUN mkdir -p /usr/local/knot-protocol
RUN git clone https://github.com/CESARBR/knot-protocol-source.git /usr/local/knot-protocol
RUN cd knot-protocol && git checkout $KNOT_PROTOCOL_VERSION && ./bootstrap-configure && make install
# Install knot-cloud-sdk-c
RUN mkdir -p /usr/local/knot-cloud-sdk-c
RUN git clone https://github.com/CESARBR/knot-cloud-sdk-c.git /usr/local/knot-cloud-sdk-c
RUN cd knot-cloud-sdk-c && git checkout $KNOT_CLOUD_SDK_VERSION && ./bootstrap-configure && make install
# Install libmodbus dependency
RUN mkdir -p /usr/local/libmodbus
RUN wget -q -O- https://libmodbus.org/releases/libmodbus-$LIBMODBUS_VERSION.tar.gz | tar xz -C /usr/local/libmodbus --strip-components=1
RUN cd libmodbus && ./configure --prefix=/usr -q && make install
# Copy files to source
COPY ./ ./
# Generate Makefile
RUN PKG_CONFIG_PATH=/usr/lib64/pkgconfig ./bootstrap-configure
# Build
RUN make install
# Copy files from builder
FROM alpine:3.10.3
ENV CRED_CONF_PATH /etc/knot/credentials.conf
ENV DEV_CONF_PATH /etc/knot/device.conf
ENV CLOUD_CONF_PATH /etc/knot/cloud.conf
WORKDIR /usr/local
# Copy shared files .so from builder to target image
COPY --from=builder /usr/lib/libell.so* /usr/lib/
COPY --from=builder /usr/lib/libjson-c.so* /usr/lib/
COPY --from=builder /usr/lib/librabbitmq.so* /usr/lib/
COPY --from=builder /usr/lib/librabbitmq.a* /usr/lib/
COPY --from=builder /usr/lib/libknotprotocol.a* /usr/lib/
COPY --from=builder /usr/lib/libknotprotocol.so* /usr/lib/
COPY --from=builder /usr/lib/libknotcloudsdkc.a* /usr/lib/
COPY --from=builder /usr/lib/libknotcloudsdkc.so* /usr/lib/
COPY --from=builder /usr/lib/libmodbus.so* /usr/lib/
COPY --from=builder /usr/lib/libmodbus.la* /usr/lib/
# Copy binary executables
COPY --from=builder /usr/local/src/thingd /usr/bin/thingd
# Copy configuration files
COPY --from=builder /usr/local/confs/credentials.conf $CRED_CONF_PATH
COPY --from=builder /usr/local/confs/device.conf $DEV_CONF_PATH
COPY --from=builder /usr/local/confs/cloud.conf $CLOUD_CONF_PATH
# Run
CMD (thingd -n -c $CRED_CONF_PATH -d $DEV_CONF_PATH -p $CLOUD_CONF_PATH)