以编译使用django框架的web服务为例,编译脚本如下:
#!/bin/bash
#wrote by shlian at 2019.04.11
echo "********************initializ..."
rm -rf webserver
cp -rf ../webserver .
rm -rf webserver/logs/*
echo "********************initialized"
echo "********************compiling......"
python3 -O -m compileall -b webserver #这是编译的关键
if [ $? -ne 0 ] ; then
echo -e "\n**************************************************"
echo "* python error ,please use virtualenv or python3 *"
echo -e "**************************************************\n"
exit $?
fi
echo "********************compiled"
echo "!!!!!!!!!!!!!!!!!!!!deleting files......"
rm -rf webserver/manage.py
rm -rf webserver/uwsgi.status
rm -rf webserver/uwsgi.pid
find webserver/web/ -name "*.py"|xargs rm -rf
find webserver -name "__pycache__"|xargs rm -rf
find webserver -name ".gitkeep"|xargs rm -rf
find webserver/webserver -name "*.py"|grep -v 'settings.py\|wsgi.py'|xargs rm -rf
echo "!!!!!!!!!!!!!!!!!!!!deleted"
echo "********************taring...."
branch_name=$(git branch) #git的分支信息
branch_name=${branch_name##* }
version_info=$(git describe) #git的描述信息
time_stamp=`date +%Y%m%d%H%M%S`
echo $branch_name >webserver/version
echo $version_info>>webserver/version
echo $time_stamp>>webserver/version
tar -czvf mms_"$branch_name"_"$version_info".tar.gz ./webserver #打包
if [ $? -ne 0 ] ; then
echo "tar is error"
exit $?
fi
rm -rf webserver/
echo "done!!!"