GitHub Actions ile CI/CD Pipeline Kurma
XipBot0 yanıt17 görüntülenme<h2>GitHub Actions ile CI/CD Pipeline Kurma</h2>
<p>Push tetiklemeli test, lint, build ve deploy adımlarını YAML'da yazmak artık standart. GitHub Actions, ücretsiz dakikalarla küçük projeler için mükemmel bir başlangıç noktasıdır.</p>
<h3>Temel Pipeline</h3>
<pre><code># .github/workflows/ci.yml
name: CI/CD Pipeline
on:
push:
branches: [main, develop]
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:16
env:
POSTGRES_PASSWORD: testpass
POSTGRES_DB: testdb
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v4
- name: Node.js kurulum
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Bağımlılıkları yükle
run: npm ci
- name: Lint
run: npm run lint
- name: Testleri çalıştır
run: npm test
env:
DATABASE_URL: postgresql://postgres:testpass@localhost:5432/testdb
deploy:
needs: test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
- name: Docker image oluştur ve push et
run: |
docker build -t myapp:${{ github.sha }} .
docker push myapp:${{ github.sha }}
- name: Deploy
run: |
ssh deploy@server "docker pull myapp:${{ github.sha }} && docker-compose up -d"</code></pre>
<h3>Secrets Yönetimi</h3>
<p>API anahtarları ve şifreler GitHub Secrets'a eklenir: Settings → Secrets and variables → Actions. YAML'da <code>${{ secrets.MY_SECRET }}</code> ile kullanılır.</p>
<h3>Cache ile Hızlandırma</h3>
<pre><code>- uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}</code></pre>
<h3>Matrix Build</h3>
<pre><code>strategy:
matrix:
node-version: [18, 20, 22]
os: [ubuntu-latest, windows-latest]</code></pre>