1. สิ่งที่คุณจะได้เรียนรู้
AI Agent Vibe Full Stack
ยินดีต้อนรับ คุณกำลังจะได้เรียนรู้ทักษะที่สำคัญอีกอย่างในการพัฒนาซอฟต์แวร์ นั่นคือวิธีแนะนําปัญญาประดิษฐ์ (AI) อย่างมีประสิทธิภาพเพื่อสร้าง ทดสอบ และติดตั้งใช้งานซอฟต์แวร์ระดับเวอร์ชันที่ใช้งานจริง Generative AI ไม่ใช่ "ระบบควบคุมอัตโนมัติ" แต่เป็นผู้ช่วยนักบินที่มีประสิทธิภาพซึ่งต้องมีผู้กำกับที่มีทักษะ
เวิร์กช็อปนี้จะนำเสนอวิธีการที่มีโครงสร้างและทำซ้ำได้สำหรับการทำงานร่วมกับ AI ในทุกขั้นตอนของวงจรการพัฒนาซอฟต์แวร์ (SDLC) ระดับมืออาชีพ คุณจะเปลี่ยนจากผู้เขียนโค้ดทีละบรรทัดไปเป็นผู้อำนวยการด้านเทคนิค ซึ่งเป็นสถาปนิกที่มีวิสัยทัศน์และผู้รับเหมาทั่วไปที่ใช้ AI เพื่อดำเนินการตามวิสัยทัศน์นั้นอย่างแม่นยำ 🚀
เมื่อจบบทแนะนำนี้ คุณจะมีสิ่งต่อไปนี้
- เปลี่ยนไอเดียระดับสูงให้เป็นสถาปัตยกรรมระบบคลาวด์โดยใช้ AI
- สร้างแบ็กเอนด์ Python ที่สมบูรณ์ด้วยพรอมต์ที่เจาะจงและเฉพาะ
- ใช้ AI เป็นโปรแกรมเมอร์คู่เพื่อแก้ไขข้อบกพร่องและแก้ไขโค้ด
- มอบหมายให้ AI สร้าง Unit Test รวมถึงการจำลอง
สร้าง Infrastructure as Code (IaC) ที่พร้อมใช้งานจริงด้วย Terraform
สร้างไปป์ไลน์ CI/CD แบบเต็มใน GitHub Actions ด้วยพรอมต์เดียว
ตรวจสอบและจัดการแอปพลิเคชันที่ใช้งานจริงโดยใช้เครื่องมือการดำเนินงานที่ทำงานด้วยระบบ AI
คุณจะไม่ได้แค่แอปที่ใช้งานได้ แต่ยังได้พิมพ์เขียวสำหรับการพัฒนาที่เพิ่มประสิทธิภาพด้วย AI อีกด้วย มาเริ่มกันเลย
2. สิ่งที่ต้องมีก่อนและการตั้งค่า
ก่อนเริ่ม มาเตรียมสภาพแวดล้อมของคุณให้พร้อมกันก่อน ซึ่งเป็นขั้นตอนสำคัญเพื่อให้การเข้าร่วมเวิร์กช็อปเป็นไปอย่างราบรื่น
สร้างบัญชี GCP ใหม่และลิงก์การเรียกเก็บเงิน
หากต้องการขับเคลื่อนเอเจนต์ AI เราต้องมี 2 สิ่ง ได้แก่ โปรเจ็กต์ Google Cloud เพื่อเป็นรากฐาน และคีย์ Gemini API เพื่อเข้าถึงโมเดลอันทรงพลังของ Google
ขั้นตอนที่ 1: เปิดใช้บัญชีสำหรับการเรียกเก็บเงิน
- การอ้างสิทธิ์บัญชีการเรียกเก็บเงินพร้อมเครดิต 5 ดอลลาร์ คุณจะต้องใช้เครดิตนี้ในการติดตั้งใช้งาน โปรดตรวจสอบบัญชี gmail
ขั้นตอนที่ 2: สร้างโปรเจ็กต์ GCP ใหม่
- ไปที่ Google Cloud Console แล้วสร้างโปรเจ็กต์ใหม่
- ไปที่ Google Cloud Console แล้วสร้างโปรเจ็กต์ใหม่
- เปิดแผงด้านซ้าย คลิก
Billing
แล้วตรวจสอบว่าบัญชีสำหรับการเรียกเก็บเงินลิงก์กับบัญชี gcp นี้หรือไม่
หากเห็นหน้านี้ ให้ตรวจสอบ manage billing account
เลือก Google Cloud Trial One แล้วลิงก์ไปยังบัญชี
ขั้นตอนที่ 3: สร้างคีย์ Gemini API
คุณต้องมีคีย์ก่อนจึงจะรักษาความปลอดภัยของคีย์ได้
- ไปที่ Google AI Studio : https://aistudio.google.com/
- ลงชื่อเข้าใช้ด้วยบัญชี Gmail
- คลิกปุ่ม "รับคีย์ API" ซึ่งมักจะอยู่ในแผงการนำทางด้านซ้ายมือหรือที่มุมขวาบน
- ในกล่องโต้ตอบ "คีย์ API" ให้คลิก "สร้างคีย์ API ในโปรเจ็กต์ใหม่"
- เลือกโปรเจ็กต์ใหม่ที่คุณสร้างขึ้นซึ่งมีการตั้งค่าบัญชีสำหรับการเรียกเก็บเงิน
- ระบบจะสร้างคีย์ API ใหม่ให้คุณ คัดลอกคีย์นี้ทันทีและเก็บไว้ในที่ปลอดภัยชั่วคราว (เช่น เครื่องมือจัดการรหัสผ่านหรือโน้ตที่ปลอดภัย) ค่านี้เป็นค่าที่คุณจะใช้ในขั้นตอนถัดไป
การตรวจสอบสิทธิ์ของ GitHub
เปิด Cloud Shell โดยไปที่ Google Cloud Console แล้วคลิกปุ่ม "เปิดใช้งาน Cloud Shell" ที่ด้านขวาบน
ขั้นตอนที่ 1: เปิด Cloud Shell
👉คลิกเปิดใช้งาน Cloud Shell ที่ด้านบนของ Google Cloud Console (ไอคอนรูปเทอร์มินัลที่ด้านบนของแผง Cloud Shell)
👉คลิกปุ่ม "เปิดตัวแก้ไข" (ลักษณะเป็นโฟลเดอร์ที่เปิดอยู่พร้อมดินสอ) ซึ่งจะเปิดตัวแก้ไขโค้ด Cloud Shell ในหน้าต่าง คุณจะเห็น File Explorer ทางด้านซ้าย
👉ค้นหารหัสโปรเจ็กต์ Google Cloud
- เปิด Google Cloud Console: https://console.cloud.google.com
- เลือกโปรเจ็กต์ที่คุณต้องการใช้สำหรับเวิร์กช็อปนี้จากเมนูแบบเลื่อนลงของโปรเจ็กต์ที่ด้านบนของหน้า
- รหัสโปรเจ็กต์จะแสดงในการ์ดข้อมูลโปรเจ็กต์ในแดชบอร์ด
👉เปิดเทอร์มินัลใน Cloud IDE
👉💻 ในเทอร์มินัล ให้ตรวจสอบว่าคุณได้รับการตรวจสอบสิทธิ์แล้วและตั้งค่าโปรเจ็กต์เป็นรหัสโปรเจ็กต์โดยใช้คำสั่งต่อไปนี้
gcloud auth list
ขั้นตอนที่ 2: ตรวจสอบสิทธิ์ด้วย GitHub และ Fork
ตรวจสอบสิทธิ์ด้วย GitHub
👉💻
gh auth login
คัดลอกรหัสไปยังหน้ายืนยันการเข้าสู่ระบบ
Fork และโคลนที่เก็บ: 👉💻
gh repo fork cuppibla/storygen-learning --clone=true
3. สถาปัตยกรรม: จากแนวคิดสู่พิมพ์เขียวด้วย Cloud Assist
ทุกโปรเจ็กต์ที่ยอดเยี่ยมเริ่มต้นด้วยวิสัยทัศน์ที่ชัดเจน เราจะใช้ผู้ช่วย AI อย่าง Cloud Assist เพื่อออกแบบสถาปัตยกรรมแอป
การทำงาน
- เปิด Google Cloud Console: https://console.cloud.google.com
- คลิก "เปิดแชท Cloud Assist" ที่มุมขวาบน
เปิดใช้ Cloud Assist
- คลิก
Get Gemini Assist
แล้วคลิกEnable Cloud Assist at no cost
- และเริ่มแชทได้เลย
ระบุพรอมต์แบบละเอียดต่อไปนี้ให้กับ Cloud Assist
ป้อนไอเดียของคุณ
Generate a Python web application that uses AI to generate children's stories and illustrations. It has Python backend and React frontend host separately on Cloudrun. They communicate through Websocket. It needs to use a generative model for text and another for images. The generated images must be used by Imagen from Vertex AI and stored in a Google Cloud Storage bucket so that frontend can fetch from the bucket to render images. I do not want any load balancer or a database for the story text. We need a solution to store the API key.
รับพิมพ์เขียวของแอป
- คลิก "แก้ไขการออกแบบแอป" คุณจะเห็นไดอะแกรม คลิกแผงด้านขวาบน "<> รับโค้ด" เพื่อดาวน์โหลดโค้ด Terraform
- Cloud Assist จะสร้างแผนภาพสถาปัตยกรรม นี่คือพิมพ์เขียวด้านภาพของเรา
ช่วงเวลาสำคัญในการเรียนรู้: AI ทำได้ดีในการออกแบบระบบระดับสูง ซึ่งสามารถแปลข้อกำหนดในภาษาง่ายๆ เป็นสถาปัตยกรรมภาพระดับมืออาชีพได้ทันที
4. การพัฒนา: สร้าง ADK ด้วย Gemini CLI
การตั้งค่าเบื้องต้น
ตรวจสอบว่าเราใช้ Gemini CLI เพื่อแยกที่เก็บและเตรียมพื้นที่ทำงาน:
การกำหนดค่าสภาพแวดล้อม
ไปที่ Cloud Shell แล้วคลิกปุ่ม "เปิดเทอร์มินัล"
- คัดลอกเทมเพลตสภาพแวดล้อม
cd ~/storygen-learning cp ~/storygen-learning/env.template ~/storygen-learning/.env
ดูไฟล์ที่ซ่อนในเครื่องมือแก้ไขหากไม่พบ .env
- คลิกดูในแถบเมนูด้านบน
- เลือกสลับไฟล์ที่ซ่อน
แก้ไขไฟล์ .env 2. แทนที่ค่าต่อไปนี้ใน .env
GOOGLE_API_KEY=[REPLACE YOUR API KEY HERE]
GOOGLE_CLOUD_PROJECT_ID=[REPLACE YOUR PROJECT ID]
GITHUB_USERNAME=[REPLACE YOUR USERNAME]
GENMEDIA_BUCKET=[REPLACE YOUR PROJECT ID]-bucket
เช่น หากรหัสโปรเจ็กต์คือ testproject
คุณควรใส่ GOOGLE_CLOUD_PROJECT_ID=testproject
และ GENMEDIA_BUCKET=testproject-bucket
สคริปต์การตั้งค่า
ไปที่ 00_Starting_Here เปิดเทอร์มินัลใหม่ (ไม่ใช่ใน Gemini CLI)
cd ~/storygen-learning/00_Starting_Here
เรียกใช้การตั้งค่าที่สมบูรณ์
./setup-complete.sh
คุณควรเห็นผลการตั้งค่าในเทอร์มินัล
สร้างเอเจนต์แรก
ไปที่ 01a_First_Agent_Ready มาใช้ Gemini CLI เพื่อสร้างเอเจนต์ ADK กัน
cd ~/storygen-learning/01a_First_Agent_Ready
เปิด Gemini CLI
gemini
ลองใช้พรอมต์ต่อไปนี้ในหน้าต่าง Gemini CLI
I need you to help me create a Google ADK (Agent Development Kit) agent for story generation. I'm working on a children's storybook app that generates creative stories with visual scenes.
Please create a complete `agent.py` file that implements an LlmAgent using Google's ADK framework. The agent should:
**Requirements:**
1. Use the `google.adk.agents.LlmAgent` class
2. Use the "gemini-2.5-flash" model (supports streaming)
3. Be named "story_agent"
4. Generate structured stories with exactly 4 scenes each
5. Output valid JSON with story text, main characters, and scene data
6. No tools needed (images are handled separately)
**Agent Specifications:**
- **Model:** gemini-2.5-flash
- **Name:** story_agent
- **Description:** "Generates creative short stories and accompanying visual keyframes based on user-provided keywords and themes."
**Story Structure Required:**
- Exactly 4 scenes: Setup → Inciting Incident → Climax → Resolution
- 100-200 words total
- Simple, charming language for all audiences
- Natural keyword integration
**JSON Output Format:**
{
"story": "Complete story text...",
"main_characters": [
{
"name": "Character Name",
"description": "VERY detailed visual description with specific colors, features, size, etc."
}
],
"scenes": [
{
"index": 1,
"title": "The Setup",
"description": "Scene action and setting WITHOUT character descriptions",
"text": "Story text for this scene"
}
// ... 3 more scenes
]
}
**Key Instructions for the Agent:**
- Extract 1-2 main characters maximum
- Character descriptions should be extremely detailed and visual
- Scene descriptions focus on ACTION and SETTING only
- Do NOT repeat character appearance in scene descriptions
- Always respond with valid JSON
Please include a complete example in the instructions showing the exact format using keywords like "tiny robot", "lost kitten", "rainy city".
The file should start with necessary imports, define an empty tools list, include a print statement for initialization, and then create the LlmAgent with all the detailed instructions.
Can you create this agent in backend/story_agent/agent.py
เมื่อเสร็จแล้ว ให้ปิดเทอร์มินัล Gemini CLI ด้วย Control+C
—————————————— ไม่บังคับ คุณสามารถข้ามไปยังส่วนวิธีแก้ปัญหาได้——————————————–
ตอนนี้ให้ยืนยันการเปลี่ยนแปลงใน ADK Web
cd ~/storygen-learning/01a_First_Agent_Ready/backend
source ../../.venv/bin/activate
adk web --port 8080
สร้างเว็บไซต์
cd ~/storygen-learning/01a_First_Agent_Ready
./start.sh
หากการเปลี่ยนแปลงใช้ไม่ได้ คุณจะเห็นข้อผิดพลาดใน ADK Web UI และเว็บไซต์
——————————————– วิธีแก้ปัญหาเริ่มต้นที่นี่ ——————————————–
Solution
สิ้นสุดกระบวนการก่อนหน้าด้วย Control+C
หรือคุณจะเปิดเทอร์มินัลอื่นก็ได้
cd ~/storygen-learning/01b_First_Agent_Done
สร้างเว็บไซต์:
./start.sh
คุณจะเห็นเว็บไซต์ดังนี้
ลองใช้ UI ของ ADK: เปิดเทอร์มินัลอื่น
cd ~/storygen-learning/01b_First_Agent_Done/backend
source ../../.venv/bin/activate
adk web --port 8080
คุณจะเห็น UI ของ ADK ซึ่งคุณสามารถถามคำถามกับตัวแทนได้
ก่อนที่จะไปยังส่วนถัดไป ให้กด Ctrl+C เพื่อสิ้นสุดกระบวนการ
5. การพัฒนา: สร้างเอเจนต์ที่กำหนดเองด้วย Imagen
สร้างเครื่องมือ Imagen (เอเจนต์ที่ 2)
cd ~/storygen-learning/02a_Image_Agent_Ready
ใช้ Gemini CLI เพื่อสร้างเอเจนต์การสร้างรูปภาพ
gemini generate "I need you to help me create a custom Google ADK (Agent Development Kit) agent for image generation. This is different from the story agent - this one handles image generation directly using the BaseAgent pattern for full control over tool execution.
Please create a complete `agent.py` file that implements a custom image generation agent. The agent should:
**Requirements:**
1. Use the `google.adk.agents.BaseAgent` class (NOT LlmAgent)
2. Be named "custom_image_agent"
3. Directly execute the ImagenTool without LLM intermediation
4. Handle JSON input with scene descriptions and character descriptions
5. Store results in session state for retrieval by main.py
6. Use async generators and yield Events
**Key Specifications:**
- **Class Name:** CustomImageAgent (inherits from BaseAgent)
- **Agent Name:** "custom_image_agent"
- **Tool:** Uses ImagenTool for direct image generation
- **Purpose:** Bypass LLM agent limitations and directly call ImagenTool
**Input Format:**
The agent should handle JSON input like:
{
"scene_description": "Scene action and setting",
"character_descriptions": {
"CharacterName": "detailed visual description"
}
}
**Core Method:** `async def _run_async_impl(self, ctx: InvocationContext) -> AsyncGenerator[Event, None]:`
- Extract user message from `ctx.user_content.parts`
- Parse JSON input or fallback to plain text
- Extract scene_description and character_descriptions
- Build image prompt with style prefix: "Children's book cartoon illustration with bright vibrant colors, simple shapes, friendly characters."
- Include character descriptions for consistency
- Call `await self.imagen_tool.run()` directly
- Store results in `ctx.session.state["image_result"]`
- Yield Event with results
**Session State:**
- Store JSON results in `ctx.session.state["image_result"]`
- Include success/error status
- Store actual image URLs or error messages
Expected Output Structure:
- Successful results stored as JSON with image URLs
- Error results stored as JSON with error messages
- Results accessible via session state in main.py
Can you create this agent in backend/story_image_agent/agent.py
"
—————————————— ไม่บังคับ คุณสามารถข้ามไปยังส่วนวิธีแก้ปัญหาได้——————————————–
ตอนนี้ให้ยืนยันการเปลี่ยนแปลงใน ADK Web
cd ~/storygen-learning/02a_Image_Agent_Ready/backend
source ../../.venv/bin/activate
adk web --port 8080
สร้างเว็บไซต์
cd ~/storygen-learning/02a_Second_Agent_Ready
./start.sh
หากการเปลี่ยนแปลงใช้ไม่ได้ คุณจะเห็นข้อผิดพลาดใน ADK Web UI และเว็บไซต์
—————————————— วิธีแก้ปัญหาเริ่มจากตรงนี้ ——————————————–
Solution
สิ้นสุดกระบวนการก่อนหน้าด้วย Control+C
หรือคุณจะเปิดเทอร์มินัลอื่นก็ได้
# Open new terminal
cd ~/storygen-learning/02b_Image_Agent_Done
สร้างเว็บไซต์:
./start.sh
คุณจะเห็นเว็บไซต์ดังนี้
ลองใช้ UI ของ ADK: เปิดเทอร์มินัลอื่น
# Open new terminal
cd ~/storygen-learning/02b_Image_Agent_Done/backend
source ../../.venv/bin/activate
adk web --port 8080
คุณจะเห็น UI ของ ADK ซึ่งคุณสามารถถามคำถามกับตัวแทนได้
ก่อนที่จะไปยังส่วนถัดไป ให้กด Ctrl+C เพื่อสิ้นสุดกระบวนการ
6. การทดสอบ: การประเมินตัวแทน
แอปของเราใช้งานได้ แต่เราต้องการระบบทดสอบที่ทำงานโดยอัตโนมัติเพื่อเป็นตาข่ายนิรภัย นี่คืองานที่เหมาะอย่างยิ่งที่จะมอบหมายให้ AI Co-Pilot ของเรา
การทำงาน
cd ~/storygen-learning/03a_Agent_Evaluation_Ready/backend
ใช้ Gemini CLI เพื่อเขียนการทดสอบที่ครอบคลุม
เปิด Gemini CLI
gemini
ลองใช้พรอมต์ต่อไปนี้ในหน้าต่าง Gemini CLI
I need you to create comprehensive test files for my backend/story_agent in Google ADK. I need three specific JSON files that match the testing structure used in ADK evaluation.
**Context:**
- The story agent generates structured JSON stories with exactly 4 scenes
- It uses LlmAgent with no tools, just direct LLM responses
- Input: Keywords
- Output: JSON with story, main_characters, and scenes arrays
**Files to Create:**
### 1. `story_agent_eval.evalset.json` (Comprehensive Integration Tests)
Create a comprehensive evaluation set with:
- **eval_set_id**: "story_agent_comprehensive_evalset"
- **name**: "Story Agent Comprehensive Evaluation Set"
- **description**: "Comprehensive evaluation scenarios for story_agent covering various keyword combinations, edge cases, and story quality metrics"
Each eval_case should include:
- Full conversation arrays with invocation_id, user_content, final_response
- Complete expected JSON responses with detailed stories, characters, and 4 scenes
- session_input with app_name "story_agent"
- All fields: story (narrative text), main_characters (with detailed visual descriptions), scenes (with index, title, description, text)
### 2. `story_generation.test.json` (Unit Tests)
Create basic generation tests with:
- **eval_set_id**: "story_agent_basic_generation_tests"
- **name**: "Story Agent Basic Generation Tests"
- **description**: "Unit tests for story_agent focusing on JSON structure compliance, scene generation, and keyword integration"
### 3. `test_config.json` (Evaluation Configuration)
Create test configuration with:
- **criteria**: response_match_score: 0.7, tool_trajectory_avg_score: 1.0
- **custom_evaluators**:
- json_structure_validator (validates required fields, scene count, character fields)
- story_quality_metrics (word count 80-250, keyword integration threshold 0.8)
- **evaluation_notes**: Story agent specifics and trajectory expectations
**Important Requirements:**
1. All responses must be valid, parseable JSON
2. Stories must have exactly 4 scenes with indices 1-4
3. Each scene must have: index, title, description, text
4. Main characters must have detailed visual descriptions
5. No tool_uses expected (empty arrays) since story agent uses direct LLM
6. Word count should be 100-200 words total
7. Keywords must be naturally integrated into the narrative
Please generate all three files with realistic example stories and comprehensive test coverage matching the ADK evaluation format.
—————————————— ไม่บังคับ คุณสามารถข้ามไปยังส่วนวิธีแก้ปัญหาได้——————————————–
วิธีดูการประเมิน
./run_adk_web_persistent.sh
ไปที่แท็บ eval
ใน UI ของ ADK
คุณควรเห็น UI เว็บของ ADK ที่มีความสามารถในการทดสอบอย่างต่อเนื่อง
ช่วงเวลาสำคัญในการเรียนรู้: AI เป็นพาร์ทเนอร์ที่มีประสิทธิภาพในการทำให้การประกันคุณภาพเป็นไปโดยอัตโนมัติ ซึ่งจะจัดการกับโค้ดมาตรฐานของการเขียนการทดสอบ ทำให้คุณมีเวลาไปมุ่งเน้นที่การสร้างฟีเจอร์
——————————————– วิธีแก้ปัญหาเริ่มต้นที่นี่ ——————————————–
Solution
- ไปที่โฟลเดอร์โซลูชัน
cd ~/storygen-learning/03b_Agent_Evaluation_Done/backend
- เปิด UI บนเว็บของ ADK
./run_adk_web_persistent.sh
คุณดูกรณีทดสอบได้จากแท็บ Eval
โดยทำดังนี้
ปรับเมตริกได้ที่นี่
ดูผลการเรียกใช้การประเมินที่นี่
7. โครงสร้างพื้นฐานเป็นโค้ด (IaC): การสร้างบ้านในระบบคลาวด์
โค้ดของเราผ่านการทดสอบแล้ว แต่ยังต้องการที่อยู่สำหรับใช้งานจริง เราจะใช้ "โครงสร้างพื้นฐานเป็นโค้ด" เพื่อกำหนดสภาพแวดล้อม
การทำงาน
cd ~/storygen-learning/04a_Manual_Deployment_Ready
ใช้ Gemini CLI เพื่อสร้าง Dockerfile สำหรับแบ็กเอนด์: เปิด Gemini CLI
Gemini
ลองใช้พรอมต์ต่อไปนี้ใน Gemini CLI
Create a manual deployment plan for my StoryGen app with Google Cloud Platform. I have a Next.js frontend, Python backend, and Terraform infrastructure.
Generate these deployment files:
1. **01-setup.sh** - Environment setup and authentication
2. **02-build-images.sh** - Build and push Docker images to Google Container Registry
3. **03-deploy-infrastructure.sh** - Deploy with Terraform and configure services
4. **load-env.sh** - Load environment variables for deployment
**Requirements:**
- Use Google Cloud Run for both frontend and backend
- Configure Imagen API and storage buckets
- Set up proper IAM permissions
- Use environment variables from .env file
- Include error handling and status checks
Keep scripts simple, well-commented, and production-ready for manual execution.
วิธีแก้ไข
cd ~/storygen-learning/04b_Manual_Deployment_Done
เรียกใช้
source ../.venv/bin/activate
./01-setup.sh
./02-build-images.sh
./03-deploy-infrastructure.sh
คุณควรเห็นผลการติดตั้งใช้งานและการสร้างโครงสร้างพื้นฐาน
8. การทำงานอัตโนมัติ (CI/CD): สายการประกอบดิจิทัล
การติดตั้งใช้งานแอปด้วยตนเองนั้นช้าและมีความเสี่ยง มาลองขอให้ AI เขียนไปป์ไลน์ CI/CD ที่สมบูรณ์โดยใช้ GitHub Actions กัน
การทำงาน
cd ~/storygen-learning/05a_CICD_Pipeline_Ready
ใช้ Gemini CLI เพื่อสร้างไปป์ไลน์ CI/CD ด้วย GitHub:
เปิด Gemini CLI
Gemini
ลองใช้พรอมต์ต่อไปนี้ใน Gemini CLI
Create a CI/CD pipeline for my StoryGen app using Google Cloud Build and GitHub integration.
Generate these automation files:
1. **cloudbuild.yaml** (for backend) - Automated build, test, and deploy pipeline
2. **GitHub Actions workflow** - Trigger builds on push/PR
3. **Deployment automation scripts** - Streamlined deployment process
**Requirements:**
- Auto-trigger on GitHub push to main branch
- Build and push Docker images
- Run automated tests if available
- Deploy to Google Cloud Run
- Environment-specific deployments (staging/prod)
- Notification on success/failure
Focus on fully automated deployment with minimal manual intervention. Include proper secret management and rollback capabilities.
——————————————– วิธีแก้ปัญหาเริ่มต้นที่นี่ ——————————————–
วิธีแก้ไข
cd ~/storygen-learning/06_Final_Solution/
# Copy the GitHub workflow to parent folder
cp -r 06_Final_Solution/.github ../../../.github
กลับไปที่โฟลเดอร์ 06_Final_Solution แล้วเรียกใช้สคริปต์
cd ~/storygen-learning/06_Final_Solution/
./setup-cicd-complete.sh
คุณควรเห็นการตั้งค่าไปป์ไลน์ CI/CD เสร็จสมบูรณ์
ทริกเกอร์เวิร์กโฟลว์: คอมมิตและพุชโค้ดไปยัง main โปรดทราบว่าคุณต้องตั้งค่าอีเมลและชื่อ GitHub เพื่ออนุญาตสิทธิ์
git add .
git commit -m "feat: Add backend, IaC, and CI/CD workflow"
git push origin main
ไปที่แท็บ "Actions" ในที่เก็บ GitHub เพื่อดูการทำงานของการติดตั้งใช้งานอัตโนมัติ
ช่วงเวลาสำคัญในการเรียนรู้: AI สามารถสร้างไปป์ไลน์ CI/CD ทั้งหมด ซึ่งเป็นส่วนที่ซับซ้อนและสำคัญของ DevOps ได้
9. การปฏิบัติงาน: AI Control Tower
เราพร้อมแล้ว แต่การเดินทางยังไม่สิ้นสุด นี่คือ "วันที่ 2" ซึ่งก็คือการปฏิบัติงาน กลับไปที่ Cloud Assist เพื่อจัดการแอปพลิเคชันที่กำลังทำงานกัน
การทำงาน
- ไปที่บริการ Cloud Run ในคอนโซล Google Cloud โต้ตอบกับแอปที่ใช้งานจริงเพื่อสร้างการเข้าชมและบันทึก
- เปิดแผง Cloud Assist แล้วใช้เป็นผู้ช่วยในการปฏิบัติงานด้วยพรอมต์ต่อไปนี้
การวิเคราะห์บันทึก:
Summarize the errors in my Cloud Run logs for the service 'genai-backend' from the last 15 minutes.
การเพิ่มประสิทธิภาพ:
My Cloud Run service 'genai-backend' has high startup latency. What are common causes for a Python app and how can I investigate with Cloud Trace?
การเพิ่มประสิทธิภาพต้นทุน:
Analyze the costs for my 'genai-backend' service and its GCS bucket. Are there any opportunities to save money?
ช่วงเวลาสำคัญในการเรียนรู้: SDLC ของ AI เป็นวงจรที่ต่อเนื่อง ผู้ช่วย AI คนเดียวกันที่ช่วยสร้างแอปพลิเคชันนี้เป็นพาร์ทเนอร์ที่ขาดไม่ได้สำหรับการตรวจสอบ การแก้ปัญหา และการเพิ่มประสิทธิภาพในเวอร์ชันที่ใช้งานจริง