Commit 2470bf960ee10d2d6bdee3f1fa0c7333db000ca1
1 parent
188e1d3d
Exists in
master
and in
39 other branches
Adding multi-distribuition support
Showing
1 changed file
with
28 additions
and
8 deletions
Show diff stats
fabfile.py
@@ -9,6 +9,16 @@ from fabric.api import env, run, sudo, local | @@ -9,6 +9,16 @@ from fabric.api import env, run, sudo, local | ||
9 | from fabric.contrib.files import exists | 9 | from fabric.contrib.files import exists |
10 | from fabric.context_managers import prefix, cd, settings, shell_env | 10 | from fabric.context_managers import prefix, cd, settings, shell_env |
11 | 11 | ||
12 | +LINUX_DISTRO = 'Debian' | ||
13 | +DISTRO_CMD = {'Debian': { | ||
14 | + 'install': 'apt-get install', | ||
15 | + 'update': 'apt-get update', | ||
16 | + }, | ||
17 | + 'CentOS': { | ||
18 | + 'install': 'yum install', | ||
19 | + 'install': 'yum update -y', | ||
20 | + } | ||
21 | + } | ||
12 | 22 | ||
13 | APP_USER = APP_NAME = VENV_NAME = 'colab' | 23 | APP_USER = APP_NAME = VENV_NAME = 'colab' |
14 | REPO_URL = 'git@github.com:colab-community/colab.git' | 24 | REPO_URL = 'git@github.com:colab-community/colab.git' |
@@ -35,6 +45,15 @@ MANAGE_PATH = os.path.join(REPO_PATH, 'src') | @@ -35,6 +45,15 @@ MANAGE_PATH = os.path.join(REPO_PATH, 'src') | ||
35 | SETTINGS_PATH = os.path.join(MANAGE_PATH, APP_NAME) | 45 | SETTINGS_PATH = os.path.join(MANAGE_PATH, APP_NAME) |
36 | 46 | ||
37 | 47 | ||
48 | +def get_distro(): | ||
49 | + global LINUX_DISTRO | ||
50 | + linux_name = run('python -c "import platform; print platform.dist()[0]"') | ||
51 | + | ||
52 | + if 'Ubuntu' in linux_name or 'Debian' in linux_name: | ||
53 | + LINUX_DISTRO = 'Debian' | ||
54 | + elif 'centos' in linux_name: | ||
55 | + LINUX_DISTRO = 'CentOS' | ||
56 | + | ||
38 | @task | 57 | @task |
39 | def environment(name=DEFAULT_ENVIRONMENT): | 58 | def environment(name=DEFAULT_ENVIRONMENT): |
40 | """Set the environment where the tasks will be executed""" | 59 | """Set the environment where the tasks will be executed""" |
@@ -53,12 +72,9 @@ def environment(name=DEFAULT_ENVIRONMENT): | @@ -53,12 +72,9 @@ def environment(name=DEFAULT_ENVIRONMENT): | ||
53 | 72 | ||
54 | env.update(environments[name]) | 73 | env.update(environments[name]) |
55 | env.environment = name | 74 | env.environment = name |
56 | -environment() | ||
57 | - | ||
58 | - | ||
59 | -def aptget_install(pkg): | ||
60 | - sudo('DEBIAN_FRONTEND=noninteractive apt-get install -y -q {}'.format(pkg)) | ||
61 | 75 | ||
76 | +def package_install(pkg): | ||
77 | + sudo(DISTRO_CMD[LINUX_DISTRO]['install'] + ' ' + pkg + ' -y -q') | ||
62 | 78 | ||
63 | def install_requirements(): | 79 | def install_requirements(): |
64 | with cd(REPO_PATH), prefix(WORKON_ENV): | 80 | with cd(REPO_PATH), prefix(WORKON_ENV): |
@@ -130,11 +146,12 @@ def update_code(): | @@ -130,11 +146,12 @@ def update_code(): | ||
130 | @task | 146 | @task |
131 | def bootstrap(): | 147 | def bootstrap(): |
132 | """Bootstrap machine to run fabric tasks""" | 148 | """Bootstrap machine to run fabric tasks""" |
133 | - | ||
134 | with settings(user=env.superuser): | 149 | with settings(user=env.superuser): |
135 | 150 | ||
136 | - if not exists('/usr/bin/git'): | ||
137 | - aptget_install('git') | 151 | + sudo(DISTRO_CMD[LINUX_DISTRO]['update']) |
152 | + | ||
153 | + if not exists('/usr/bin/git'): | ||
154 | + package_install('git-core') | ||
138 | 155 | ||
139 | if env.is_vagrant: | 156 | if env.is_vagrant: |
140 | groups = 'sudo,vagrant' | 157 | groups = 'sudo,vagrant' |
@@ -222,3 +239,6 @@ def deploy(noprovision=False): | @@ -222,3 +239,6 @@ def deploy(noprovision=False): | ||
222 | migrate() | 239 | migrate() |
223 | 240 | ||
224 | sudo('supervisorctl start all') | 241 | sudo('supervisorctl start all') |
242 | + | ||
243 | +# Main | ||
244 | +environment() |