31
2014/05/24 第8弾 週末ランサーズ Tomonari NAKAMURA Infrastructure as Code ~ ツールスタック / ヌーラボの事例 ~ http://www.flickr.com/photos/statuelibrtynps/6276757947/

Infrastructure as code ~ ツールスタック / ヌーラボの事例 ~

Embed Size (px)

DESCRIPTION

第8弾 週末ランサーズ http://weekendlancers.doorkeeper.jp/events/11216

Citation preview

Page 1: Infrastructure as code ~ ツールスタック / ヌーラボの事例 ~

2014/05/24 第8弾 週末ランサーズ Tomonari NAKAMURA

Infrastructure as Code ~ ツールスタック / ヌーラボの事例 ~

http://www.flickr.com/photos/statuelibrtynps/6276757947/

Page 2: Infrastructure as code ~ ツールスタック / ヌーラボの事例 ~

自己紹介•名前:中村知成 ( @ikikko ) •所属 •株式会社ヌーラボ •日本Jenkinsユーザ会 •推しメン:さっしー 現在、総選挙

速報1位!

Page 3: Infrastructure as code ~ ツールスタック / ヌーラボの事例 ~

�� ��������������� ������������������������������������������������������������������������������������� ��������������•  ��������������!��� ���•  ��������� �����������������!����������

������������ ��� ���������

Page 4: Infrastructure as code ~ ツールスタック / ヌーラボの事例 ~

������������ ������ �������"��������"�"��������������"�������������� ����� ����������������������������������!������������ ����������#���������"������������"��� �������������!������ ���������•  ������ �����������������������������#�� ������� �����•  ��� ����������������� � ���� ����������������������������!����������������� ���

Page 5: Infrastructure as code ~ ツールスタック / ヌーラボの事例 ~

��� ������ �������������������������� ����������� ���������!�������•  ��� ��� ����!��������������������•  �������� ��������� "�����������������•  �����������!����������������������������������������������!������������

Page 6: Infrastructure as code ~ ツールスタック / ヌーラボの事例 ~

in ヌーラボ!

•アプリ寄りの開発者 •インフラ方面も関わり出す !

•Jenkinsやビルド環境の整備

Page 7: Infrastructure as code ~ ツールスタック / ヌーラボの事例 ~

アジェンダ•背景 •Infrastructure as Code とは •関連ツールスタック •ヌーラボでの事例

Page 8: Infrastructure as code ~ ツールスタック / ヌーラボの事例 ~

背景

https://speakerdeck.com/nulabinc/yun-yong-devopsshi-dai-wosheng-kinukutameni

Page 9: Infrastructure as code ~ ツールスタック / ヌーラボの事例 ~

背景•インフラそこまで詳しくない •既存の手順書とか、シェルスクリプトはあった

•けど、見てもよく分からない><

Page 10: Infrastructure as code ~ ツールスタック / ヌーラボの事例 ~
Page 11: Infrastructure as code ~ ツールスタック / ヌーラボの事例 ~

サ|バ

Page 12: Infrastructure as code ~ ツールスタック / ヌーラボの事例 ~

背景•インフラ周りが整備されてると嬉しいな

•簡単に試せる環境とか •いつでも動くように、スクリプトがメンテされてるとか

Page 13: Infrastructure as code ~ ツールスタック / ヌーラボの事例 ~

!!!

Infrastructure as Code

Page 14: Infrastructure as code ~ ツールスタック / ヌーラボの事例 ~

アジェンダ•背景 •Infrastructure as Code とは •関連ツールスタック •ヌーラボでの事例

Page 15: Infrastructure as code ~ ツールスタック / ヌーラボの事例 ~

Infrastructure as Code•インフラをコードとして表現 •アプリ開発で培った開発方法論を、インフラ領域にも適用可

•テスト / 継続的インテグレーション •コードレビュー / Pull Request

Page 16: Infrastructure as code ~ ツールスタック / ヌーラボの事例 ~

参考•naoya さんのブログ記事 • http://d.hatena.ne.jp/naoya/20131215/1387090668

•mizzy さんの Web+DB Press  「テスト駆動インフラ」 • http://gihyo.jp/magazine/wdpress/archive/2014/vol80

実は僕も 第3特集書いてます

