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
CI / CDって具体的にどう動いている??
Search
toyo-da01
January 24, 2023
Technology
22
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
CI / CDって具体的にどう動いている??
社内勉強会登壇資料。CICDパイプラインをFizzBuzzコードで作成した内容を共有。
toyo-da01
January 24, 2023
More Decks by toyo-da01
See All by toyo-da01
AWSからLANケーブルへ!パブリッククラウドエンジニアのホームラボ挑戦
da01toyo
0
29
Amazon Connect コンタクトフローの大量移管?!
da01toyo
0
59
AWS ハッカソン体験記~ゲーム開発で得られたAWSスキル紹介~
da01toyo
0
40
UTM (統合脅威管理; FortiGate) on AWSを構築するにはどんなネットワーク設定??
da01toyo
0
380
悪用厳禁! SQLインジェクションやってみた!
da01toyo
0
39
業務効率化したいのに時間がない??OSSとLambdaを用いたツールのスピード開発術
da01toyo
0
55
普通のやり方だとできない!?💦 Amazon Connect x Lambdaのレア?な連携のご紹介!
da01toyo
0
37
CI/CD ツール導入で達成した、開発と運用の協力関係強化とストレスフリーなリリースプロセスの実現に迫る!
da01toyo
0
26
監視オペレータはもういらない?~Amazon Connectを用いたスペシャリスト自動手配システムの内製開発~
da01toyo
0
20
Other Decks in Technology
See All in Technology
Metadata - Section 1: HTML Basics
mohab1
0
120
Conditional PED-ANOVA: Hyperparameter Importance in Hierarchical & Dynamic Search Spaces
pfn
PRO
0
140
Local CI × GitHub Actions
gogutan
2
220
ブラウザとサーバーから考えるAI時代のフロントエンド監視
shogo4131
3
990
DBについての基礎説明(MySQL編) - コロプラ 2026年度 新卒研修
colopl
0
110
専門領域のAIをどう評価するか
bengo4com
2
270
継続的なAIコスト最適化
bgpat
1
350
フロントエンドカンファレンス関西2026 - 速すぎるUIに、待ち時間を
teamlab
PRO
0
180
DWH の限界突破! AI エージェント向け爆速リアルタイムデータ基盤 ClickHouse
jozono
1
480
宣言型部分更新は何を解決しどこへ向かうのか
shuta13
1
460
Webの常識が通じないHTMLメールのダークモード
teamlab
PRO
0
130
WasmをRustにする
sansantech
PRO
0
260
Featured
See All Featured
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
4
4.4k
Into the Great Unknown - MozCon
thekraken
41
2.8k
Paper Plane (Part 1)
katiecoart
PRO
2
12k
The browser strikes back
jonoalderson
0
1.8k
Marketing to machines
jonoalderson
1
5.9k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
330
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2.2k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
7k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
Raft: Consensus for Rubyists
vanstee
142
7.8k
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
600
Transcript
2023/01/24 社内勉強会 豊岡大地 CI / CDって具体的にどう動いている?? pytestで! aws lambda deploymemtで!
GitHub Actions Pythonのコードで見てみると、、
/7 ―― Agenda ―― 1. 改めて!CI / CDとは? 2. Pythonでpytestを用いたテストコード作成
3. AWS Lambda(s3 キックイベント)に適用 4. デプロイを合わせたCI / CDの構築 ◼ GitHub Actionsの簡単なやり方 ◼ トライ&エラーの説明 ◼ これまで作成したシナリオの紹介 5. まとめ デモ① デモ② 1
/7 ――改めて!CI / CDとは? ―― ◼ CI (継続的インテグレーション; Continuos Integration)
開発者向けの自動化プロセスを表し、アプリケーションへの新しいコード変更が定期的にビルド、テストされ、 共通リポジトリに統合 ◼ CD (継続的デリバリー/デプロイメント; Continuos Delivery/Deployment) 継続的デリバリーは、開発者のアプリケーションへの変更に対して、バグがないか自動的にテスト、リ ポジトリにアップロード 継続的デプロイメントは、開発者による変更をリポジトリから本番環境に自動的にリリースして顧客が 利用できるようにする (図)RedHatから引用 2
/7 ――Pythonでpytestを用いたテストコード作成―― CI / CD を実現するにはテストコードが必要 →Pythonには、主流なテストフレームワークは”unittest”と“pytest”の2種類が主流 ◼ unittest:Pythonの標準ライブラリに入っているテストフレームワーク。 JavaのJunitをベースに作られている。
◼ pytest:pipなどでインストールする必要があるが、簡単に記述ができるテストフレームワーク。 (図)Googleで作成。赤がunittestで、青がpytest 特にこだわりがあるわけではないので、 ”pytest”を採用! 3
/7 ――Pythonでpytestを用いたテストコード作成―― pytestは次のようなルールがあります。 ◼評価側:関数に戻り値を設ける ◼テスト側:スクリプト、テスト関数に”test_”のprefixをつける #fizzbuzz.py(FizzBuzz関数) def fizzbuzz(num): if num
% 15 == 0: return "FizzBuzz" elif num % 3 == 0: return "Fizz" elif num % 5 == 0: return "Buzz" else: return str(num) ※chatGPTに書いてもらいました、、! #test_fizzbuzz.py(テストコード) from fizzbuzz import fizzbuzz def test_1st(): num = 15 assert fizzbuzz(num) == "FizzBuzz" #--------------------------------------------------------- import pytest test_set = [ (1, "1"), (3, "Fizz"), (5, "Buzz"), (15, "FizzBuzz") ] @pytest.mark.parametrize("test_input, expect", test_set) def test_2nd(test_input, expect): assert fizzbuzz(test_input) == expect “”” 3で割り切れる数字は”Fizz” 5で割り切れる数字は”Buzz” 15で割り切れる数字は”FizzBuzz” その他はそのまま文字列で返す “”“ デモ① ターミナル上の動き pytest test_fizzbuzz.py or python –m pytest test_fizzbuzz.py #オプション -s で標準出力込み -v で各テスト別の出力 4
/7 ――AWS Lambda(s3 キックイベント)に適用―― 呼び出しツールの架電メールを判断するLambdaで、テストコードを適用させました! 5
/7 ――AWS Lambda(s3 キックイベント)に適用―― 呼び出しツールの運用に当たり、架電判定メールの調整が3-4か月に一度程度。 →コードでカスタマイズした際に、既存の動きに影響が出ていないか不安 テストフレームワークを使ってみてよかったところ ◼ これまで正常に動作していた関数の担保 ※新規開発よりアップデート作業でより、
効果が感じやすいなと思いました ◼ ステータスを評価する戻り値は必須なので、早期 リターンを意識してネストが深くならない #test_lambda_handler.py def get_args(bucket, key): event = { "Records": [{ "s3": { "bucket": { "name": bucket, }, "object": { "key": key } } }] } return event class TestMailJudge(): def test_1st(self): event = get_args(bucket, key) response = lambda_handler(event, "") assert response["statusCode"] == 200 and response["alertType"] == "word" : : 6
/7 ――デプロイを合わせたCI / CDの構築―― ◼ GitHub Actionsの簡単なやり方 ①GitHubレポジトリのトップディレクトリ配下の、.github/workflows/にymlファイルを追加 ②ymlに環境情報・ジョブ情報を加えていく #pytest.yml
name: Run pytest on: push: branches: - stg workflow_dispatch: permissions: read-all(write-all) jobs: pytest: runs-on: ubuntu-latest defaults: run: shell: bash working-directory: ./pytest (1/2) steps: # Configure - name: Git clone the repository uses: actions/checkout@v3 - name: Set up Python 3.10 uses: actions/setup-python@v4 with: python-version: '3.10’ - name: Install dependencies run: | python -m pip install --upgrade pip pip install pytest # Execute - name: PyTest run: python -m pytest test_fizzbuzz.py --junit-xml pytest.xml (2/2) デモ②;トライ&エラーの説明 テストフレームワークの準備 テストの実施 環境情報① 環境情報② 7