Constructs a tagged docker image name from a Docker image name and an optional tag.
dockerImageName(str): Name of the Docker image in namespace/image format
dockerImageTag(str, optional): Optional tag of the Docker image
A Fabric task which runs locally; it does the following:
1. clones a given git repository to a local temporary directory and checks out the branch supplied
2. If the performGitCryptInit argument is True, runs git-crypt init to decrypt the files
3. builds a Docker image using the Dockerfile in the relativeDockerfileDirInGitRepo directory of the git repository. The Docker image is tagged (details are in the docstring for the dockerImageTag parameter).
NOTE: This Fabric task is only run once regardless of the number of hosts/roles you supply.
dockerImageName(str): Name of the Docker image in namespace/image format
A Fabric task which runs locally; it pushes a local Docker image with a given tag to the Docker registry (http://index.docker.io).
NOTE: This Fabric task is only run once regardless of the number of hosts/roles you supply.
dockerImageName(str): Name of the Docker image in namespace/image format
A Fabric task which runs locally; it builds a Docker image from a git repository and pushes it to the Docker registry (http://index.docker.io). This task runs the build_docker_image_from_git_repo task followed by the push_docker_image_to_registry task.
NOTE: This Fabric task is only run once regardless of the number of hosts/roles you supply.
Pulls a tagged Docker image from the Docker registry.
Rationale: While a docker run command for a missing image will pull the image from the Docker registry, it requires any running Docker container with the same name to be stopped before the newly pulled Docker container eventually runs. This usually means stopping any running Docker container with the same name before a time consuming docker pull. Pulling the desired Docker image before a docker stop docker run will minimize the downtime of the Docker container.
dockerImageName(str): Name of the Docker image in namespace/image format
cmdString(str): Command to run
“stdout”: list(str) if captureStdout==True, None otherwise
“stderr”: list(str) if captureStderr==True, None otherwise
>>> run_and_get_output("ls")
{ "stdout": ["LICENSE", "README.md", "setup.py"], "stderr": [] }
Runs a command and grabs its output from standard output, without all the Fabric associated stuff and other crap (hopefully).
cmdString(str): Command to run
>>> run_and_get_stdout("ls")
["LICENSE", "README.md", "setup.py"]
Returns the home directory for the current user of a given server.
>>> get_home_dir()
"/home/ubuntu"
Downloads a file from a server to a tempfile.NamedTemporaryFile.
NOTE: This function calls the close method on the NamedTemporaryFile.
NOTE: The caller is reponsible for deleting the NamedTemporaryFile.
>>> downloadedFileName = download_remote_file_to_tempfile(
"/home/ubuntu/a/search.rb"
)
>>> with open(downloadedFileName, "r") as f:
# do some processing here...
>>> os.unlink(downloadedFileName) # delete the file
Copies a file to the server if it does not exist there.
localFileName(str): local path of the file to copy to the server
serverFileName(str): path on the server to copy to
>>> copy_file_to_server_if_not_exists("helpers.py",
os.path.join("my-repo", "helpers.py")
)
Checks if a given path on the server is a directory.
>>> is_dir("/home/ubuntu")
True
Updates the package list of the package manager (currently assumed to be apt-get)
>>> update_package_manage_package_lists()
Installs a list of software using the system’s package manager if they have not been installed. Currently this assumes apt-get to be the package manager.
>>> install_software_using_package_manager(
["vim", "openjdk-6-jdk", "unzip"]
)
Determines if a given software is installed on the system by its package manager (currently assumed to be apt-get).
>>> is_installed_using_package_manager("python")
True
Clones the Vundle vim plugin (https://github.com/gmarik/Vundle.vim) to the server (if it hasn’t been cloned), pulls updates, checkout v0.10.2, and installs vim plugins managed by Vundle.
>>> setup-vundle()
Determines if a program is in any folder in the PATH environment variable.
>>> is_program_on_path("python")
True
Installs the most recent version of docker (https://www.docker.io) using the http://get.docker.io shell script, and adds the current user to the docker group.
Extracts one return value of a Fabric task decorated with fabric.decorators.run_once and ran with fabric.tasks.execute; this Fabric task should have the same return value for all hosts.
Refer to the Example Script in viki.fabric.docker - A short guide for an example of when to use this function.
Obtains the value under a series of nested keys in fabric.api.env; the value of every key in keyList 9except for the final key) is expected to be a dict.
keyList(list of str): list of keys under fabric.api.env
>>> env
{'liar': {'pants': {'on': 'fire'}, 'cuts': {'tree': 'leaf'}}, 'feed': {'ready': 'roll'}}
>>> env_get_nested_keys(["liar"])
{'pants': {'on': 'fire'}, 'cuts': {'tree': 'leaf'}}
>>> env_get_nested_keys(["liar", "cuts"])
{'tree': 'leaf'}
>>> env_get_nested_keys(["feed", "ready"])
'roll'
>>> env_get_nested_keys(["feed", "ready", "roll"])
None
>>> env_get_nested_keys(["liar", "on"])
None
>>> env_get_nested_keys(["liar", "liar", "pants", "on", "fire"])
None
>>> env_get_nested_keys(["liar", "liar", "pants", "on", "fire"], "argh")
'argh'
Calls get_in_env, but with the 0th element of the keyList set to VIKI_FABRIC_CONFIG_KEY_NAME.
>>> env
{'viki_fabric_config': {'hierarchy': {'of': 'keys', 'king': {'pin': 'ship'}}}}}
>>> get_in_viki_fabric_config(["hierarchy"])
{"of": "keys", "king": {"pin": {"ship"}}}
>>> get_in_viki_fabric_config(["hierarchy", "of"])
'keys'
>>> get_in_viki_fabric_config(["hierarchy", "of", "keys"])
None
>>> get_in_viki_fabric_config(["hierarchy", "notthere"])
None
>>> get_in_viki_fabric_config(["hierarchy", "pin"])
None
>>> get_in_viki_fabric_config(["hierarchy", "pin"], "useThis")
'useThis'
Determines if fabric.api.env has a set of nested keys; the value of each key in keyList (except for the final key) is expected to be a dict
>>> env
{'whos': {'your': 'daddy', 'the': {'man': {'not': 'him'}}}}
>>> env_has_nested_keys(['whos'])
True
>>> env_has_nested_keys(['your'])
False
>>> env_has_nested_keys(['whos', 'your'])
True
>>> env_has_nested_keys(['whos', 'your', 'daddy'])
False
>>> env_has_nested_keys(['whos', 'the', 'man'])
True
>>> env_has_nested_keys(['whos', 'man', 'not'])
False
Determines if a directory on a server is under Git control.
>>> is_dir_under_git_control("/home/ubuntu/viki-fabric-helpers")
True
Fabric task that sets up the ssh keys and a wrapper script for GIT_SSH to allow cloning of private Github repositories.
For a Python Fabric script that imports the viki.fabric.git module using:
import viki.fabric.git
we can use this Fabric task from the command line, like so:
fab -H host1,host2,host3 viki.fabric.git.setup_server_for_git_clone
Alternatively, for a Python Fabric script that imports the viki.fabric.git module using:
import viki.fabric.git as fabric_git
we can use this Fabric task from the command like, like so:
fab -H host1,host2,host3 fabric_git.setup_server_for_git_clone
This function can also be called as a normal function (hopefully from within another Fabric task).
Determines if the setup_server_for_git_clone Fabric task has been run.
This task checks for the existence of some files on the server to determine whether the setup_server_for_git_clone task has been run.
>>> is_fabtask_setup_server_for_git_clone_run()
False # along with some other output before this return value
Returns the path to the git ssh script
>>> get_git_ssh_script_path()
"/home/ubuntu/git_ssh_wrap.sh"