Page 17: Infrastructure as code ~ ツールスタック / ヌーラボの事例 ~

アジェンダ•背景 •Infrastructure as Code とは •関連ツールスタック •ヌーラボでの事例

Page 18: Infrastructure as code ~ ツールスタック / ヌーラボの事例 ~

各ツールの関連

Page 19: Infrastructure as code ~ ツールスタック / ヌーラボの事例 ~

Vagrant•VirtualBoxやAWSなどの仮想マシンをコマンドで手軽に扱える

•AnsibleやChefとも連携可能Vagrant.configure(2)  do  |config|  !    config.vm.provision  "chef_solo"  do  |chef|          chef.cookbooks_path  =  "cookbooks"          chef.add_recipe  "httpd"      end  !end

Page 20: Infrastructure as code ~ ツールスタック / ヌーラボの事例 ~

Ansible•Python製のサーバ構成管理ツール •冪等性: 何度実行しても結果は同じ •サーバ側はPythonとsshdだけ

-­‐  name:  install  requirement  system  packages      action:  yum  name={{  item  }}      with_items:          -­‐  make          -­‐  gcc          -­‐  curl

Page 21: Infrastructure as code ~ ツールスタック / ヌーラボの事例 ~

serverspec•RSpec風のサーバ構成管理テストツール

•稼働前 / 稼働中のサーバにテスト

describe  "#{ENV['TARGET_HOST']}.spec"  do  !    describe  service('tomcat')  do          it  {  should  be_running      }          it  {  should_not  be_enabled  }      end  !    describe  port(8080)  do          it  {  should  be_listening  }      end  !...

Page 22: Infrastructure as code ~ ツールスタック / ヌーラボの事例 ~

Jenkins•継続的インテグレーションツール •コミット時や定期実行で自動ビルド

Page 23: Infrastructure as code ~ ツールスタック / ヌーラボの事例 ~

ハンズオンで実践!

https://www.flickr.com/photos/ochre_jelly/7066887773

Page 24: Infrastructure as code ~ ツールスタック / ヌーラボの事例 ~

ハンズオン +α

Page 25: Infrastructure as code ~ ツールスタック / ヌーラボの事例 ~

アジェンダ•背景 •Infrastructure as Code とは •関連ツールスタック •ヌーラボでの事例

Page 26: Infrastructure as code ~ ツールスタック / ヌーラボの事例 ~

ワークフロー

http://nulab-inc.com/ja/blog/nulab/nulab-immutable-infrastructure_1/

Page 27: Infrastructure as code ~ ツールスタック / ヌーラボの事例 ~

Packer

•イメージ (AMI) 作成ツール

•Ansibleを起動時に実行可能

{      "builders":  [{          "type":  "amazon-­‐ebs",          "region":  "us-­‐west-­‐2",          "source_ami":  "ami-­‐ccf297fc",          "instance_type":  "m1.small",          "ssh_username":  "ec2-­‐user",          "ami_name":  "base  {{isotime}}"      }],      "provisioners":  [          {              "type":  "ansible-­‐local",              "playbook_file":  "ansible/ami.yml",              "role_paths":  [                      "ansible/roles/base"              ]          }      ]  }

Page 28: Infrastructure as code ~ ツールスタック / ヌーラボの事例 ~

Fabric•Python製のデプロイツール •シェルコマンドを列挙していく、シンプルな記述

@task  def  start_tomcat():      sudo('rm  -­‐f  /usr/java/tomcat/temp/*.{index,data}')      sudo('service  tomcat  start’)      print  green("Tomcat  started!!!")

Page 29: Infrastructure as code ~ ツールスタック / ヌーラボの事例 ~

Typetalk•JenkinsやAnsibleの実行結果を通知 •   /    プラグインも提供

!

!

!

•Hubotで、Typetalk->Jenkinsの連携も

Page 30: Infrastructure as code ~ ツールスタック / ヌーラボの事例 ~

チャットってそんなに重要?Infrastructure as Codeの先には

DevOpsが見えてくる

DevOpsで関わる全ての人が手軽に扱える チャットは、ますます重要に!

Page 31: Infrastructure as code ~ ツールスタック / ヌーラボの事例 ~

ご清聴 ありがとうございました!