개요
Martin Fowler는 Continuous Integration을 팀원 각자가 변경 사항을 최소 하루에 한 번 이상 공유 codebase에 merge하는 개발 방식으로 설명하고, 각 integration을 테스트를 포함한 automated build로 검증해 통합 오류를 가능한 한 빨리 찾는다고 설명합니다 (https://martinfowler.com/articles/continuousIntegration.html). Continuous Delivery는 소프트웨어를 언제든 프로덕션에 release할 수 있도록 만드는 개발 방식입니다 (https://martinfowler.com/bliki/ContinuousDelivery.html).
이 글에서는 도구와 무관한 CI/CD 개념, 파이프라인 구조, 환경 분리, Secrets 관리, Jenkins와 GitLab CI 비교, 파이프라인 디버깅을 정리합니다.
1. CI와 CD는 뭐가 다른가
상세 내용
CI (Continuous Integration)
Martin Fowler의 정의에 따르면 CI에서는 각 integration을 테스트를 포함한 automated build로 검증합니다 (https://martinfowler.com/articles/continuousIntegration.html). 파이프라인에 어떤 검사 단계를 넣을지는 팀이 정하며, 린트나 보안 스캔 단계를 추가하는 구성도 가능합니다.
CD (Continuous Delivery / Continuous Deployment)
AWS 문서는 continuous delivery 파이프라인을 소스 변경이 build, test를 거쳐 non-production 테스트 또는 staging 환경에 배포되는 흐름으로 설명하고, continuous delivery와 continuous deployment의 차이를 프로덕션 배포 전 manual approval이 있는지 여부로 설명합니다 (https://aws.amazon.com/devops/continuous-delivery/).
| 용어 | 차이 |
|---|---|
| Continuous Delivery | 프로덕션 배포 전에 manual approval이 있음 |
| Continuous Deployment | 승인 없이 프로덕션까지 자동 배포 |
Martin Fowler는 Continuous Deployment를 모든 변경이 파이프라인을 거쳐 자동으로 프로덕션에 배포되는 방식으로 설명합니다. Continuous Delivery는 빈번한 배포를 할 수 있는 상태를 뜻하며, 배포 여부는 팀이 선택할 수 있다고 설명합니다 (https://martinfowler.com/bliki/ContinuousDelivery.html).
흐름 예시
개발자 push
→ CI: 빌드 → 테스트 → 이미지 생성 → Registry push
→ CD: dev 자동 배포 → stg 자동 배포 → prod 수동 승인 후 배포2. 파이프라인 구조
상세 내용
파이프라인 = 스테이지의 연속
┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐
│ Build │ → │ Test │ → │ Deploy │ → │ Notify │
│ (빌드) │ │ (테스트) │ │ (배포) │ │ (알림) │
└──────────┘ └──────────┘ └──────────┘ └──────────┘GitLab CI/CD 문서에서 stage는 job을 묶는 단위입니다. stage는 순서대로 실행되고 같은 stage의 job은 병렬로 실행됩니다. stage의 모든 job이 성공하면 파이프라인이 다음 stage로 넘어가고, stage의 job이 하나라도 실패하면 다음 stage는 (보통) 실행되지 않고 파이프라인이 일찍 끝납니다 (https://docs.gitlab.com/ci/pipelines/).
스테이지 구성 예시
| 스테이지 | 하는 일 | 예시 |
|---|---|---|
| Checkout | 코드 가져오기 | git clone |
| Build | 빌드/컴파일 | npm run build, docker build |
| Test | 테스트 실행 | pytest, jest |
| Lint | 코드 품질 검사 | eslint, flake8 |
| Scan | 보안 취약점 스캔 | trivy, snyk |
| Push | 이미지를 Registry에 업로드 | docker push |
| Deploy | 환경에 배포 | kubectl apply, helm upgrade |
| Notify | 결과 알림 | Slack, 이메일 |
트리거
| 실행 조건 | GitHub Actions | GitLab CI/CD |
|---|---|---|
| 정해진 시간 | schedule event |
pipeline schedule |
| 수동 실행 | workflow_dispatch event |
when: manual로 지정한 manual job (프로덕션 배포 같은 job에 사용할 수 있다고 문서에 설명) |
GitHub Actions는 workflow를 trigger하는 event를 on에 지정합니다 (https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows). GitLab CI/CD의 manual job은 사용자가 시작해야만 실행되는 job입니다 (https://docs.gitlab.com/ci/jobs/job_control/). GitLab의 pipeline schedule은 https://docs.gitlab.com/ci/pipelines/schedules/ 에 설명되어 있습니다.
3. 환경 분리 (dev / stg / prod)
상세 내용
환경(environment)
GitHub Actions 문서에서 environment는 production, staging, development 같은 배포 대상을 나타내는 용도입니다. environment를 사용하면 job 진행에 승인을 요구하거나, workflow를 trigger할 수 있는 branch를 제한하거나, secret에 대한 접근을 제한할 수 있습니다 (https://docs.github.com/en/actions/concepts/workflows-and-actions/deployment-environments). required reviewers 같은 deployment protection rule은 사용하는 플랜과 repository 공개 여부에 따라 제공 범위가 다릅니다 (https://docs.github.com/en/actions/how-tos/deploy/configure-and-manage-deployments/manage-environments).
환경 구성 예시
| 환경 | 용도 | 배포 방식 |
|---|---|---|
| dev | 개발 중인 변경 확인 | push 시 자동 배포 |
| stg (staging) | 프로덕션 배포 전 검증 | dev 이후 자동 또는 수동 |
| prod (production) | 실제 서비스 | 수동 승인 후 배포 |
브랜치 전략 연결 예시
feature/* → develop 브랜치 → dev 환경 자동 배포
develop → main(또는 release) 브랜치 → stg 환경 배포
main + 태그 → prod 환경 배포 (수동 승인)환경별 설정 분리 예시
방법 1: 환경변수로 분리
- dev: DB_HOST=dev-db.internal
- prod: DB_HOST=prod-db.internal
방법 2: 설정 파일 분리
- config/dev.yaml
- config/prod.yaml
방법 3: Helm values 분리 (K8s)
- values-dev.yaml
- values-prod.yamlHelm은 helm install의 --values(-f) 옵션으로 values 파일을 지정할 수 있습니다 (https://helm.sh/docs/helm/helm_install/).
4. Secrets 관리
상세 내용
Secrets = DB 비밀번호, API 키, 인증서처럼 민감한 값
Kubernetes 문서는 Secret을 password, token, key 같은 소량의 민감한 데이터를 담는 오브젝트로 설명하고, Secret을 쓰면 애플리케이션 코드에 기밀 데이터를 넣지 않아도 된다고 설명합니다 (https://kubernetes.io/docs/concepts/configuration/secret/).
저장소에 secret을 커밋한 경우 GitHub 문서는 먼저 해당 secret을 revoke하거나 rotate하라고 안내합니다. revoke 또는 rotate한 secret은 더 이상 접근에 쓸 수 없고, 이것으로 충분할 수 있다고 설명합니다. 히스토리를 재작성해 제거하는 방법에는 재오염(recontamination) 위험 등 여러 부작용이 있다고 설명합니다 (https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/removing-sensitive-data-from-a-repository).
도구별 Secrets 관리
| 도구 | 방법 |
|---|---|
| Jenkins | Jenkins에 저장한 credentials를 Pipeline에서 사용. 전역, 특정 Pipeline 프로젝트, 특정 사용자 단위로 사용할 수 있음 (https://www.jenkins.io/doc/book/using/using-credentials/) |
| GitLab CI | CI/CD variable로 등록. variable을 mask하면 job log에 값이 출력되지 않고 [MASKED]로 대체됨 (https://docs.gitlab.com/ci/variables/) |
| GitHub Actions | repository, environment, organization 수준에서 secret 생성 (https://docs.github.com/en/actions/security-for-github-actions/security-guides/using-secrets-in-github-actions) |
| Kubernetes | Secret 오브젝트 |
GitHub Actions에서는 ${{ secrets.NAME }}으로 secret을 참조합니다. 워크플로가 fork된 repository에서 trigger되면 GITHUB_TOKEN을 제외한 secret은 runner로 전달되지 않습니다. 클라우드 제공자에 접근해야 하는 경우 OpenID Connect(OIDC)를 사용하면 workflow가 클라우드 제공자로부터 short-lived token을 직접 받아 자격증명을 long-lived secret으로 저장하지 않아도 됩니다 (https://docs.github.com/en/actions/concepts/security/openid-connect).
GitLab 문서는 variable masking이 악의적인 사용자의 variable 값 접근을 막는 보장된 방법은 아니라고 설명합니다 (https://docs.gitlab.com/ci/variables/).
외부 Secrets Manager
| 도구 | 특징 |
|---|---|
| AWS Secrets Manager | database credential, API key 등의 secret을 수명 주기 전반에 걸쳐 관리, 조회, rotate. 자동 rotation 일정을 설정할 수 있음 (https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html) |
| AWS Systems Manager Parameter Store | standard tier는 계정·Region당 최대 10,000개 parameter, 값 최대 4 KB, 추가 요금 없음. advanced tier는 최대 100,000개, 값 최대 8 KB, 요금 부과 (https://docs.aws.amazon.com/systems-manager/latest/userguide/parameter-store-advanced-parameters.html) |
| HashiCorp Vault | on-premises, 클라우드, 하이브리드 환경에서 privileged access와 secret을 중앙에서 관리 (https://developer.hashicorp.com/vault/docs/about-vault/what-is-vault) |
5. 도구 비교 — Jenkins vs GitLab CI
상세 내용
| 항목 | Jenkins | GitLab CI/CD |
|---|---|---|
| 파이프라인 정의 파일 | Jenkinsfile | .gitlab-ci.yml |
| 작업 실행 주체 | agent가 controller의 지시에 따라 작업 실행 | runner |
| 기능 확장 | plugin 설치 | CI/CD components 등 |
Jenkins glossary에서 agent는 보통 Jenkins controller에 연결되어 controller의 지시에 따라 작업을 실행하는 머신 또는 컨테이너이고, controller는 설정을 저장하고 plugin을 로드하며 UI를 제공하는 중앙 조정 프로세스입니다. built-in node는 Jenkins 2.307 이전에 “master node"로 불렸고, 같은 문서는 build를 built-in node가 아닌 agent에서 실행하길 권장합니다 (https://www.jenkins.io/doc/book/glossary/).
Jenkinsfile은 Pipeline 정의를 담는 파일이며 Declarative Pipeline과 Scripted Pipeline 두 문법을 사용합니다 (https://www.jenkins.io/doc/book/pipeline/jenkinsfile/). GitLab runner는 job을 실행하는 주체이고 GitLab 문서는 runner 구성을 https://docs.gitlab.com/ci/runners/ 에서, CI/CD component를 https://docs.gitlab.com/ci/components/ 에서 설명합니다.
6. 파이프라인 구성
상세 내용
파이프라인 실행 시간
- GitLab CI/CD에서 stage는 순서대로 실행되고 같은 stage의 job은 병렬로 실행됩니다 (https://docs.gitlab.com/ci/pipelines/).
- GitLab CI/CD의 cache는 job이 내려받아 저장한 파일입니다. 같은 cache를 쓰는 이후 job은 그 파일을 다시 내려받지 않아도 되므로 더 빨리 실행됩니다 (https://docs.gitlab.com/ci/caching/).
- GitHub Actions는 dependency caching 기능을 제공합니다 (https://docs.github.com/en/actions/reference/workflows-and-actions/dependency-caching).
실패 알림
- GitLab의 Slack notifications integration은 GitLab 15.9에서 deprecated되었고, 문서는 GitLab for Slack app을 사용하라고 안내합니다 (https://docs.gitlab.com/user/project/integrations/slack/).
- GitHub Actions는 이메일 또는 웹 알림을 켜면 사용자가 trigger한 workflow run이 끝났을 때 알림을 받습니다. 알림에는 성공, 실패, neutral, canceled 같은 run 상태가 포함됩니다 (https://docs.github.com/en/actions/concepts/workflows-and-actions/notifications-for-workflow-runs).
빌드 환경
- GitLab CI/CD의
image키워드로 job을 실행할 Docker image를 지정할 수 있습니다 (https://docs.gitlab.com/ci/docker/using_docker_images/). - GitHub Actions에서는 job을 컨테이너 안에서 실행하도록 지정할 수 있습니다 (https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax).
이미지 태그
GitLab은 predefined variable CI_COMMIT_SHA(빌드 대상 commit revision)와, 그 앞 8자인 CI_COMMIT_SHORT_SHA를 제공합니다 (https://docs.gitlab.com/ci/variables/predefined_variables/). 이 값을 이미지 태그에 쓰면 태그로 빌드된 commit을 식별할 수 있습니다.
이미지 태그 예시:
myapp:abc123f9 (commit SHA 앞 8자, GitLab CI_COMMIT_SHORT_SHA 형식)
myapp:v1.2.3 (릴리즈 태그)시크릿과 이미지
- GitLab CI/CD에서 masked variable 값이 job log에 출력되면
[MASKED]로 대체됩니다 (https://docs.gitlab.com/ci/variables/). - GitHub Actions 문서는 GitHub secret이 아닌 민감 정보에
::add-mask::VALUE를 쓰면 값이 secret처럼 취급되어 log에서 redact된다고 설명합니다 (https://docs.github.com/en/actions/security-for-github-actions/security-guides/using-secrets-in-github-actions). - Docker 문서에 따르면 multi-stage build에서는 한 stage의 artifact만 선택해 다음 stage로 복사하고, 최종 image에 원하지 않는 것은 남기지 않을 수 있습니다 (https://docs.docker.com/build/building/multi-stage/).
7. 파이프라인 디버깅
상세 내용
디버깅 방법
- Jenkins: Replay 기능으로 기존 Pipeline을 수정해 바로 다시 실행할 수 있습니다 (https://www.jenkins.io/doc/book/pipeline/development/).
- Jenkins: Jenkins CLI 명령이나 HTTP POST 요청으로 Declarative Pipeline을 실행 전에 lint할 수 있습니다 (https://www.jenkins.io/doc/book/pipeline/development/).
- GitLab CI: 실패한 job은 job 페이지에서 retry할 수 있습니다 (https://docs.gitlab.com/ci/jobs/).
- GitLab CI: CI Lint 도구는 CI/CD 설정의 문법과 로직 오류를 검사하고, pipeline creation을 simulate해
needs와rules설정 문제 같은 더 복잡한 문제를 찾을 수 있습니다. 파이프라인 에디터를 쓰면 설정이 자동으로 검증됩니다 (https://docs.gitlab.com/ci/yaml/lint/). - GitLab Runner:
gitlab-runner exec명령은 GitLab Runner changelog 기준으로 15.6.1에서 deprecated 표기가 추가되었고 17.0.0에서 제거되었습니다 (https://gitlab.com/gitlab-org/gitlab-runner/-/blob/main/CHANGELOG.md). 현재 명령 목록은 https://docs.gitlab.com/runner/commands/ 에서 확인할 수 있습니다. - GitHub Actions: 서드파티 오픈소스 프로젝트
act는 GitHub Actions를 로컬에서 실행하는 도구로 소개됩니다 (https://github.com/nektos/act). GitHub 공식 도구는 아닙니다.