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
Laravel や Symfony で手っ取り早く OpenAPI のドキュメントを作成する
azuki
2
120
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
1
100
[Do iOS '24] Ship your app on a Friday...and enjoy your weekend!
polpielladev
0
110
Why Jakarta EE Matters to Spring - and Vice Versa
ivargrimstad
0
1.1k
みんなでプロポーザルを書いてみた
yuriko1211
0
280
Duckdb-Wasmでローカルダッシュボードを作ってみた
nkforwork
0
130
WebフロントエンドにおけるGraphQL(あるいはバックエンドのAPI)との向き合い方 / #241106_plk_frontend
izumin5210
4
1.4k
距離関数を極める! / SESSIONS 2024
gam0022
0
290
Remix on Hono on Cloudflare Workers
yusukebe
1
300
C++でシェーダを書く
fadis
6
4.1k
CSC509 Lecture 09
javiergs
PRO
0
140
アジャイルを支えるテストアーキテクチャ設計/Test Architecting for Agile
goyoki
9
3.3k
Featured
See All Featured
Building a Scalable Design System with Sketch
lauravandoore
459
33k
A Tale of Four Properties
chriscoyier
156
23k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
YesSQL, Process and Tooling at Scale
rocio
169
14k
Code Reviewing Like a Champion
maltzj
520
39k
The Invisible Side of Design
smashingmag
298
50k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
Producing Creativity
orderedlist
PRO
341
39k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
What's in a price? How to price your products and services
michaelherold
243
12k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
44
2.2k
A designer walks into a library…
pauljervisheath
204
24k
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