Slide 1

Slide 1 text

Fabric Python Developers Festa 2013.03

Slide 2

Slide 2 text

͓·͑୭Α

Slide 3

Slide 3 text

drillbits

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

BePROUD

Slide 6

Slide 6 text

BePROUD Web Alchemist

Slide 7

Slide 7 text

BePROUD Web Alchemist #sht #precure #nitiasa

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

Fabric?

Slide 10

Slide 10 text

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.

Slide 11

Slide 11 text

͸͍

Slide 12

Slide 12 text

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.

Slide 13

Slide 13 text

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.

Slide 14

Slide 14 text

Application Deployment?

Slide 15

Slide 15 text

Πϯετʔϧ ઃఆ ىಈ

Slide 16

Slide 16 text

By SSH

Slide 17

Slide 17 text

ϗϫοτ

Slide 18

Slide 18 text

ϗϫοτ Python

Slide 19

Slide 19 text

ϗϫοτ Python MySQL

Slide 20

Slide 20 text

ϗϫοτ Python MySQL Nginx

Slide 21

Slide 21 text

ϗϫοτ Python MySQL Nginx gunicorn

Slide 22

Slide 22 text

ϗϫοτ Python MySQL Nginx gunicorn Jenkins

Slide 23

Slide 23 text

ϗϫοτ Python MySQL Nginx gunicorn Jenkins mercurial

Slide 24

Slide 24 text

ϗϫοτ Python MySQL Nginx gunicorn Jenkins mercurial Django

Slide 25

Slide 25 text

ϗϫοτ Python MySQL Nginx gunicorn Jenkins mercurial Django Nagios

Slide 26

Slide 26 text

ϗϫοτ Python MySQL Nginx gunicorn Jenkins mercurial Django Nagios

Slide 27

Slide 27 text

ϗϫοτ Python MySQL Nginx gunicorn Jenkins mercurial Django Nagios memcached

Slide 28

Slide 28 text

ϗϫοτ Python MySQL Nginx gunicorn Jenkins mercurial Django Nagios memcached RabbitMQ

Slide 29

Slide 29 text

ϗϫοτ Python MySQL Nginx gunicorn Jenkins mercurial Django Nagios memcached RabbitMQ redis

Slide 30

Slide 30 text

ϗϫοτ Python MySQL Nginx gunicorn Jenkins mercurial Django Nagios memcached RabbitMQ redis node.js

Slide 31

Slide 31 text

ϗϫοτ Python MySQL Nginx gunicorn Jenkins mercurial Django Nagios memcached RabbitMQ redis node.js Hadoop

Slide 32

Slide 32 text

ϗϫοτ Python MySQL Nginx gunicorn Jenkins mercurial Django Nagios memcached RabbitMQ redis node.js Hadoop daemontoo

Slide 33

Slide 33 text

ϗϫοτ Python MySQL Nginx gunicorn Jenkins mercurial Django Nagios memcached RabbitMQ redis node.js Hadoop daemontoo PHP

Slide 34

Slide 34 text

ϗϫοτ Python MySQL Nginx gunicorn Jenkins mercurial Django Nagios memcached RabbitMQ redis node.js Hadoop daemontoo PHP mongoDB

Slide 35

Slide 35 text

ϗϫοτ Python MySQL Nginx gunicorn Jenkins mercurial Django Nagios memcached RabbitMQ redis node.js Hadoop daemontoo PHP mongoDB POSTFIX

Slide 36

Slide 36 text

ϗϫοτ Python MySQL Nginx gunicorn Jenkins mercurial Django Nagios memcached RabbitMQ redis node.js Hadoop daemontoo PHP mongoDB POSTFIX δϟό

Slide 37

Slide 37 text

ͨ͘͞Μ

Slide 38

Slide 38 text

͔͠΋

Slide 39

Slide 39 text

To Many Servers

Slide 40

Slide 40 text

Complex Combination

Slide 41

Slide 41 text

ͩΔ͍

Slide 42

Slide 42 text

Only Once?

Slide 43

Slide 43 text

NO

Slide 44

Slide 44 text

։ൃ؀ڥ

Slide 45

Slide 45 text

։ൃ؀ڥ εςʔδϯά

Slide 46

Slide 46 text

։ൃ؀ڥ εςʔδϯά ຊ൪؀ڥ

Slide 47

Slide 47 text

Is That All?

Slide 48

Slide 48 text

NO

Slide 49

Slide 49 text

࣍ϑΣʔζͷͨΊͷ Yet Another εςʔδϯά

