Skip to content

Commit

Permalink
switch to alpine based docker image
Browse files Browse the repository at this point in the history
Co-authored-by: Max Berger <[email protected]>
  • Loading branch information
StefanSchoof and maxberger committed Jan 22, 2023
1 parent 929a8d6 commit f073738
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 45 deletions.
45 changes: 45 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# docker related
.dockerignore
Dockerfile

*~

# Binaries
src/vzlogger

# directories from install.sh
libs/
build*/

# Compiled Object files
*.slo
*.lo
*.o

# Compiled Dynamic libraries
*.so
*.so.*

# Compiled Static libraries
*.lai
*.la
*.a

# automake
Makefile
.deps

# autoconf
autom4te.cache
config.status
config.log
config.h
stamp-h1
libtool

# Debian packaging
debian/config.log

# CMake temp files
CMakeFiles/
CMakeCache.txt
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Binaries
src/vzlogger

# directorys from install.sh
# directories from install.sh
libs/
build*/

Expand Down
89 changes: 45 additions & 44 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,79 +1,80 @@
ARG DEBIAN_VERSION=buster-slim

############################
# STEP 1 build executable binary
############################

FROM debian:$DEBIAN_VERSION as builder
FROM alpine:latest as builder

RUN apt-get update && apt-get install -y \
build-essential \
git-core \
RUN apk add --no-cache \
gcc \
g++ \
libc-dev \
linux-headers \
git \
make \
cmake \
pkg-config \
libcurl4-openssl-dev \
libgnutls28-dev \
libsasl2-dev \
uuid-dev \
curl-dev \
gnutls-dev \
cyrus-sasl-dev \
# for libuuid
util-linux-dev \
libtool \
libssl-dev \
libgcrypt20-dev \
libgcrypt-dev \
libmicrohttpd-dev \
libltdl-dev \
libjson-c-dev \
libleptonica-dev \
libmosquitto-dev \
json-c-dev \
mosquitto-dev \
libunistring-dev \
dh-autoreconf \
&& rm -rf /var/lib/apt/lists/*
automake \
autoconf

WORKDIR /vzlogger

RUN git clone https://github.com/volkszaehler/libsml.git --depth 1 \
&& make install -C libsml/sml
&& make install -C libsml/sml

RUN git clone https://github.com/rscada/libmbus.git --depth 1 \
&& cd libmbus \
&& ./build.sh \
&& make install
&& cd libmbus \
&& ./build.sh \
&& make install

COPY . /vzlogger

RUN cmake -DBUILD_TEST=off \
&& make \
&& make install
ARG build_test=off
RUN cmake -DBUILD_TEST=${build_test} \
&& make \
&& make install \
&& if [ "$build_test" = "on" ]; then make test; fi


#############################
## STEP 2 build a small image
#############################

FROM debian:$DEBIAN_VERSION
FROM alpine:latest

LABEL Description="vzlogger"

RUN apt-get update && apt-get install -y \
libcurl4 \
libgnutls30 \
libsasl2-2 \
libuuid1 \
libssl1.1 \
libgcrypt20 \
libmicrohttpd12 \
libltdl7 \
libatomic1 \
libjson-c3 \
liblept5 \
libmosquitto1 \
libunistring2 \
&& rm -rf /var/lib/apt/lists/*
RUN apk add --no-cache \
libcurl \
gnutls \
libsasl \
libuuid \
libgcrypt \
libmicrohttpd \
json-c \
libatomic \
mosquitto-libs \
libunistring \
libstdc++ \
libgcc

# libsml is linked statically => no need to copy
COPY --from=builder /usr/local/bin/vzlogger /usr/local/bin/vzlogger
COPY --from=builder /usr/local/lib/libmbus.so* /usr/local/lib/

# without running a user context, no exec is possible and without the dialout group no access to usb ir reader possible
RUN useradd -M -G dialout vz
USER vz
RUN adduser -S vz -G dialout

RUN vzlogger --version

USER vz
CMD ["vzlogger", "--foreground"]

0 comments on commit f073738

Please sign in to comment.