fabric ====== .. image:: fabric-logo.png :align: right .. class:: incremental "Fabric is a simple pythonic remote deployment tool." Less general tool - remote deployment scripting. Similar in function to capistrano. First released Jan 2008, pretty stable pre-1.0 app, Python 2.5 on unix only. Developed by Jeff Forcier and Christian Hansen Homepage: http://www.nongnu.org/fab/ .. footer:: Simeon Franklin - Baypiggies March 26th, 2009 Fail ==== .. image:: ws_ftp.gif :scale: 75 :align: left .. class:: small incremental Sad truth of web development - deployment strategy in the past frequently consisted of - manually ftp'ing files, - manually updating database schema - manually restarting services to reflect configuration changes - manually ... Alternatives to ws_ftp ====================== Remote deployment tool should .. class:: incremental - run local commands - transfer files - run remote commands Fabric is a framework for building a command line tool that easily accomplishes these tasks. Usage ===== Create file fabfile.py. Functions in fabfile.py become fab commands accessed like:: $ fab function_name Fabric offers a dozen built in operations - I primarily use .. class:: incremental - put - upload files to remote hosts - local - run local shell commands - run - run shell command on remote host Configuration ============= Configuration class supporting keyword arguments or attribute assignment. Fabric expects: .. class:: incremental - fab_hosts: a list of remote hosts - and optionally fab_user (if the remote username != local username) - and that's it. Simple Example ============== .. class:: small green :: config(fab_hosts=['simeonfranklin.com'], fab_user='simeon') def build(): """Build local resources""" local("ls -l > build.txt") def deploy(): """Copy local resources to remote host""" put("build.txt","public_html/") Simple Usage ============ .. class:: tiny gray :: $ fab list Fabric v. 0.1.0. Running list... Available commands are: about : Display Fabric version... *build : Build local resources *deploy : Copy local resources to remote host help : Display Fabric usage help... let : Set a Fabric variable. list : Display a list of commands ... shell : Start an interactive shell ... Done. Simple Usage ============ .. class:: tiny gray :: $ fab build deploy Running build... [localhost] run: ls -l > build.txt Running deploy... Logging into the following hosts as simeon: simeonfranklin.com Password for simeon@simeonfranklin.com: [simeonfranklin.com] put: build.txt -> public_html/build.txt Done. Requires decorator ================== .. class:: tiny green :: def staging(): config.target = "test" def production(): config.target = "public_html" @requires('target', used_for='finding the target deployment dir.', provided_by=['staging', 'production']) def deploy(): """Copy local resources to remote host""" put("build.txt","$(target)/") Output ====== .. class:: tiny gray :: $ fab deploy Fabric v. 0.1.0. Running deploy... The 'deploy' command requires a 'target' variable. This variable is used for finding the target deployment dir. Get the variable by running one of these commands: staging production $ fab staging deploy And Much Much More ================== .. class:: incremental If you need it! My personal fabfile has about a dozen commands to package my virtualenv and project, transer to the remote server, run a test suite, and restart the appropriate services. 108 lines, docstrings included. All based on commands/decorators shown so far - and there are only about 5 decorators and a dozen operations in the fabric api all told... Not just deployment! Great place to store frequently run utility commands (cleaning local cache, #backup# files, etc). Conclusion ========== Useful, minimal, easy to learn... This is the end =============== [insert public domain pic of Jim Morrison here] My only friend, the end... .. class:: huge Questions?