|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# This assumes all of the OS-level configuration has been completed and git repo has already been cloned |
| 4 | +#sudo yum-config-manager --enable epel |
| 5 | +#sudo yum update -y |
| 6 | +#sudo yum install git libpng-devel libcurl-devel gcc python-devel libjpeg-devel -y |
| 7 | +#sudo pip install --upgrade pip |
| 8 | +#alias sudo='sudo env PATH=$PATH' |
| 9 | +#sudo pip install --upgrade setuptools |
| 10 | +#sudo pip install --upgrade virtualenv |
| 11 | + |
| 12 | +# This script should be run from the repo's deployment directory |
| 13 | +# cd deployment |
| 14 | +# ./build-s3-dist.sh source-bucket-base-name |
| 15 | +# source-bucket-base-name should be the base name for the S3 bucket location where the template will source the Lambda code from. |
| 16 | +# The template will append '-[region_name]' to this bucket name. |
| 17 | +# For example: ./build-s3-dist.sh solutions |
| 18 | +# The template will then expect the source code to be located in the solutions-[region_name] bucket |
| 19 | + |
| 20 | +# Check to see if input has been provided: |
| 21 | +if [ -z "$1" ]; then |
| 22 | + echo "Please provide the base source bucket name where the lambda code will eventually reside.\nFor example: ./build-s3-dist.sh solutions" |
| 23 | + exit 1 |
| 24 | +fi |
| 25 | + |
| 26 | +# Build source |
| 27 | +echo "Staring to build distribution" |
| 28 | +echo "mkdir -p dist" |
| 29 | +mkdir -p dist |
| 30 | +echo "cp -f serverless-image-handler.template dist" |
| 31 | +cp -f serverless-image-handler.template dist |
| 32 | +echo "Updating code source bucket in template with $1" |
| 33 | +replace="s/%%BUCKET_NAME%%/$1/g" |
| 34 | +echo "sed -i '' -e $replace dist/serverless-image-handler.template" |
| 35 | +sed -i '' -e $replace dist/serverless-image-handler.template |
| 36 | +cd dist |
| 37 | +pwd |
| 38 | +echo "virtualenv env" |
| 39 | +virtualenv env |
| 40 | +echo "source env/bin/activate" |
| 41 | +source env/bin/activate |
| 42 | +cd ../.. |
| 43 | +pwd |
| 44 | +echo "pip install source/. --target=$VIRTUAL_ENV/lib/python2.7/site-packages/" |
| 45 | +pip install source/. --target=$VIRTUAL_ENV/lib/python2.7/site-packages/ |
| 46 | +echo "pip install -r source/requirements.txt --target=$VIRTUAL_ENV/lib/python2.7/site-packages/" |
| 47 | +pip install -r source/requirements.txt --target=$VIRTUAL_ENV/lib/python2.7/site-packages/ |
| 48 | +cd $VIRTUAL_ENV |
| 49 | +pwd |
| 50 | +echo "git clone git://github.com/pornel/pngquant.git pngquant_s" |
| 51 | +git clone git://github.com/pornel/pngquant.git pngquant_s |
| 52 | +cd pngquant_s |
| 53 | +pwd |
| 54 | +echo "./configure --enable-static --disable-shared" |
| 55 | +./configure --enable-static --disable-shared |
| 56 | +echo "make" |
| 57 | +make |
| 58 | +echo "cp pngquant $VIRTUAL_ENV" |
| 59 | +cp -f pngquant $VIRTUAL_ENV |
| 60 | +cd $VIRTUAL_ENV/lib/python2.7/site-packages |
| 61 | +pwd |
| 62 | +echo "zip -q -r9 $VIRTUAL_ENV/../serverless-image-handler.zip *" |
| 63 | +zip -q -r9 $VIRTUAL_ENV/../serverless-image-handler.zip * |
| 64 | +cd $VIRTUAL_ENV |
| 65 | +pwd |
| 66 | +echo "zip -q -g $VIRTUAL_ENV/../serverless-image-handler.zip pngquant" |
| 67 | +zip -q -g $VIRTUAL_ENV/../serverless-image-handler.zip pngquant |
| 68 | +cd .. |
| 69 | +echo zip -d serverless-image-handler.zip botocore* |
| 70 | +zip -q -d serverless-image-handler.zip pip* |
| 71 | +zip -q -d serverless-image-handler.zip easy* |
| 72 | +echo "Clean up build material" |
| 73 | +rm -rf $VIRTUAL_ENV |
| 74 | +echo "Completed building distribution" |
0 commit comments