How to build custom kernel modules

One-to-many kernels modules needs to be build in order support multiple balenaOS versions.
The below example is for usb, but can be changed to support other kernel modules.
Note: Not all modules can be loaded dynamically, see Custom ResinOS and OS update

FROM resin/intel-nuc-buildpack-deps:stretch AS kernelbuilder1

RUN apt-get update && apt-get install -y --no-install-recommends \
	    bc \
	&& rm -rf /var/lib/apt/lists/*

    KERNEL_VERSION=4.12.12 \

# tutorial from here:
# ideas from here:

RUN cd /usr/src \
    && wget${KERNEL_MAJOR_VERSION}/linux-${KERNEL_VERSION}.tar.gz \
    && tar xzf linux-${KERNEL_VERSION}.tar.gz \
    && wget${RESIN_OS_VERSION}/kernel_modules_headers.tar.gz \
    && tar xzf kernel_modules_headers.tar.gz

RUN cd /usr/src \
    && cd linux-${KERNEL_VERSION} \
    && cp ../kernel_modules_headers/.config ../kernel_modules_headers/Module.symvers . \
    && sed -i 's/# CONFIG_USB_XXX is not set/CONFIG_USB_XXX=m/g' .config \
    && make modules_prepare \
    && make M=drivers/usb \
    && make M=drivers/usb modules_install

Hi @aliasbits,

This is great!

Thank you for your effort to document this!