-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dockerfile to build a buildroot-based cross-compile environment for v…
…zlogger
- Loading branch information
Showing
1 changed file
with
175 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
# Dockerfile to build a buildroot-based cross-compile environment for vzlogger | ||
|
||
# the OS version used here is largely irrelevant, | ||
# as buildroot compiles it's own toolchain | ||
FROM debian:buster as builder | ||
|
||
LABEL maintainer="Thorben T. <r00t@constancy.org>" | ||
|
||
# don't inherit upstream labels | ||
LABEL org.label-schema.build-date=null | ||
LABEL org.label-schema.license=null | ||
LABEL org.label-schema.name=null | ||
LABEL org.label-schema.schema-version=null | ||
LABEL org.label-schema.vendor=null | ||
|
||
# update host-OS and install required host packages | ||
# (we should optimize by using a base image that already contains this.) | ||
RUN set -xe ; \ | ||
apt-get update ; \ | ||
apt-get -y --force-yes upgrade ; \ | ||
apt-get -y --force-yes install \ | ||
# https://buildroot.org/downloads/manual/manual.html#requirement | ||
make gcc g++ \ | ||
patch \ | ||
bzip2 \ | ||
cpio \ | ||
unzip \ | ||
rsync \ | ||
file \ | ||
bc \ | ||
#libncurses-dev \ | ||
wget \ | ||
git \ | ||
; \ | ||
apt-get purge ; \ | ||
rm -fr /var/lib/apt/lists | ||
|
||
WORKDIR /buildroot | ||
|
||
RUN \ | ||
set -xe ; \ | ||
\ | ||
# download and unpack buildroot | ||
wget --progress=dot:mega https://buildroot.org/downloads/buildroot-2021.02.1.tar.bz2 ; \ | ||
tar xj --strip-components=1 <buildroot-2021.02.1.tar.bz2 ; \ | ||
rm buildroot-2021.02.1.tar.bz2 ; \ | ||
\ | ||
# create vzlogger package configuration | ||
mkdir -p package/vzlogger ; \ | ||
echo 'config BR2_PACKAGE_VZLOGGER' >>package/vzlogger/Config.in ; \ | ||
echo 'bool "vzlogger"' >>package/vzlogger/Config.in ; \ | ||
echo 'help' >>package/vzlogger/Config.in ; \ | ||
echo ' vzlogger' >>package/vzlogger/Config.in ; \ | ||
# have the package pull in vzlogger's deps | ||
echo 'select BR2_TOOLCHAIN_BUILDROOT_CXX' >>package/vzlogger/Config.in ; \ | ||
echo 'select BR2_PACKAGE_UTIL_LINUX' >>package/vzlogger/Config.in ; \ | ||
echo 'select BR2_PACKAGE_UTIL_LINUX_LIBUUID' >>package/vzlogger/Config.in ; \ | ||
echo 'select BR2_PACKAGE_OPENSSL' >>package/vzlogger/Config.in ; \ | ||
echo 'select BR2_PACKAGE_ZLIB' >>package/vzlogger/Config.in ; \ | ||
echo 'select BR2_PACKAGE_LIBZLIB' >>package/vzlogger/Config.in ; \ | ||
echo 'select BR2_PACKAGE_LIBOPENSSL' >>package/vzlogger/Config.in ; \ | ||
echo 'select BR2_PACKAGE_LIBCURL' >>package/vzlogger/Config.in ; \ | ||
echo 'select BR2_PACKAGE_LIBCURL_OPENSSL' >>package/vzlogger/Config.in ; \ | ||
\ | ||
echo 'VZLOGGER_SITE = https://github.com/volkszaehler/vzlogger.git' >>package/vzlogger/vzlogger.mk ; \ | ||
echo 'VZLOGGER_SITE_METHOD = git' >>package/vzlogger/vzlogger.mk ; \ | ||
echo 'VZLOGGER_GIT_SUBMODULES = NO' >>package/vzlogger/vzlogger.mk ; \ | ||
# this is a hack, it only works if we delete the cache in dl/vzlogger/git before building, | ||
echo 'VZLOGGER_VERSION = origin/master' >>package/vzlogger/vzlogger.mk ; \ | ||
echo 'VZLOGGER_DEPENDENCIES = libgcrypt libunistring json-c libmicrohttpd util-linux libcurl' >>package/vzlogger/vzlogger.mk ; \ | ||
echo 'VZLOGGER_CONF_OPTS = -DENABLE_SML=Off -DENABLE_OMS=Off' >>package/vzlogger/vzlogger.mk ; \ | ||
echo '$(eval $(cmake-package))' >>package/vzlogger/vzlogger.mk ; \ | ||
\ | ||
# add vzlogger package to buildroot | ||
sed -i '1a source "package/vzlogger/Config.in"' package/Config.in ; \ | ||
\ | ||
# create a minimal buildroot system configuration | ||
head --lines 6 configs/raspberrypi2_defconfig >.config ; \ | ||
# WCHAR support is needed at least for libunistring | ||
echo BR2_TOOLCHAIN_BUILDROOT_WCHAR=y >>.config ; \ | ||
# we can disable these as we never build an OS image | ||
echo BR2_INIT_NONE=y >>.config ; \ | ||
echo BR2_SYSTEM_BIN_SH_NONE=y >>.config ; \ | ||
echo "# BR2_TARGET_ROOTFS_TAR is not set" >>.config ; \ | ||
\ | ||
# enable our vzlogger package | ||
echo BR2_PACKAGE_VZLOGGER=y >>.config ; \ | ||
\ | ||
# calculate full config based on above settings | ||
make olddefconfig ; \ | ||
\ | ||
# sanity check to ensure config was applied correcly | ||
grep -q BR2_PACKAGE_VZLOGGER=y .config ; \ | ||
grep -q BR2_TOOLCHAIN_BUILDROOT_WCHAR=y .config | ||
|
||
# install a helper for neatly formatted build output | ||
RUN \ | ||
set -xe ; \ | ||
( \ | ||
echo '#!/bin/bash' ;\ | ||
echo 'f=/tmp/br_make_wrapper.$$' ; \ | ||
echo 'trap "rm -f $f" EXIT' ; \ | ||
echo 'echo "=== make $@ ===" >&2' ; \ | ||
echo 'make "$@" &> >(tee "$f" | grep --line-buffered ">>>") || {' ; \ | ||
echo ' e=$?' ; \ | ||
echo ' cat "$f" >&2' ; \ | ||
echo ' exit $e' ; \ | ||
echo '}' ; \ | ||
) >br_make_wrapper.bash ; \ | ||
chmod +x br_make_wrapper.bash | ||
|
||
# download required sources | ||
RUN ./br_make_wrapper.bash source | ||
|
||
# build toolchain | ||
RUN ./br_make_wrapper.bash toolchain | ||
|
||
# WIP: we could package the toolchain, but seems pointless with docker | ||
#RUN ./br_make_wrapper.bash sdk | ||
#RUN ls -l buildroot/output/images/*_sdk-buildroot.tar.gz | ||
|
||
# build deps of vzlogger | ||
# (this will also download vzlogger source, which we delete again) | ||
RUN ./br_make_wrapper.bash vzlogger-depends && rm -fr dl/vzlogger output/build/vzlogger-* | ||
|
||
# this stuff is not needed anymore | ||
# (but we need to keep the .stamp files inside the directories) | ||
RUN rm -fr dl output/build/*/* && du -chx . | sort -h | tail -n 30 ; ( du -sh / 2>/dev/null || true ) | ||
|
||
# ensure build works | ||
#RUN \ | ||
# set -xe ; \ | ||
# ./br_make_wrapper.bash vzlogger-build ;\ | ||
# file output/build/vzlogger-*/src/vzlogger ; \ | ||
# ls -l output/build/vzlogger-*/src/vzlogger ; \ | ||
# rm -fr dl/vzlogger output/build/vzlogger-* | ||
|
||
FROM debian:buster | ||
|
||
COPY --from=builder /buildroot /buildroot | ||
|
||
WORKDIR /buildroot | ||
|
||
# disable buildroot's dependency check | ||
# we install a minimal set of host-software that works for building vzlogger, | ||
# other buildroot operations will be broken, but we don't need them | ||
RUN ln -sf /bin/true support/dependencies/dependencies.sh | ||
|
||
# docker-COPY-ing the buildroot tree clobbers some timestamp, | ||
# making buildroot want to run `make syncconfig`, which would requite gcc. | ||
# this prevents this | ||
RUN touch output/build/buildroot-config/auto.conf | ||
|
||
RUN set -xe ; \ | ||
apt-get update ; \ | ||
# apt-get -y --force-yes upgrade ; \ | ||
apt-get -y --force-yes install \ | ||
# these are required to run a vzlogger build | ||
make \ | ||
rsync \ | ||
git \ | ||
# only for showing the type of the binary below | ||
file \ | ||
; \ | ||
apt-get purge ; \ | ||
rm -fr /var/lib/apt/lists | ||
|
||
# ensure build works (also usage example for final image) | ||
RUN \ | ||
set -xe ; \ | ||
./br_make_wrapper.bash vzlogger-build ;\ | ||
file output/build/vzlogger-*/src/vzlogger ; \ | ||
ls -l output/build/vzlogger-*/src/vzlogger ; \ | ||
rm -fr dl/vzlogger output/build/vzlogger-* | ||
|