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
『ドメイン駆動設計をはじめよう』のモデリングアプローチ
masuda220
PRO
8
440
Vue SFCのtemplateでTypeScriptの型を活用しよう
tsukkee
3
1.5k
Kotlin2でdataクラスの copyメソッドを禁止する/Data class copy function to have the same visibility as constructor
eichisanden
1
130
Synchronizationを支える技術
s_shimotori
1
150
役立つログに取り組もう
irof
26
8.6k
OpenTelemetryでRailsのパフォーマンス分析を始めてみよう(KoR2024)
ymtdzzz
4
1.5k
WEBエンジニア向けAI活用入門
sutetotanuki
0
300
ECSのサービス間通信 4つの方法を比較する 〜Canary,Blue/Greenも添えて〜
tkikuc
11
2.3k
Sidekiqで実現する 長時間非同期処理の中断と再開 / Pausing and Resuming Long-Running Asynchronous Jobs with Sidekiq
hypermkt
6
2.7k
Java ジェネリクス入門 2024
nagise
0
600
2万ページのSSG運用における工夫と注意点 / Vue Fes Japan 2024
chinen
3
1.3k
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
1
290
Featured
See All Featured
Building Adaptive Systems
keathley
38
2.2k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Adopting Sorbet at Scale
ufuk
73
9k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
664
120k
Raft: Consensus for Rubyists
vanstee
136
6.6k
Building Applications with DynamoDB
mza
90
6.1k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Intergalactic Javascript Robots from Outer Space
tanoku
268
27k
YesSQL, Process and Tooling at Scale
rocio
167
14k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
4
290
Designing the Hi-DPI Web
ddemaree
280
34k
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