Lesson 117 — Advanced

CI/CD with GitHub Actions

Commit se deploy tak ka raasta automate hona chahiye — warna release ek insaan ki yaad par chalegi. Is lesson mein hum tests → eval gate → build wala order, commit-tagged images, pipeline secrets, staging auto aur production manual approval, aur rollback ko redeploy banaana dekhenge.

⏱ 20 min• Advanced• Application Serving & Containerization

Pipeline kyun — order hi safety hai

Kya hai?

CI/CD matlab commit hote hi pipeline: unit tests, phir eval gate, phir image build aur registry push — har release wahi raasta chalti hai, koi manual shortcut nahi.

Kab kaam aata hai?

Pehle production deploy ke saath hi. Uske baad har change — code, prompt, config — isi pipeline se jaata hai; manual deploy exception ban jaata hai, rule nahi.

Kahan milta hai?

.github/workflows ki YAML file mein, runner jobs mein, aur registry (Docker Hub jaisa) mein push hue images ke roop mein.

Pipeline ka asli design decision order hai: sabse sasta check pehle (unit tests), phir mehnga (eval gate), phir build. Ulta kiya toh har chhoti typo ke liye bhi eval ka kharcha uthaoge. Aur yaad rakho — prompt change bhi isi pipeline se hi jaata hai, koi alag rasta nahi.

Mental model: Push → unit tests → eval gate → build & tag → registry → staging → approve → production. Ye line repo ki README mein likh do — naya member isi se samajh jaayega ki releases kaise chalti hain.

Workflow — tests, gate, build

# .github/workflows/ci.yml (conceptual)
name: ci
on:
  pull_request:
  push:
    branches: [main]

jobs:
  test-and-gate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Install pinned deps
        run: pip install -r requirements.txt
      - name: Unit tests
        run: pytest tests/unit -q
      - name: Eval gate (fast subset)
        run: pytest tests/eval -q
        env:
          PROVIDER_API_KEY: ${{ secrets.PROVIDER_API_KEY }}
      - name: Build image
        run: docker build -t registry.example/app:${{ github.sha }} ./backend
      - name: Push
        if: github.ref == "refs/heads/main"
        run: docker push registry.example/app:${{ github.sha }}
Gate ko protect karo: Branch protection rules on karo: main pe green pipeline bina merge nahi. Warna "ek chhota fix" kabhi bina gate ke chala jaayega — aur wahi fix kabhi kabhi production ka incident ban jaata hai.

Pipeline secrets

secret ka life-cycle:

banaya (dashboard/CLI) -> CI mein add -> workflow env se use
         |                                   |
         |                        print attempt -> masked logs
         |
rotate: naya banao -> CI update -> purana delete
         # aur: kabhi bhi log dump mein secret na dikhe — audit karke dekho
Rule: Secret repo mein aaya nahi — na YAML mein, na test fixture mein, na error message mein. Ek baar git history mein aa gaya toh history rewrite tak maamla hai; rotation hi sabse saaf fix hai.

Manual approval aur rollback-to-tag

push (main)
  -> tests -> eval gate -> image:${sha} push
  -> staging deploy (automatic, har main push)
  -> staging smoke + eval on live config
  -> approval gate (insaan)  --- reject? -> wapas ek fix commit
  -> production deploy (same image tag)

rollback = production ko image:${purana_sha} dobara deploy
           # rebuild nahi — wahi bit-for-bit image, known behaviour
Approval ka matlab: Manual approval ek rubber stamp nahi hai — eval report padhna, diff dekhna, phir approve. Ye 5 minute ka insaani review tumhara last line of defense hai; bina context ke approve karne wala koi bhi gate hawa jaisa hai.

Exercise

Question: Pipeline mein pehle chalte hain — unit tests ya eval gate?

Question: Image ko kis cheez se tag karte hain taaki code aur image ka rishta clear ho? (commit sha / date)

Question: Fork wale pull request ko provider keys dena safe hai ya nahi?

Question: Rollback ka sahi tareeka — purana tag redeploy ya naya build?

Common mistakes

Desi example: Cinema ke release prints

Film ka final print (image) ek baar banta hai, censor certificate (gate) lagta hai, phir same print har theatre mein (staging se production) jaata hai. Kharab screening ho toh same print wapas — naya print banane se picture nahi badlegi:

text
print bana (build, tag: commit sha)
censor pass (tests + gate)
premiere (staging auto)
insaani approval (manual gate)
release (same print, production)
recall (rollback = purana print dobara)
Interview angle — yahan se sawaal aate hain
  • Q: LLM app ki CI pipeline ka order kya hona chahiye? — Unit tests → eval gate → image build → registry push; staging auto, production approval ke baad.
  • Q: Prompt change bhi pipeline se kyun? — Prompt = release component; same gate guarantees ki bina eval ke koi behaviour change production nahi pahunchta.
  • Q: Image tagging strategy? — Commit SHA; har deploy traceable ki kaunse code se bana, aur rollback ke liye known tag hamesha available.
  • Q: Rollback kaise? — Purane known tag ki image dobara deploy — rebuild nahi; isi liye purane images retain karte hain.
Lesson complete?

Commit se image tak ka raasta automatic hai, approval ke saath. Agla lesson — Deployment on AWS — mein ye images cloud pe health-checked releases ke saath deploy karenge.

Popular courses: Data Science Course in Lucknow · AI Course in Lucknow · Python Course in Lucknow · Power BI Course · Data Analytics Course