Jenkins 통합
공식 Docker 컨테이너를 사용하여 Alpacon을 Jenkins 파이프라인에 통합합니다.
사전 요구사항
- Docker Pipeline 플러그인이 설치된 Jenkins
- Alpacon 워크스페이스 및 API 토큰
빠른 시작
1. Credentials 추가
Manage Jenkins → Credentials에서 다음을 추가하세요:
- ALPACON_WORKSPACE_URL:
https://your-workspace.us1.alpacon.io(Secret text) - ALPACON_API_TOKEN: API 토큰 (Secret text)
2. 파이프라인 생성
pipeline {
agent {
docker {
image 'alpacax/alpacon-cli:latest'
args '--entrypoint=""'
}
}
environment {
ALPACON_WORKSPACE_URL = credentials('ALPACON_WORKSPACE_URL')
ALPACON_API_TOKEN = credentials('ALPACON_API_TOKEN')
}
stages {
stage('Deploy') {
steps {
sh 'alpacon login $ALPACON_WORKSPACE_URL -t $ALPACON_API_TOKEN'
sh 'alpacon websh prod-server "cd /opt/myapp && git pull && pm2 restart app"'
}
}
}
}
중요: 컨테이너의 기본 entrypoint를 override하기 위해 args '--entrypoint=""'가 필요합니다.
사용 예시
애플리케이션 배포
pipeline {
agent {
docker {
image 'alpacax/alpacon-cli:latest'
args '--entrypoint=""'
}
}
environment {
ALPACON_WORKSPACE_URL = credentials('ALPACON_WORKSPACE_URL')
ALPACON_API_TOKEN = credentials('ALPACON_API_TOKEN')
TARGET_SERVER = 'prod-server'
}
stages {
stage('Deploy') {
steps {
sh 'alpacon login $ALPACON_WORKSPACE_URL -t $ALPACON_API_TOKEN'
sh 'alpacon websh $TARGET_SERVER "cd /opt/myapp && git pull origin main"'
sh 'alpacon websh $TARGET_SERVER "cd /opt/myapp && npm ci --omit=dev"'
sh 'alpacon websh $TARGET_SERVER "pm2 restart myapp"'
}
}
}
}
Root 권한으로 서비스 재시작
pipeline {
agent {
docker {
image 'alpacax/alpacon-cli:latest'
args '--entrypoint=""'
}
}
environment {
ALPACON_WORKSPACE_URL = credentials('ALPACON_WORKSPACE_URL')
ALPACON_API_TOKEN = credentials('ALPACON_API_TOKEN')
}
stages {
stage('Restart') {
steps {
sh 'alpacon login $ALPACON_WORKSPACE_URL -t $ALPACON_API_TOKEN'
sh 'alpacon websh root@prod-server "systemctl restart nginx"'
sh 'alpacon websh root@prod-server "systemctl status nginx"'
}
}
}
}
Docker Compose로 배포
pipeline {
agent {
docker {
image 'alpacax/alpacon-cli:latest'
args '--entrypoint=""'
}
}
environment {
ALPACON_WORKSPACE_URL = credentials('ALPACON_WORKSPACE_URL')
ALPACON_API_TOKEN = credentials('ALPACON_API_TOKEN')
}
stages {
stage('Deploy') {
steps {
sh 'alpacon login $ALPACON_WORKSPACE_URL -t $ALPACON_API_TOKEN'
sh 'alpacon cp docker-compose.yml prod-server:/opt/myapp/docker-compose.yml'
sh 'alpacon cp .env prod-server:/opt/myapp/.env'
sh 'alpacon websh root@prod-server "docker compose -f /opt/myapp/docker-compose.yml pull"'
sh 'alpacon websh root@prod-server "docker compose -f /opt/myapp/docker-compose.yml up -d"'
sh 'alpacon websh root@prod-server "docker compose -f /opt/myapp/docker-compose.yml ps"'
}
}
}
}
보안
Alpacon을 통해 실행된 모든 명령은 워크스페이스 감사 로그에 기록됩니다. 환경 변수를 통해 전달된 민감한 값(비밀번호, 토큰 등)은 명령 기록에서 자동으로 마스킹됩니다.
문제 해결
Entrypoint 오류
증상: Container doesn’t run the expected command
해결 방법: docker agent 설정에 args '--entrypoint=""'를 반드시 포함해야 합니다.