Slide 50

Slide 50 text

ʊਓਓਓਓਓਓਓਓʊ ʼɹεςʔδϯά2ɹʻ ʉY^Y^Y^Y^Y^Y^Yʉ

Slide 51

Slide 51 text

͓٬͞Μ͕ಈ࡞֬ೝ͢Δ Yet Another εςʔδϯά2

Slide 52

Slide 52 text

ʊਓਓਓਓਓਓਓਓʊ ʼɹεςʔδϯά3ɹʻ ʉY^Y^Y^Y^Y^Y^Yʉ

Slide 53

Slide 53 text

ޫ଎ͷҟ໊Λ࣋ͪ͜Ε·Ͱͷ εςʔδϯά 2 Ͱ͸ॲཧ͖͠ Εͳ͔ͬͨେྔσʔλ΋ࣗࡏ ʹૢΔߴՁͳΔڀۃͷ৽؀ڥ

Slide 54

Slide 54 text

ʊਓਓਓਓਓਓਓਓʊ ʼ εςʔδϯά2_2 ʻ ʉY^Y^Y^Y^Y^Y^Yʉ

Slide 55

Slide 55 text

αʔόʔ෺ނׂΕͨ

Slide 56

Slide 56 text

ʊਓਓਓਓਓਓਓਓʊ ʼ ɹ ɹ࠶ߏஙɹ ɹ ʻ ʉY^Y^Y^Y^Y^Y^Yʉ

Slide 57

Slide 57 text

Կճ΋΍Δ͜ͱʹͳΔ ※ϑΟΫγϣϯͰ͢

Slide 58

Slide 58 text

ͩΔ͍

Slide 59

Slide 59 text

Update

Slide 60

Slide 60 text

ϝϯςφϯεϞʔυ

Slide 61

Slide 61 text

ϝϯςφϯεϞʔυ ϒϥϯν੾Γସ͑

Slide 62

Slide 62 text

ϝϯςφϯεϞʔυ ϒϥϯν੾Γସ͑ ϚΠάϨʔγϣϯͱ͔

Slide 63

Slide 63 text

ϝϯςφϯεϞʔυ ϒϥϯν੾Γସ͑ ϚΠάϨʔγϣϯͱ͔ ͍Ζ͍Ζ࠶ىಈ

Slide 64

Slide 64 text

։ൃ؀ڥͰ͸ 1೔Կճ΋΍Δ

Slide 65

Slide 65 text

darui

Slide 66

Slide 66 text

Operation Mistakes

Slide 67

Slide 67 text

όον࠶ىಈ๨Ε ϚΠάϨʔγϣϯ͠๨Ε ϒϥϯν໭͠๨Ε

Slide 68

Slide 68 text

Yes! खॱॻ

Slide 69

Slide 69 text

No content

Slide 70

Slide 70 text

No content

Slide 71

Slide 71 text

d

Slide 72

Slide 72 text

ͩΔ͍ͷ͸͍΍Ͱ͢Ͷ

Slide 73

Slide 73 text

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.

Slide 74

Slide 74 text

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.

Slide 75

Slide 75 text

streamlining

Slide 76

Slide 76 text

ޮ཰Խ

Slide 77

Slide 77 text

DDD

Slide 78

Slide 78 text

Darui Driven Deployment

Slide 79

Slide 79 text

ࣗಈԽ͠·͠ΐ͏

Slide 80

Slide 80 text

ैདྷͷࣗಈԽ

Slide 81

Slide 81 text

Shell Script

Slide 82

Slide 82 text

No content

Slide 83

Slide 83 text

No content

Slide 84

Slide 84 text

No content

Slide 85

Slide 85 text

ແɹཧ

Slide 86

Slide 86 text

No content

Slide 87

Slide 87 text

ख୳ΓͰൺֱ͠·͢

Slide 88

Slide 88 text

Shell Script Soldier, Stay aSleep ( ˘ω˘) ɹɹ ⊂˶ʗʋ-ɺʊ_ ɹʗ⊂_/ʊʊʊʊ ʗ

Slide 89

Slide 89 text

Python Remote control Utils

Slide 90

Slide 90 text

Python Remote control Utils

Slide 91

Slide 91 text

Getting Started

Slide 92

Slide 92 text

$ pip install fabric

Slide 93

Slide 93 text

$ fab Fatal error: Couldn't find any fabfiles! Remember that -f can be used to specify fabfile path, and use -h for help. Aborting.

Slide 94

Slide 94 text

