Pipeline
파이프라인
자동화된 작업 흐름. CI/CD 파이프라인이 대표적.
파이프라인
자동화된 작업 흐름. CI/CD 파이프라인이 대표적.
파이프라인(Pipeline)은 소프트웨어 개발에서 코드가 작성된 후 프로덕션 환경에 배포되기까지의 일련의 자동화된 단계들을 의미합니다. 각 단계는 순차적으로 또는 병렬로 실행되며, 한 단계가 실패하면 전체 파이프라인이 중단됩니다.
일반적인 CI/CD 파이프라인은 빌드(Build), 테스트(Test), 정적 분석(Lint), 보안 스캔(Security Scan), 스테이징 배포(Deploy to Staging), 통합 테스트(Integration Test), 프로덕션 배포(Deploy to Production) 단계로 구성됩니다. 평균적으로 7~10개의 단계를 거치며, 전체 실행 시간은 10~30분 정도입니다.
파이프라인은 DAG(Directed Acyclic Graph) 구조로 설계할 수 있어, 독립적인 작업은 병렬로 실행하여 전체 시간을 단축할 수 있습니다. 예를 들어 단위 테스트, 린트, 보안 스캔은 동시에 실행 가능합니다.
주요 파이프라인 도구로는 GitHub Actions, GitLab CI, Jenkins, CircleCI, ArgoCD 등이 있습니다. 최신 트렌드는 선언적(Declarative) 파이프라인으로, YAML 파일로 전체 워크플로우를 코드로 정의하여 버전 관리하고 재사용합니다.
# GitHub Actions CI/CD Pipeline
name: Production Deploy Pipeline
on:
push:
branches: [main]
pull_request:
branches: [main]
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
# 1단계: 빌드 및 테스트 (병렬 실행)
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: build
path: dist/
test:
runs-on: ubuntu-latest
needs: build
strategy:
matrix:
test-type: [unit, integration]
steps:
- uses: actions/checkout@v4
- name: Run ${{ matrix.test-type }} tests
run: npm run test:${{ matrix.test-type }}
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm ci
- run: npm run lint
security-scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
scan-type: 'fs'
severity: 'CRITICAL,HIGH'
# 2단계: Docker 이미지 빌드
docker-build:
runs-on: ubuntu-latest
needs: [test, lint, security-scan]
outputs:
image-tag: ${{ steps.meta.outputs.tags }}
steps:
- uses: actions/checkout@v4
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
# 3단계: 스테이징 배포
deploy-staging:
runs-on: ubuntu-latest
needs: docker-build
environment: staging
steps:
- name: Deploy to staging
run: |
kubectl set image deployment/app \
app=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }} \
--namespace=staging
# 4단계: 프로덕션 배포 (수동 승인 필요)
deploy-production:
runs-on: ubuntu-latest
needs: deploy-staging
environment:
name: production
url: https://app.example.com
steps:
- name: Deploy to production
run: |
kubectl set image deployment/app \
app=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }} \
--namespace=production
시니어: "이번 릴리스 파이프라인 실행 시간이 45분인데, 병렬화 가능한 단계 있는지 확인해볼까요?"
주니어: "분석해보니 lint, unit test, security scan이 순차 실행되고 있었어요. 병렬로 바꾸면 15분 정도 단축될 것 같습니다."
면접관: "CI/CD 파이프라인 구축 경험이 있으신가요?"
지원자: "GitHub Actions로 빌드-테스트-배포 파이프라인을 구축했습니다. 테스트 매트릭스로 Node 18/20 버전 동시 테스트, 캐싱으로 빌드 시간 50% 단축, 환경별 자동 배포를 구현했습니다."
리뷰어: "이 파이프라인, needs 의존성이 없어서 프로덕션 배포가 테스트 완료 전에 실행될 수 있어요."
개발자: "아, 놓쳤네요. deploy-production에 needs: [test, security-scan] 추가하겠습니다."