Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
CUE+Goで安全かつ簡単に設定ファイルを自動生成してみた
Search
kuro
December 01, 2023
850
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
CUE+Goで安全かつ簡単に設定ファイルを自動生成してみた
Go Conference mini 2023/12/02 Winter in Kyotoの登壇資料です。
kuro
December 01, 2023
More Decks by kuro
See All by kuro
Loosening the Reins: Go Generics Get More Flexible
kuro_kurorrr
0
440
Bit by Bit: Building a SIMD CSV Parser in Go 1.26
kuro_kurorrr
0
57
nilとは何か 〜interfaceの構造とnil!=nilから理解する〜
kuro_kurorrr
3
2.9k
GoLab2025 Recap
kuro_kurorrr
0
5.3k
OpenFeatureに学ぶ コミュニティの広げ方
kuro_kurorrr
0
68
Module Proxyのマニアックな話 / Niche Topics in Module Proxy
kuro_kurorrr
0
4.1k
Weak References in Go 1.24: Memory Management Superpowers
kuro_kurorrr
0
130
サプライチェーン攻撃に学ぶModuleの仕組みと セキュリティ対策
kuro_kurorrr
3
2.3k
PipeCD と Bucketeer の Document MCP Serverを作って公開した話
kuro_kurorrr
0
260
Featured
See All Featured
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9.2k
Why You Should Never Use an ORM
jnunemaker
PRO
61
10k
Embracing the Ebb and Flow
colly
88
5.2k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
530
Raft: Consensus for Rubyists
vanstee
142
7.7k
Ethics towards AI in product and experience design
skipperchong
2
380
[RailsConf 2023] Rails as a piece of cake
palkan
59
7k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2.2k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.3k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Product Roadmaps are Hard
iamctodd
55
13k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.8k
Transcript
CUE+Goで安全かつ簡単に設定 ファイルを自動生成してみた Go Conference mini 2023/12/02 Winter in Kyoto kuroda
naoki
自己紹介 kuro @knkurokuro7 - 名前:kuroda naoki - 所属:株式会社サイバーエージェントAI事業本部 プリズムパートナーカンパニー -
大学生の時、京都で過ごしました。 - 鴨川デルタで毎日のようにお酒を飲んだり、花火 をしたりしていました。 この三角のとこが鴨 川デルタです→
CUEについて - Goで書かれた設定記述言語 - JSONやYAMLのように値を設定するだけでなく、同時に型を設定すること もできる。→値と型を同等に扱う。 - 型や制約の表現が豊富(例. string型やint型、デフォルト値、配列、struct、 パターン制約、for文、if
) - 異なるファイル間に定義を分割できる。 →「package」(https://cuelang.org/docs/tutorials/tour/packages/packages/)を使う - Goの処理の中で呼び出して、JSONやYAMLに変換できる。
なぜCUEを使いたいのか PipeCDというCDツール(ArgoCDみたいなもの)を使いたい。 →そのために各環境×アプリケーション(ECS or Lambda)×(設定YAML+リソース 記述YAML)=約360YAMLファイル の数のYAMLファイルを作成する必要があった。 →ファイルごとに共通した部分も多く、なるべくcopy&pasteミスを減らしたい。 →CUEでバリデーションをしながらGoでファイルを自動生成 →さらにコマンド化する。
具体的な実装(CUE) 1. ベースファイル→全てのファイルで共通 する値(バージョンとか)や各値に対する制 約(cpuやmemoryとか) 2. 各設定ファイル→各YAMLで異なる具体 的な値 ↓同じpackageであればファイルを分割でき る。
具体的な実装(Go) 1. ベースファイルと各個別ファイル をマージしてインスタンスを作成 2. バリデーションを実行 3. 各CUEのvalueごとにYAMLに 変換 4.
YAMLファイルに出力 ("cuelang.org/go/cue"、"cuelang.or g/go/cue/load"、"cuelang.org/go/en coding/yaml"を使用)
バリデーションの挙動 例えば先ほどの_cpuの値を 25600としたとき。 make pipecdコマンドを叩くと、 {"time":"2023-12-02T06:08:45.056174+09:00","level": "ERROR","msg":"failed to generate cue
file: value error (path = cue/app/dev/fuga/taskdef.cue): _cpu: invalid value 25600 (out of bound <=4096)","syslog":{"appname":"unknown","env":"loca l","tag":"","commit":""}} make: *** [pipecd] Error 1
Pros&Cons Pros - バリデーションによってミスが減った(気がする?)。 - Goから直接呼び出して操作できるので、ロジックをGo側でも追加できる。 →特定のファイルは生成しないとか、特定の値はJSONファイルに出力する等 - 公式ドキュメントが詳しい。(https://cuelang.org/) Cons
- いろんな制約や型を追加したくなるので、慣れてないメンバーには読みにくい。 - CUE→YAMLという流れなので、YAMLを直接書き換えたくなる→CIでチェック。 - 日本語での記事があまりない→これからもっと広まってほしい。。
おまけ - CUEもっと広まってほしい。 - playground(https://cuelang.org/play/#cue@export@cue)もあるのでぜひ試 してみてください。 - 使えそうな部分は無限にありそうなので、もし何か思いついたらぜひ教えてくだ さい。 -
あと、sivchariさんスライドチェックしてもらってありがとうございます。