Install statically linked jq and cifs-utils

- Create static binaries using staticx from pypi
- Copy onto k8s node in daemonset when INSTALL_DEPS docker arg is true
This commit is contained in:
Seth Nickell 2020-04-27 23:57:38 -10:00
Родитель acae4f3963
Коммит fea2d57483
4 изменённых файлов: 40 добавлений и 70 удалений

Просмотреть файл

@ -1,4 +1,32 @@
###################################################
FROM python:slim as statically-linked-deps
###################################################
ARG INSTALL_DEPS=true
ENV SOURCE_DIR="/install-bin"
RUN \
mkdir -p ${SOURCE_DIR} && \
apt-get update && \
apt-get install --no-install-recommends -y \
binutils \
cifs-utils \
jq \
patchelf \
&& \
apt-get clean && \
pip3 install --no-cache-dir staticx && \
staticx `which mount.cifs` ${SOURCE_DIR}/mount.cifs && \
staticx `which jq` ${SOURCE_DIR}/jq
###################################################
FROM busybox
###################################################
ARG INSTALL_DEPS=false
ENV INSTALL_DEPS="$INSTALL_DEPS"
ENV SOURCE_DIR="/install-bin"
COPY --from=statically-linked-deps ${SOURCE_DIR} ${SOURCE_DIR}
ADD ./smb /bin/smb
ADD ./install.sh /bin/install_smb_flexvol.sh

Просмотреть файл

@ -13,6 +13,14 @@ fi
smb_vol_dir="${target_dir}/microsoft.com~smb"
mkdir -p ${smb_vol_dir} >> $LOG 2>&1
if [ "$INSTALL_DEPS" = true ] ; then
echo "installing statically linked dependencies (jq, cifs-utils)" >> $LOG
# copy any other static deps
cp ${SOURCE_DIR}/* ${smb_vol_dir} >> $LOG 2>&1
else
echo "skipping installing deps: jq and cifs-utils must be pre-installed" >> $LOG
fi
#copy smb script
cp /bin/smb ${smb_vol_dir}/smb >> $LOG 2>&1
chmod a+x ${smb_vol_dir}/smb >> $LOG 2>&1

Просмотреть файл

@ -4,7 +4,8 @@
# - Please install "jq" package before using this driver.
DIR=$(dirname "$(readlink -f "$0")")
JQ="/usr/bin/jq"
JQ="${DIR}/jq" && [[ -f ${JQ} ]] || JQ="/usr/bin/jq"
MOUNT_CIFS="${DIR}/mount.cifs" && [[ -f ${MOUNT_CIFS} ]] || MOUNT_CIFS="/usr/sbin/mount.cifs"
LOG="/var/log/smb-driver.log"
VER="1.0.2"
@ -60,9 +61,9 @@ mount() {
mkdir -p ${MNTPATH} >>$LOG 2>&1
#mounting
echo "`date` EXEC: /bin/mount -t cifs ${VOLUME_SRC} ${MNTPATH}" >>$LOG
echo "`date` EXEC: ${MOUNT_CIFS} ${VOLUME_SRC} ${MNTPATH}" >>$LOG
/bin/mount -t cifs "${VOLUME_SRC}" "${MNTPATH}" -o "${ALL_OPTIONS}" >>$LOG 2>&1
"${MOUNT_CIFS}" "${VOLUME_SRC}" "${MNTPATH}" -o "${ALL_OPTIONS}" >>$LOG 2>&1
if [ $? -ne 0 ]; then
errorLog=`tail -n 1 "${LOG}"`
err "{ \"status\": \"Failure\", \"message\": \"Failed to mount device ${DMDEV} at ${MNTPATH}, user:${USERNAME}, ${VOLUME_SRC}, error log:${errorLog}\" }"

Просмотреть файл

@ -1,67 +0,0 @@
# This image builds statically linked versions of 'jq' and 'cifs-utils'
FROM debian:stable as build-static-link-deps
ENV BUILD_DIR="/build"
# Build statically linked debs
ENV DEB_CFLAGS_PREPEND="-static"
ENV DEB_LDFLAGS_PREPEND="-static"
ENV DEB_CPPFLAGS_PREPEND="-static"
ENV DEB_CXXFLAGS_PREPEND="-static"
ENV DEB_BUILD_OPTIONS="nocheck"
#ENV LIBTOOLFLAGS="-all-static"
# Setup debian for doing package builds
RUN \
apt-get update && \
apt-get install --no-install-recommends -y \
build-essential \
devscripts \
dpatch \
equivs \
fakeroot \
# TODO: delete
less \
lintian \
# TODO: delete
nano \
quilt \
&& \
apt-get clean
# Get debian package source for jq & cifs-utils
RUN \
echo '\
deb-src http://deb.debian.org/debian stable main\n \
deb-src http://security.debian.org/debian-security stable/updates main\n \
' >> /etc/apt/sources.list \
&& \
apt update && \
mkdir -p $BUILD_DIR && \
cd $BUILD_DIR && \
apt source \
jq \
cifs-utils \
&& \
yes | mk-build-deps -i -r \
jq \
cifs-utils \
&& \
apt-get clean
# Build cifs-utils deb
RUN \
cd $BUILD_DIR/cifs-utils-* && \
fakeroot debian/rules binary && \
cd .. && \
dpkg -i cifs-utils_*deb
# Build jq deb
RUN \
printf "override_dh_auto_configure:\n\tdh_auto_configure -- --enable-all-static" >> debian/rules && \
cd $BUILD_DIR/jq-* && \
DEB_CONFIGURE_EXTRA_FLAGS="--enable-all-static" \
fakeroot debian/rules binary
# TODO: now copy them onto the target?