我建議使用項目的自動化安裝工具如(fabric/fabtools):安裝它們pip install fabric fabtools
在你的問題,你沒有指定你是否想在本地或在運行這些東西遠程服務器,任何方式,找到婁兩種情況:
from fabric.api import local, cd, run, env, roles
from fabric.context_managers import prefix
env.project_name = "project name"
env.repo = "your_repo.git"
REMOTEHOST = "Ip or domaine"
REMOTEUSER = "user"
REMOTEPASSWORD = "password"
env.roledefs.update({
"remote": [REMOTEHOST]
})
def remote():
"""Defines the Development Role
"""
env.user = REMOTEUSER
env.password = REMOTEPASSWORD
env.forward_agent = True # Your local machine has access, and the remote not, so you forward you identity to the
# remote, and then the remote gets access
def install_requirements(environment="local"):
"""Install the packages required by our each environment
"""
if environment == "local":
with cd("/your project/"):
with prefix("source activate {0}".format("YOUR VIRTUALENV NAME")):
run("pip install -r requirements/local.txt")
elif environment == "remote":
with cd("your project"):
with prefix("source activate {0}".format("YOUR VIRTUALENV NAME")):
run("pip install -r requirements/remote.txt")
def bootstrap_local():
"""Do your job locally
"""
env.warn_only = True
with cd("your directory"):
with prefix("source activate {0}".format("YOUR VIRTUALENV NAME")):
local("git checkout {0}".format("YOUR BRANCH"))
local("git pull origin {0}".format("YOUR BRANCH"))
install_requirements(environment="local")
local("the command line of the Application you wanna launch")
@roles('remote')
def bootstrap_remote():
"""do your job in the Remote server
"""
env.warn_only = True
remote()
with cd("your directory"):
with prefix("source activate {0}".format("YOUR VIRTUALENV NAME")):
run("git checkout {0}".format("YOUR BRANCH"))
run("git pull origin {0}".format("YOUR BRANCH"))
install_requirements(environment="remote")
run("the command line of the Application you wanna launch")
寫這個劇本變成「fabfile.py」後,從終端到該目錄caontaining此腳本:
- 運行
fab bootstrap_local
運行作業本地
- 或者運行
fab bootstrap_remote
運行作業遠程
感謝的人,我不知道這存在。 – Ominus
在這裏我做了一個非常簡單的例子,你可以用fabtools製作很多非常可愛的東西,非常簡單而且非常有效!例如:安裝和配置主管,postgrest,git操作......所有準備使用;-) –