Created
March 4, 2019 18:06
-
-
Save vladimirsavenkov/5795f155fd7493c40b067f0c2d3e295b to your computer and use it in GitHub Desktop.
build-bash-lambda-layer.sh
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
#!/usr/bin/env bash | |
# This script is supposed to be executed in docker container, for example like this: | |
# docker run -it --rm -v $DIR:/var/layer --entrypoint /var/layer/builder.sh lambci/lambda:build-python2.7 | |
set -e # exit if any command fails | |
set -u # prevent using an undefined variable | |
set -x # show executed commands | |
set -o pipefail # force pipelines to fail on the first non-zero status | |
echo "Building H24 Lambda bash layer..." | |
BUILD_PATH="/var/layer" | |
echo "Creating dir structure..." | |
rm -rf $BUILD_PATH/bin $BUILD_PATH/lib | |
mkdir $BUILD_PATH/bin $BUILD_PATH/lib | |
echo "...done" | |
echo "Rebuilding SSH with lambda patch..." | |
#find /usr ! -type d | sort > fs.txt && \ | |
# yum reinstall -y openssl openssh-clients && \ | |
# bash -c 'comm -13 fs.txt <(find /usr ! -type d | sort)' | \ | |
# grep -v ^/usr/share | \ | |
# tar -c -T - | \ | |
# tar -x --strip-components=1 -C /opt && \ | |
# cp -R /opt/lib64 $BUILD_PATH/lib | |
yum install -y --releasever=latest yum-utils rpm-build && \ | |
yumdownloader --source openssh && \ | |
yum-builddep -y openssh && \ | |
rpm -ivh *.rpm | |
cp ${BUILD_PATH}/ssh/openssh-6.6p1-privend.patch /usr/src/rpm/SOURCES/ | |
cd /usr/src/rpm/SPECS && \ | |
patch openssh.spec < ${BUILD_PATH}/ssh/openssh.spec.patch && \ | |
rpmbuild -bi openssh.spec && \ | |
cp /usr/src/rpm/BUILDROOT/openssh*/usr/bin/ssh $BUILD_PATH/bin/ | |
echo "...done" | |
echo "Installing Poppler for pdfunite..." | |
yum -y install poppler poppler-utils | |
echo "...done" | |
echo "Copying bin tools..." | |
cp /usr/bin/sftp $BUILD_PATH/bin/ | |
cp `which pdfunite` $BUILD_PATH/bin/ | |
cp `which scp` $BUILD_PATH/bin/ | |
echo "...done" | |
echo "Copying libs..." | |
readelf -d `which sftp` | grep "Shared library" | cut -d "[" -f2 | cut -d "]" -f1 | xargs whereis | sed "s/.* //g" | xargs -I {} cp -L {} $BUILD_PATH/lib/ | |
readelf -d `which pdfunite` | grep "Shared library" | cut -d "[" -f2 | cut -d "]" -f1 | xargs whereis | sed "s/.* //g" | xargs -I {} cp -L {} $BUILD_PATH/lib/ | |
readelf -d `which ssh` | grep "Shared library" | cut -d "[" -f2 | cut -d "]" -f1 | xargs whereis | sed "s/.* //g" | xargs -I {} cp -L {} $BUILD_PATH/lib/ | |
readelf -d `which scp` | grep "Shared library" | cut -d "[" -f2 | cut -d "]" -f1 | xargs whereis | sed "s/.* //g" | xargs -I {} cp -L {} $BUILD_PATH/lib/ | |
echo "...done" | |
echo "Install aws cli..." | |
tmpdir=$(mktemp -d /tmp/lambda-XXXXXX) | |
virtualenv=$tmpdir/virtual-env | |
( | |
virtualenv $virtualenv | |
source $virtualenv/bin/activate | |
pip install --ignore-installed awscli boto3 | |
) | |
# "aws" command (fixing shabang line) | |
cp $virtualenv/bin/aws $BUILD_PATH/bin/ | |
perl -pi -e '$_ ="#!/usr/bin/python\n" if $. == 1' $BUILD_PATH/bin/aws | |
# aws-cli package requirements | |
cp -R $virtualenv/lib/python2.7/site-packages/* $BUILD_PATH/bin/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Awesome work, do you run this as a lambda layer?