Continuous Integration with Fabric
-
Upload
varun-batra -
Category
Technology
-
view
315 -
download
1
description
Transcript of Continuous Integration with Fabric
![Page 1: Continuous Integration with Fabric](https://reader033.fdocuments.us/reader033/viewer/2022052910/559c1c6d1a28ab14158b4633/html5/thumbnails/1.jpg)
Continuous IntegrationWith Fabric
http://docs.fabfile.org
Varun Batra @ Deft Infotech Pvt. Ltd.
![Page 2: Continuous Integration with Fabric](https://reader033.fdocuments.us/reader033/viewer/2022052910/559c1c6d1a28ab14158b4633/html5/thumbnails/2.jpg)
I am Lazy!
I need one command to deploy codes.
>fab deploy
That’s what I was talking about
Varun Batra @ Deft Infotech Pvt. Ltd.
![Page 3: Continuous Integration with Fabric](https://reader033.fdocuments.us/reader033/viewer/2022052910/559c1c6d1a28ab14158b4633/html5/thumbnails/3.jpg)
What if something goes wrong?
>fab deploy
This command should handle that as well and report me.
Varun Batra @ Deft Infotech Pvt. Ltd.
![Page 4: Continuous Integration with Fabric](https://reader033.fdocuments.us/reader033/viewer/2022052910/559c1c6d1a28ab14158b4633/html5/thumbnails/4.jpg)
Common Principle of CI
• Code Repository (I use GIT)
• Fast & Auto Build
• Self Testing
• ‘Test Environment’ is not ‘Build Environment’
• Auto Deployment: merge to master/deploy branch (GIT), this should auto deploy it
• Self Sustainable System, e.g. if db is destroyed, it should automatically recreated by latest backup
Varun Batra @ Deft Infotech Pvt. Ltd.
![Page 5: Continuous Integration with Fabric](https://reader033.fdocuments.us/reader033/viewer/2022052910/559c1c6d1a28ab14158b4633/html5/thumbnails/5.jpg)
My Deployment Principle
• Based on my experience
• Based on guys’s ‘better than me’ experience
• Let me know if you can improve because you can
Varun Batra @ Deft Infotech Pvt. Ltd.
![Page 6: Continuous Integration with Fabric](https://reader033.fdocuments.us/reader033/viewer/2022052910/559c1c6d1a28ab14158b4633/html5/thumbnails/6.jpg)
Varun Batra @ Deft Infotech Pvt. Ltd.
![Page 7: Continuous Integration with Fabric](https://reader033.fdocuments.us/reader033/viewer/2022052910/559c1c6d1a28ab14158b4633/html5/thumbnails/7.jpg)
Why Fabric?I learned it in half day
It can do what I need
Few seconds installation
Varun Batra @ Deft Infotech Pvt. Ltd.
![Page 8: Continuous Integration with Fabric](https://reader033.fdocuments.us/reader033/viewer/2022052910/559c1c6d1a28ab14158b4633/html5/thumbnails/8.jpg)
GIT
>git branch something_cool
>git checkout something_cool
>git commit -a -m ‘what I did?’
>git checkout master
>git merge something_cool
>git push
git checkout -b something_cool combines first two commands
Varun Batra @ Deft Infotech Pvt. Ltd.
![Page 9: Continuous Integration with Fabric](https://reader033.fdocuments.us/reader033/viewer/2022052910/559c1c6d1a28ab14158b4633/html5/thumbnails/9.jpg)
Fabric: library + command-line tool
Fabric is a Python (2.5 or higher) library and command-line tool for streamlining the use of SSH for application deployment or systems administration tasks.
I copied from their website, I am lazy
Varun Batra @ Deft Infotech Pvt. Ltd.
![Page 10: Continuous Integration with Fabric](https://reader033.fdocuments.us/reader033/viewer/2022052910/559c1c6d1a28ab14158b4633/html5/thumbnails/10.jpg)
Fabric Features
• Runs local and remote commands
• Runs normal or sudo commands
• Upload & Download files
• Prompt for input
• Simultaneous deploying in multiple server
• Output in different colors like red(text,bold=False)
Varun Batra @ Deft Infotech Pvt. Ltd.
![Page 11: Continuous Integration with Fabric](https://reader033.fdocuments.us/reader033/viewer/2022052910/559c1c6d1a28ab14158b4633/html5/thumbnails/11.jpg)
Fabric combines
fabfile.py fab
Varun Batra @ Deft Infotech Pvt. Ltd.
![Page 12: Continuous Integration with Fabric](https://reader033.fdocuments.us/reader033/viewer/2022052910/559c1c6d1a28ab14158b4633/html5/thumbnails/12.jpg)
There is a catch
each run or sudo call has its own distinct shell session.
run('cd foo' && 'mkdir bar')is notrun('cd foo')run('mkdir bar')
iswith('cd foo')
run('mkdir bar')
Varun Batra @ Deft Infotech Pvt. Ltd.
![Page 13: Continuous Integration with Fabric](https://reader033.fdocuments.us/reader033/viewer/2022052910/559c1c6d1a28ab14158b4633/html5/thumbnails/13.jpg)
How discussed deployment process should be?
Varun Batra @ Deft Infotech Pvt. Ltd.
![Page 14: Continuous Integration with Fabric](https://reader033.fdocuments.us/reader033/viewer/2022052910/559c1c6d1a28ab14158b4633/html5/thumbnails/14.jpg)
Processing Output
Output of ‘run’ command is stored in ‘url’ variable
Varun Batra @ Deft Infotech Pvt. Ltd.
![Page 15: Continuous Integration with Fabric](https://reader033.fdocuments.us/reader033/viewer/2022052910/559c1c6d1a28ab14158b4633/html5/thumbnails/15.jpg)
Deploy with options?
• Passing parameters?• fab deploy:env=production
• fab deploy:production (in order of params)
• !Passing True is string i.e. ‘True’ not True
• Deploy to many hosts?• env.hosts = ['[email protected]', ' [email protected] ']
• fab –H [email protected], [email protected] deploy
• Show fewer output?• with hide('output','running'), settings(warn_only=True):
Varun Batra @ Deft Infotech Pvt. Ltd.
![Page 16: Continuous Integration with Fabric](https://reader033.fdocuments.us/reader033/viewer/2022052910/559c1c6d1a28ab14158b4633/html5/thumbnails/16.jpg)
@serial VS @parallel
Varun Batra @ Deft Infotech Pvt. Ltd.
![Page 17: Continuous Integration with Fabric](https://reader033.fdocuments.us/reader033/viewer/2022052910/559c1c6d1a28ab14158b4633/html5/thumbnails/17.jpg)
More decorators?
• @hosts
• @roles
• @runs_once !caution with @parallel
• @task
• @with_settings
• @serial
• @parallel
Varun Batra @ Deft Infotech Pvt. Ltd.
![Page 18: Continuous Integration with Fabric](https://reader033.fdocuments.us/reader033/viewer/2022052910/559c1c6d1a28ab14158b4633/html5/thumbnails/18.jpg)
Context Managers
Remember ‘with’?
with('cd ~/git_repo/'):
run('git pull')
#cd ~/git_repo/ && git pull
with hide('running', 'stdout', 'stderr'):
do_something()
Varun Batra @ Deft Infotech Pvt. Ltd.
![Page 19: Continuous Integration with Fabric](https://reader033.fdocuments.us/reader033/viewer/2022052910/559c1c6d1a28ab14158b4633/html5/thumbnails/19.jpg)
Context Manager cont’d..
• cd
• with
• lcd
• path
• prefix
• settings
• show
Varun Batra @ Deft Infotech Pvt. Ltd.
![Page 20: Continuous Integration with Fabric](https://reader033.fdocuments.us/reader033/viewer/2022052910/559c1c6d1a28ab14158b4633/html5/thumbnails/20.jpg)
Contributions
• File/directory management• comment/uncomment, sed, append, contains, exists, upload_template, first
• Project Tools• rsync_project, upload_project
• Django integration
Varun Batra @ Deft Infotech Pvt. Ltd.
![Page 21: Continuous Integration with Fabric](https://reader033.fdocuments.us/reader033/viewer/2022052910/559c1c6d1a28ab14158b4633/html5/thumbnails/21.jpg)
Lets look at fabfile.py
Varun Batra @ Deft Infotech Pvt. Ltd.
![Page 22: Continuous Integration with Fabric](https://reader033.fdocuments.us/reader033/viewer/2022052910/559c1c6d1a28ab14158b4633/html5/thumbnails/22.jpg)
But wait..What about auto-
deployment?cron VS service
Varun Batra @ Deft Infotech Pvt. Ltd.
![Page 23: Continuous Integration with Fabric](https://reader033.fdocuments.us/reader033/viewer/2022052910/559c1c6d1a28ab14158b4633/html5/thumbnails/23.jpg)
fab prompt_for_any_questions
Varun Batra
IT Consultant
Deft Infotech Pvt. Ltd.
skype:varunb.deftinfotech
http://varunbatra.com
https://www.linkedin.com/in/varunbatra/
https://www.facebook.com/VarunBatraIT
https://twitter.com/batravarun
fab stay_in_touch
Varun Batra @ Deft Infotech Pvt. Ltd.