Infra/k8s
[CI/CD] Github Actions, Jenkins, ArgoCD로 CICD 파이프라인 구축
개발자 쿠키
2025. 8. 18. 00:03

시퀀스 다이어그램


GitHub Actions로 PR 빌드/검증 → Jenkins로 빌드, 이미지 푸시 → ArgoCD로 K8s 배포
1. Jenkins로 이미지 GHCR에 push
Jenkinsfile
pipeline {
agent any
options {
// 로그 타임스탬프, 워크스페이스 정리 등 선택 사항
timestamps()
skipDefaultCheckout(true)
}
environment {
// ---- 이미지/레지스트리 설정 ----
REGISTRY = 'ghcr.io'
OWNER = 'quoteline' // 깃허브 ORG/USER (반드시 소문자)
REPO = 'quoteline' // 이미지 이름 (소문자)
IMAGE = "${REGISTRY}/${OWNER}/${REPO}:${env.BUILD_NUMBER}"
LATEST = "${REGISTRY}/${OWNER}/${REPO}:latest"
// Jenkins 자격증명 ID (아래 2단계에서 만듭니다)
// - GitHub PAT로 GHCR 로그인 (Username with password)
REGISTRY_CREDENTIALS = credentials('registry-creds')
// 선택: 도커 빌드킷
DOCKER_BUILDKIT = '1'
}
stages {
stage('Checkout') {
steps {
// SCM(현재 브랜치) 체크아웃
checkout scm
}
}
stage('Build') {
steps {
sh 'chmod +x ./gradlew'
sh './gradlew clean build -x test'
}
}
stage('Docker Build') {
steps {
sh 'docker build -t ${IMAGE} -t ${LATEST} .'
}
}
stage('Docker Push') {
//when { branch 'main' }
environment { GH_PAT = credentials('github-token') }
steps {
// GHCR 로그인 후 푸시
sh 'echo ${REGISTRY_CREDENTIALS_PSW} | docker login ${REGISTRY} -u ${REGISTRY_CREDENTIALS_USR} --password-stdin'
sh 'docker push ${IMAGE}'
sh 'docker push ${LATEST}'
}
}
}
post {
always {
// 로그인 세션 정리 (실패해도 무시)
sh 'docker logout ${REGISTRY} || true'
}
}
}
Jenkins로 빌드 자동화 자세한 내용
https://cookie.tistory.com/152
Jenkins로 Build 자동화 설정
1. 프로젝트 위치 이동cd C:\Users\1stev\IdeaProjects\QuoteLine 2. Jenkins 컨테이너 실행mkdir jenkins_homedocker run --name jenkins -d -p 8080:8080 -p 50000:50000 ` -v ${PWD}\jenkins_home:/var/jenkins_home ` -u root jenkins/jenkins:lts-jdk17 3.
cookie.tistory.com
2. Github Actions Jenkins가 보낸 태그로 k8s manifest의 이미지 태그 업데이트
.github/worksflow/ci.yml
name: PR CI
on:
pull_request:
branches: [ main, develop, feat/** ]
push:
branches: [ main, develop, feat/** ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '17'
- name: Cache Gradle
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: ${{ runner.os }}-gradle-
- name: Build (no test or with test)
run: |
chmod +x ./gradlew
./gradlew clean build -x test
3. Argo CD
3-1. Namespace 생성
kubectl create namespace quoteline-dev
3-2. ArgoCD 설치 및 UI 접속
# ArgoCD 설치 (namespace: argocd)
kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
# ArgoCD 서비스 포트 포워딩
kubectl port-forward svc/argocd-server -n argocd 8080:443
# 비밀번호 찾는 방법
kubectl -n argocd get secret argocd-initial-admin-secret \
-o jsonpath="{.data.password}" | base64 -d; echo
3-3. GitOps 파이프라인 준비
- ArgoCD에서 Application 생성
- Github Repo 연결
argocd app create quoteline-server \
--repo https://github.com/사용자명/QuoteLine.git \
--path k8s \
--dest-server https://kubernetes.default.svc \
--dest-namespace quoteline-dev