我有一个Java应用程序,它应该与远程机器上安装的Python代理进行交互。我的主应用程序具有对这些远程计算机的SSH访问权限。为了简化用户的工作,我希望自动化代理安装过程,这样用户只需按下按钮,主应用程序就可以远程连接,安装和运行应用程序。
我希望:
我的Python代理使用virtualenv和pip,有许多依赖项。我已经制作了一个脚本来下载virtualenv和依赖项作为tar.gz / zip:
#!/usr/bin/env bash
# Should be the same in dist.sh and install_dist.sh.
VIRTUALENV_VERSION=13.0.3
VIRTUALENV_BASE_URL=https://pypi.python.org/packages/source/v/virtualenv
echo "Recreating dist directory..."
if [ -d "dist" ]; then
rm -rf dist
fi
mkdir -p dist
echo "Copying agent sources..."
cp -r src dist
cp requirements.txt dist
cp agent.sh dist
cp install_dist.sh dist
echo "Downloading virtualenv..."
curl -o dist/virtualenv-$VIRTUALENV_VERSION.tar.gz -O $VIRTUALENV_BASE_URL/virtualenv-$VIRTUALENV_VERSION.tar.gz
echo "Downloading requirements..."
mkdir dist/libs
./env/bin/pip install --download="dist/libs" --no-binary :all: -r requirements.txt
echo "Packing dist directory..."
tar cvzf dist.tar.gz dist
安装开始时,我的主应用程序将所有这些存档scp到远程机器,安装virtualenv和要求,复制所有必需的脚本:
#!/usr/bin/env bash
# Runs remotely.
SCRIPT_DIR="`dirname \"$0\"`"
SCRIPT_DIR="`( cd \"$SCRIPT_DIR\" && pwd )`"
HOME_DIR="`( cd \"$SCRIPT_DIR/..\" && pwd )`"
VIRTUALENV_VERSION=13.0.3
echo "Installing virtualenv..."
tar xzf $SCRIPT_DIR/virtualenv-$VIRTUALENV_VERSION.tar.gz --directory $SCRIPT_DIR
python $SCRIPT_DIR/virtualenv-$VIRTUALENV_VERSION/virtualenv.py $HOME_DIR/env
if [ $? -ne 0 ]
then
echo "Unable to create virtualenv."
exit 1
fi
$HOME_DIR/env/bin/pip install $SCRIPT_DIR/virtualenv-$VIRTUALENV_VERSION.tar.gz
if [ $? -ne 0 ]
then
echo "Unable to install virtualenv."
exit 1
fi
echo "Installing requirements..."
$HOME_DIR/env/bin/pip install --no-index --find-links="$SCRIPT_DIR/libs" -r $SCRIPT_DIR/requirements.txt
if [ $? -ne 0 ]
then
echo "Unable to install requirements."
exit 1
fi
echo "Copying agent sources..."
cp -r $SCRIPT_DIR/src $HOME_DIR
if [ $? -ne 0 ]
then
echo "Unable to copy agent sources."
exit 1
fi
cp -r $SCRIPT_DIR/agent.sh $HOME_DIR
if [ $? -ne 0 ]
then
echo "Unable to copy agent.sh."
exit 1
fi
cp -r $SCRIPT_DIR/requirements.txt $HOME_DIR
echo "Cleaning installation files..."
rm -rf $HOME_DIR/dist.tar.gz
rm -rf $SCRIPT_DIR
我遇到了远程构建一些依赖项的问题 - 例如,它们可能需要gcc或其他应该手动安装sudo的库...可能是,我应该尽可能使用预编译的轮子,提供它们每个目标系统?或者你可能看到一些更好的方法来实现这个任务?