Skip to content

Commit 2e9bbfd

Browse files
author
Sam Cook
committed
Add task to blank bundler config
If the gemstash server fails then bundler won't automatically failover (due to the age of some versions of bundler). In order to continue deploiying if the gemstash server is unavailable (and can't be brought back up) we can remove the configuration that says to use the server and return to using the default values (i.e. rubygems). This adds a task that will lock puppet on the targeted machine then empty the bundler config file.
1 parent 1627512 commit 2e9bbfd

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

bundler.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from os.path import join
2+
from fabric.api import sudo, task
3+
from fabric.utils import error
4+
import fabric.contrib.files
5+
6+
import puppet
7+
8+
config_file_locations = [
9+
'/home/deploy',
10+
'/var/lib/jenkins'
11+
]
12+
13+
config_file_suffix = '.bundle/config'
14+
15+
16+
def get_bundler_config():
17+
for prefix in config_file_locations:
18+
location = join(prefix, config_file_suffix)
19+
if fabric.contrib.files.exists(location, use_sudo=True):
20+
return location
21+
22+
error('Could not find bundler config file.')
23+
24+
25+
@task
26+
def failover_to_rubygems():
27+
"""Change bundler to use rubygems.org for gems rather than gemstash"""
28+
bundler_config = get_bundler_config()
29+
puppet.disable('Fabric failover_to_rubygems invoked')
30+
# Overwrite the bundler config with an empty file to force failover to default
31+
# Use an empty file rather than rm to avoid running rm as sudo.
32+
sudo('echo "" > {0}'.format(bundler_config))
33+
print('Disabled puppet and overwritten the bundler config file.')
34+
print('Run "bundler.revert_mirror" to start using gemstash again.')
35+
36+
37+
@task
38+
def revert_mirror():
39+
puppet.enable()
40+
puppet.agent()
41+
get_bundler_config()
42+
print('Puppet has been re-enabled. The bundler config file should be in it\'s usual state.')

fabfile.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
# Our command submodules
2121
import app
2222
import apt
23+
import bundler
2324
import cache
2425
import campaigns
2526
import cdn

0 commit comments

Comments
 (0)