# fabfile.py from fabric.api import local # task def hello(): local('echo hello') # shell command def uname(): local('uname')

Slide 95

Slide 95 text

$ fab --list Available commands: hello uname

Slide 96

Slide 96 text

$ fab hello [localhost] local: echo hello hello Done.

Slide 97

Slide 97 text

$ fab uname [localhost] local: uname Darwin Done.

Slide 98

Slide 98 text

$ fab hello uname [localhost] local: echo hello hello [localhost] local: uname Darwin Done.

Slide 99

Slide 99 text

$ fab start_maintenance update restart

Slide 100

Slide 100 text

# fabfile.py from fabric.api import run def uname(): run('uname')

Slide 101

Slide 101 text

$ 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.

Slide 102

Slide 102 text

# fabfile.py from fabric.api import sudo def uname(): sudo('uname')

Slide 103

Slide 103 text

# 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')

Slide 104

Slide 104 text

# 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')

Slide 105

Slide 105 text

$ fab dev uname

Slide 106

Slide 106 text

$ fab production uname

Slide 107

Slide 107 text

Package

Slide 108

Slide 108 text

$ tree fabfile fabfile ├── __init__.py ├── django.py └── host.py

Slide 109

Slide 109 text

# fabfile/__init__.py from . import django from . import host

Slide 110

Slide 110 text

# 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'

Slide 111

Slide 111 text

# fabfile/django.py from fabric.api import task @task def restart(): pass

Slide 112

Slide 112 text

$ fab --list Available commands: django.restart host.dev

Slide 113

Slide 113 text

Roles

Slide 114

Slide 114 text

# 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'], }

Slide 115

Slide 115 text

# fabfile/django.py from fabric.api import roles, task @task @roles('app') def restart(): pass

Slide 116

Slide 116 text

Shell Script?

Slide 117

Slide 117 text

No content

Slide 118

Slide 118 text

ͨͿΜେมͰ͢

Slide 119

Slide 119 text

Python Remote control Utils

Slide 120

Slide 120 text

No content

Slide 121

Slide 121 text

$ ssh [email protected] -i id_rsa uname run('uname')

Slide 122

Slide 122 text

Python Remote control Utils

Slide 123

Slide 123 text

put upload_template append, uncomment prefix

Slide 124

Slide 124 text

put

Slide 125

Slide 125 text

from fabric.api import put put( local_path='resources/sushi.txt', remote_path='/var/www/sushi.txt', )

Slide 126

Slide 126 text

upload_template

Slide 127

Slide 127 text

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, }, )

Slide 128

Slide 128 text

# templates/my.cnf : # You can set .._buffer_pool_size up to 50 - 80 %% innodb_buffer_pool_size = %(buffer_pool_size)s :

Slide 129

Slide 129 text

# templates/my.cnf : # You can set .._buffer_pool_size up to 50 - 80 %% innodb_buffer_pool_size = %(buffer_pool_size)s :

Slide 130

Slide 130 text

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', )

Slide 131

Slide 131 text

# templates/my.cnf : # You can set .._buffer_pool_size up to 50 - 80 % innodb_buffer_pool_size = {{ buffer_pool_size }} :

Slide 132

Slide 132 text

append

Slide 133

Slide 133 text

from fabric.contrib.files import append append( filename='/etc/hosts', text='10.0.0.101 dev-server', )

Slide 134

Slide 134 text

uncomment

Slide 135

Slide 135 text

from fabric.contrib.files \ import uncomment uncomment( filename='/etc/vsftpd.conf', regex='write_enable=YES', char='#', )

Slide 136

Slide 136 text

prefix

Slide 137

Slide 137 text

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')

Slide 138

Slide 138 text

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')

Slide 139

Slide 139 text

$ 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

Slide 140

Slide 140 text

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')

Slide 141

Slide 141 text

$ 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

Slide 142

Slide 142 text

from contextlib import contextmanager from fabric.context_managers \ import prefix @contextmanager def workon(venv): with prefix('workon ' + venv): yield

Slide 143

Slide 143 text

with workon('myproj'): run('pip install xaxtsuxo')

Slide 144

Slide 144 text

·ͱΊ

Slide 145

Slide 145 text

Deploy ͩΔ͍

Slide 146

Slide 146 text

Deploy ͩΔ͍ Shell Script ࢖͏ඞཁͳ͠

Slide 147

Slide 147 text

Deploy ͩΔ͍ Shell Script ࢖͏ඞཁͳ͠ ͦΕ Chef Ͱ | @tk0miya

Slide 148

Slide 148 text

No content