Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Fabric Python Developers Festa 2013.03 #pyfes
Search
drillbits
March 16, 2013
Programming
28
6.7k
Fabric Python Developers Festa 2013.03 #pyfes
はい
drillbits
March 16, 2013
Tweet
Share
Other Decks in Programming
See All in Programming
TypeScript Graph でコードレビューの心理的障壁を乗り越える
ysk8hori
2
1.1k
よくできたテンプレート言語として TypeScript + JSX を利用する試み / Using TypeScript + JSX outside of Web Frontend #TSKaigiKansai
izumin5210
6
1.7k
as(型アサーション)を書く前にできること
marokanatani
9
2.6k
Webの技術スタックで マルチプラットフォームアプリ開発を可能にするElixirDesktopの紹介
thehaigo
2
1k
詳細解説! ArrayListの仕組みと実装
yujisoftware
0
580
3rd party scriptでもReactを使いたい! Preact + Reactのハイブリッド開発
righttouch
PRO
1
600
Jakarta EE meets AI
ivargrimstad
0
130
色々なIaCツールを実際に触って比較してみる
iriikeita
0
330
シェーダーで魅せるMapLibreの動的ラスタータイル
satoshi7190
1
480
Realtime API 入門
riofujimon
0
150
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
190
Arm移行タイムアタック
qnighy
0
310
Featured
See All Featured
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Rails Girls Zürich Keynote
gr2m
94
13k
Designing the Hi-DPI Web
ddemaree
280
34k
GitHub's CSS Performance
jonrohan
1030
460k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
Statistics for Hackers
jakevdp
796
220k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.4k
Transcript
Fabric Python Developers Festa 2013.03
͓·͑୭Α
drillbits
None
BePROUD
BePROUD Web Alchemist
BePROUD Web Alchemist #sht #precure #nitiasa
None
Fabric?
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.
͍
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.
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.
Application Deployment?
Πϯετʔϧ ઃఆ ىಈ
By SSH
ϗϫοτ
ϗϫοτ Python
ϗϫοτ Python MySQL
ϗϫοτ Python MySQL Nginx
ϗϫοτ Python MySQL Nginx gunicorn
ϗϫοτ Python MySQL Nginx gunicorn Jenkins
ϗϫοτ Python MySQL Nginx gunicorn Jenkins mercurial
ϗϫοτ Python MySQL Nginx gunicorn Jenkins mercurial Django
ϗϫοτ Python MySQL Nginx gunicorn Jenkins mercurial Django Nagios
ϗϫοτ Python MySQL Nginx gunicorn Jenkins mercurial Django Nagios
ϗϫοτ Python MySQL Nginx gunicorn Jenkins mercurial Django Nagios memcached
ϗϫοτ Python MySQL Nginx gunicorn Jenkins mercurial Django Nagios memcached
RabbitMQ
ϗϫοτ Python MySQL Nginx gunicorn Jenkins mercurial Django Nagios memcached
RabbitMQ redis
ϗϫοτ Python MySQL Nginx gunicorn Jenkins mercurial Django Nagios memcached
RabbitMQ redis node.js
ϗϫοτ Python MySQL Nginx gunicorn Jenkins mercurial Django Nagios memcached
RabbitMQ redis node.js Hadoop
ϗϫοτ Python MySQL Nginx gunicorn Jenkins mercurial Django Nagios memcached
RabbitMQ redis node.js Hadoop daemontoo
ϗϫοτ Python MySQL Nginx gunicorn Jenkins mercurial Django Nagios memcached
RabbitMQ redis node.js Hadoop daemontoo PHP
ϗϫοτ Python MySQL Nginx gunicorn Jenkins mercurial Django Nagios memcached
RabbitMQ redis node.js Hadoop daemontoo PHP mongoDB
ϗϫοτ Python MySQL Nginx gunicorn Jenkins mercurial Django Nagios memcached
RabbitMQ redis node.js Hadoop daemontoo PHP mongoDB POSTFIX
ϗϫοτ Python MySQL Nginx gunicorn Jenkins mercurial Django Nagios memcached
RabbitMQ redis node.js Hadoop daemontoo PHP mongoDB POSTFIX δϟό
ͨ͘͞Μ
͔͠
To Many Servers
Complex Combination
ͩΔ͍
Only Once?
NO
։ൃڥ
։ൃڥ εςʔδϯά
։ൃڥ εςʔδϯά ຊ൪ڥ
Is That All?
NO
࣍ϑΣʔζͷͨΊͷ Yet Another εςʔδϯά
ʊਓਓਓਓਓਓਓਓʊ ʼɹεςʔδϯά2ɹʻ ʉY^Y^Y^Y^Y^Y^Yʉ
͓٬͞Μ͕ಈ࡞֬ೝ͢Δ Yet Another εςʔδϯά2
ʊਓਓਓਓਓਓਓਓʊ ʼɹεςʔδϯά3ɹʻ ʉY^Y^Y^Y^Y^Y^Yʉ
ޫͷҟ໊Λ࣋ͪ͜Ε·Ͱͷ εςʔδϯά 2 Ͱॲཧ͖͠ Εͳ͔ͬͨେྔσʔλࣗࡏ ʹૢΔߴՁͳΔڀۃͷ৽ڥ
ʊਓਓਓਓਓਓਓਓʊ ʼ εςʔδϯά2_2 ʻ ʉY^Y^Y^Y^Y^Y^Yʉ
αʔόʔނׂΕͨ
ʊਓਓਓਓਓਓਓਓʊ ʼ ɹ ɹ࠶ߏஙɹ ɹ ʻ ʉY^Y^Y^Y^Y^Y^Yʉ
ԿճΔ͜ͱʹͳΔ ※ϑΟΫγϣϯͰ͢
ͩΔ͍
Update
ϝϯςφϯεϞʔυ
ϝϯςφϯεϞʔυ ϒϥϯνΓସ͑
ϝϯςφϯεϞʔυ ϒϥϯνΓସ͑ ϚΠάϨʔγϣϯͱ͔
ϝϯςφϯεϞʔυ ϒϥϯνΓସ͑ ϚΠάϨʔγϣϯͱ͔ ͍Ζ͍Ζ࠶ىಈ
։ൃڥͰ 1ԿճΔ
darui
Operation Mistakes
όον࠶ىಈΕ ϚΠάϨʔγϣϯ͠Ε ϒϥϯν͠Ε
Yes! खॱॻ
None
None
d
ͩΔ͍ͷ͍Ͱ͢Ͷ
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.
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.
streamlining
ޮԽ
DDD
Darui Driven Deployment
ࣗಈԽ͠·͠ΐ͏
ैདྷͷࣗಈԽ
Shell Script
None
None
None
ແɹཧ
None
ख୳ΓͰൺֱ͠·͢
Shell Script Soldier, Stay aSleep ( ˘ω˘) ɹɹ ⊂˶ʗʋ-ɺʊ_ ɹʗ⊂_/ʊʊʊʊ
ʗ
Python Remote control Utils
Python Remote control Utils
Getting Started
$ pip install fabric
$ fab Fatal error: Couldn't find any fabfiles! Remember that
-f can be used to specify fabfile path, and use -h for help. Aborting.
# fabfile.py from fabric.api import local # task def hello():
local('echo hello') # shell command def uname(): local('uname')
$ fab --list Available commands: hello uname
$ fab hello [localhost] local: echo hello hello Done.
$ fab uname [localhost] local: uname Darwin Done.
$ fab hello uname [localhost] local: echo hello hello [localhost]
local: uname Darwin Done.
$ fab start_maintenance update restart
# fabfile.py from fabric.api import run def uname(): run('uname')
$ fab uname -u me -H 10.0.0.1 -i id_rsa [10.0.0.1]
Executing task 'uname' [10.0.0.1] run: uname [10.0.0.1] out: Linux [10.0.0.1] out: Done. Disconnecting from 10.0.0.1... done.
# fabfile.py from fabric.api import sudo def uname(): sudo('uname')
# fabfile.py from fabric.api import env, run env.hosts = ['10.0.0.1']
env.user = 'me' env.key_filename = 'id_rsa' def uname(): run('uname')
# fabfile.py from fabric.api import env, run def dev(): env.hosts
= ['10.0.0.1'] env.user = 'me' env.key_filename = 'id_rsa' def uname(): run('uname')
$ fab dev uname
$ fab production uname
Package
$ tree fabfile fabfile ├── __init__.py ├── django.py └── host.py
# fabfile/__init__.py from . import django from . import host
# fabfile/host.py from fabric.api import env, task @task def dev():
env.hosts = ['10.0.0.1'] env.user = 'me' env.key_filename = 'id_rsa'
# fabfile/django.py from fabric.api import task @task def restart(): pass
$ fab --list Available commands: django.restart host.dev
Roles
# fabfile/host.py from fabric.api import env, task @task def dev():
env.hosts = ['10.0.0.1', '10.0.0.2'] env.roledefs = { 'app': ['10.0.0.1'], 'db': ['10.0.0.2'], }
# fabfile/django.py from fabric.api import roles, task @task @roles('app') def
restart(): pass
Shell Script?
None
ͨͿΜେมͰ͢
Python Remote control Utils
None
$ ssh
[email protected]
-i id_rsa uname run('uname')
Python Remote control Utils
put upload_template append, uncomment prefix
put
from fabric.api import put put( local_path='resources/sushi.txt', remote_path='/var/www/sushi.txt', )
upload_template
from fabric.contrib.files \ import upload_template upload_template( filename='templates/my.cnf', destination='/etc/my.cnf', context={ 'buffer_pool_size':
env.MYSQL_BUFFER_POOL_SIZE, }, )
# templates/my.cnf : # You can set .._buffer_pool_size up to
50 - 80 %% innodb_buffer_pool_size = %(buffer_pool_size)s :
# templates/my.cnf : # You can set .._buffer_pool_size up to
50 - 80 %% innodb_buffer_pool_size = %(buffer_pool_size)s :
from fabric.contrib.files \ import upload_template upload_template( filename='templates/my.cnf', remote_path='/etc/my.cnf', context=context, use_jinja=True,
# jinja2! template_dir='templates', )
# templates/my.cnf : # You can set .._buffer_pool_size up to
50 - 80 % innodb_buffer_pool_size = {{ buffer_pool_size }} :
append
from fabric.contrib.files import append append( filename='/etc/hosts', text='10.0.0.101 dev-server', )
uncomment
from fabric.contrib.files \ import uncomment uncomment( filename='/etc/vsftpd.conf', regex='write_enable=YES', char='#', )
prefix
from fabric.api import run from fabric.context_managers \ import cd run('tar
xzvf Python-2.7.3.tgz') with cd('Python-2.7.3'): run('./configure') run('make') sudo('make install')
from fabric.api import run run('tar xzvf Python-2.7.3.tgz') run('cd Python-2.7.3'): run('./configure')
run('make') sudo('make install')
$ ssh
[email protected]
-i id_rsa tar xzvf Python-2.7.3.tgz $ ssh
[email protected]
-i id_rsa cd Python-2.7.3 $ ssh
[email protected]
-i id_rsa ./configure $ ssh
[email protected]
-i id_rsa make $ ssh
[email protected]
-i id_rsa make install
from fabric.api import run from fabric.context_managers \ import cd run('tar
xzvf Python-2.7.3.tgz') with cd('Python-2.7.3'): run('./configure') run('make') sudo('make install')
$ ssh (...) cd Python-2.7.3 $ ssh (...) cd Python-2.7.3
&& ./configure $ ssh (...) cd Python-2.7.3 && make $ ssh (...) cd Python-2.7.3 && make install
from contextlib import contextmanager from fabric.context_managers \ import prefix @contextmanager
def workon(venv): with prefix('workon ' + venv): yield
with workon('myproj'): run('pip install xaxtsuxo')
·ͱΊ
Deploy ͩΔ͍
Deploy ͩΔ͍ Shell Script ͏ඞཁͳ͠
Deploy ͩΔ͍ Shell Script ͏ඞཁͳ͠ ͦΕ Chef Ͱ | @tk0miya
None