![Page 1: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」](https://reader031.vdocuments.us/reader031/viewer/2022011721/5873bd961a28abbc788b5c85/html5/thumbnails/1.jpg)
PythonとYAMLでGCPをDeploy! 「Google Cloud Deployment Manager」
![Page 2: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」](https://reader031.vdocuments.us/reader031/viewer/2022011721/5873bd961a28abbc788b5c85/html5/thumbnails/2.jpg)
2
![Page 3: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」](https://reader031.vdocuments.us/reader031/viewer/2022011721/5873bd961a28abbc788b5c85/html5/thumbnails/3.jpg)
3
![Page 4: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」](https://reader031.vdocuments.us/reader031/viewer/2022011721/5873bd961a28abbc788b5c85/html5/thumbnails/4.jpg)
Masashi Terui @ marcy_teruiI’m a developer and architect in the operators company (JIG-SAW Inc.)
I'm the organizer on the some of events in sapporo with the theme of "Infrastructure as Code”. I’m a member of JAWS-UG Sapporo and GCPUG Sapporo (Coming soon!)
I develop a IoT application (ServerSide) with Python and more. I’m a husband of my wife. I’m a father of my son and daughter.
ABOUT ME
4
![Page 5: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」](https://reader031.vdocuments.us/reader031/viewer/2022011721/5873bd961a28abbc788b5c85/html5/thumbnails/5.jpg)
ABOUT US
5
Coming soon!!
![Page 6: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」](https://reader031.vdocuments.us/reader031/viewer/2022011721/5873bd961a28abbc788b5c85/html5/thumbnails/6.jpg)
6
![Page 7: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」](https://reader031.vdocuments.us/reader031/viewer/2022011721/5873bd961a28abbc788b5c85/html5/thumbnails/7.jpg)
7
Cloud Deployment Managerは、複雑なクラウドプラットフォームのソリューションを
シンプルな宣言型のテンプレートを使用して、
開発者が容易に設計、共有、展開、管理することを可能とします。
簡単なWebサーバから複雑な高可用性クラスタまで、
Cloud Deployment Managerはチームがインフラの管理に費やす時間を少なくし、
より多くの時間を開発をに向けることができます。
- - 公式ページ(https://cloud.google.com/deployment-manager/) の英文訳(間違ってたらゴメンナサイ) -
”
![Page 8: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」](https://reader031.vdocuments.us/reader031/viewer/2022011721/5873bd961a28abbc788b5c85/html5/thumbnails/8.jpg)
つまり
8
複雑なクラウドプラットフォームのソリューション
シンプルな宣言型のテンプレート
容易に設計、共有、展開、管理
→ GCPを
→ YAMLで
→ アレコレできちゃうわけです
![Page 9: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」](https://reader031.vdocuments.us/reader031/viewer/2022011721/5873bd961a28abbc788b5c85/html5/thumbnails/9.jpg)
9
resources: - type: compute.v1.instance name: vm-my-first-deployment properties: zone: us-central1-b machineType: https://www.googleapis.com/compute/v1/projects/sunlit-arcade-100913/zones/us-central1-b/machineTypes/f1-micro disks: - deviceName: boot type: PERSISTENT boot: true autoDelete: true initializeParams: diskName: disk-my-first-deployment sourceImage: https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-7-wheezy-v20140619 networkInterfaces: - network: https://www.googleapis.com/compute/v1/projects/sunlit-arcade-100913/global/networks/default accessConfigs: - name: External NAT type: ONE_TO_ONE_NAT
![Page 10: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」](https://reader031.vdocuments.us/reader031/viewer/2022011721/5873bd961a28abbc788b5c85/html5/thumbnails/10.jpg)
10
いいえ、違います
YAMLとかJSONとかは”Code”ではありません
あくまでデータ(リソース)の表現方法(フォーマット)
別にあ○しぼーをdisってるわけではありません
個人的見解です
![Page 11: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」](https://reader031.vdocuments.us/reader031/viewer/2022011721/5873bd961a28abbc788b5c85/html5/thumbnails/11.jpg)
11
![Page 12: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」](https://reader031.vdocuments.us/reader031/viewer/2022011721/5873bd961a28abbc788b5c85/html5/thumbnails/12.jpg)
12
JSON or YAML
CloudFormationはより細かく制御でき、
ほとんどのサービスや機能を網羅しているが表現が冗長
軽く1000行とかのJSONができあがるの、何か間違ってると思うんですよ…
(
Pythonで書ける
![Page 13: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」](https://reader031.vdocuments.us/reader031/viewer/2022011721/5873bd961a28abbc788b5c85/html5/thumbnails/13.jpg)
13
![Page 14: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」](https://reader031.vdocuments.us/reader031/viewer/2022011721/5873bd961a28abbc788b5c85/html5/thumbnails/14.jpg)
14
インフラのコード化
自動化
再現可能なインフラ
インフラの世界へ開発のプロセスを持ち込む(TDD, CI etc…)
バズワード・・・?
![Page 15: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」](https://reader031.vdocuments.us/reader031/viewer/2022011721/5873bd961a28abbc788b5c85/html5/thumbnails/15.jpg)
15
![Page 16: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」](https://reader031.vdocuments.us/reader031/viewer/2022011721/5873bd961a28abbc788b5c85/html5/thumbnails/16.jpg)
16
![Page 17: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」](https://reader031.vdocuments.us/reader031/viewer/2022011721/5873bd961a28abbc788b5c85/html5/thumbnails/17.jpg)
17
![Page 18: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」](https://reader031.vdocuments.us/reader031/viewer/2022011721/5873bd961a28abbc788b5c85/html5/thumbnails/18.jpg)
18
![Page 19: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」](https://reader031.vdocuments.us/reader031/viewer/2022011721/5873bd961a28abbc788b5c85/html5/thumbnails/19.jpg)
19
resources: - type: compute.v1.instance name: vm-my-first-deployment properties: zone: us-central1-b machineType: https://www.googleapis.com/compute/v1/projects/sunlit-arcade-100913/zones/us-central1-b/machineTypes/f1-micro disks: - deviceName: boot type: PERSISTENT boot: true autoDelete: true initializeParams: diskName: disk-my-first-deployment sourceImage: https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-7-wheezy-v20140619 networkInterfaces: - network: https://www.googleapis.com/compute/v1/projects/sunlit-arcade-100913/global/networks/default accessConfigs: - name: External NAT type: ONE_TO_ONE_NAT
![Page 20: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」](https://reader031.vdocuments.us/reader031/viewer/2022011721/5873bd961a28abbc788b5c85/html5/thumbnails/20.jpg)
20
def GenerateConfig(context): return """ resources: - type: compute.v1.instance name: vm-my-first-deployment properties: zone: us-central1-b machineType: https://www.googleapis.com/compute/v1/projects/sunlit-arcade-100913/zones/us-central1-b/machineTypes/f1-micro <snip> sourceImage: https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-7-wheezy-v20140619 networkInterfaces: - network: https://www.googleapis.com/compute/v1/projects/sunlit-arcade-100913/global/networks/default accessConfigs: - name: External NAT type: ONE_TO_ONE_NAT """
![Page 21: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」](https://reader031.vdocuments.us/reader031/viewer/2022011721/5873bd961a28abbc788b5c85/html5/thumbnails/21.jpg)
21
import helpers.common
def GenerateConfig(context): return """ resources: - type: compute.v1.instance name: %(name) properties: zone: %(zone) machineType: %(machine_type) disks: - deviceName: boot <snip> sourceImage: %(source_image) networkInterfaces: - network: %(metwork_project)/global/networks/default <snip> """ % {"name": (common.GenerateMachineName("myFrontend", context.env(“environment")), "zone": context.env("zone"),, "machine_type": common.GenerateMachineTypeURI(zone=context.env("zone"), type=context.env("type")), "project": common.GenerateProjectURI(context.env("project")), "source_image": common.GenerateProjectURI("debian-cloud", "ebian-7-wheezy-v20140619"), "metwork_project": common.GenerateProjectURI("sunlit-arcade-100913")}
![Page 22: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」](https://reader031.vdocuments.us/reader031/viewer/2022011721/5873bd961a28abbc788b5c85/html5/thumbnails/22.jpg)
22
![Page 23: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」](https://reader031.vdocuments.us/reader031/viewer/2022011721/5873bd961a28abbc788b5c85/html5/thumbnails/23.jpg)
こんな風に
23
よく使う記述をメソッドにまとめる
オブジェクトに属性を与えて、
メソッドコールするだけ的な感じにしたり
使い回しを考えて共通化・部品化
自分(達)のインフラ構築・管理フレームワークを作れる
![Page 24: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」](https://reader031.vdocuments.us/reader031/viewer/2022011721/5873bd961a28abbc788b5c85/html5/thumbnails/24.jpg)
24
![Page 25: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」](https://reader031.vdocuments.us/reader031/viewer/2022011721/5873bd961a28abbc788b5c85/html5/thumbnails/25.jpg)
25
![Page 26: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」](https://reader031.vdocuments.us/reader031/viewer/2022011721/5873bd961a28abbc788b5c85/html5/thumbnails/26.jpg)
26
gcloud deployment-manager deployments create <name> --config <yml>
![Page 27: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」](https://reader031.vdocuments.us/reader031/viewer/2022011721/5873bd961a28abbc788b5c85/html5/thumbnails/27.jpg)
27
公式ドキュメント(英語ですw)
https://cloud.google.com/deployment-manager/overview
![Page 28: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」](https://reader031.vdocuments.us/reader031/viewer/2022011721/5873bd961a28abbc788b5c85/html5/thumbnails/28.jpg)
28
![Page 29: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」](https://reader031.vdocuments.us/reader031/viewer/2022011721/5873bd961a28abbc788b5c85/html5/thumbnails/29.jpg)
29
![Page 30: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」](https://reader031.vdocuments.us/reader031/viewer/2022011721/5873bd961a28abbc788b5c85/html5/thumbnails/30.jpg)
30
![Page 32: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」](https://reader031.vdocuments.us/reader031/viewer/2022011721/5873bd961a28abbc788b5c85/html5/thumbnails/32.jpg)
32
![Page 33: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」](https://reader031.vdocuments.us/reader031/viewer/2022011721/5873bd961a28abbc788b5c85/html5/thumbnails/33.jpg)
33
Pythonでクラウド(特にGCP)を操りたい イケてるクラウドインフラ上でPythonでIoTサーバサイド開発したい方今のところAWSメイン(Kinesis, DynamoDBとか、コアなプロダクト触れます) GCPは具体的に活用計画有り、Azure他もベンダー問わずメリットあるなら使います。もちろんInfra as CodeやChatOps等も実践しています。
![Page 34: PythonとYAMLでGCPをDeploy!「Google Cloud Deployment Manager」](https://reader031.vdocuments.us/reader031/viewer/2022011721/5873bd961a28abbc788b5c85/html5/thumbnails/34.jpg)