GitLab CI 구성 업데이트: 빌드 단계에 SonarQube 분석 추가 및 관련 설정 파일 생성

This commit is contained in:
2025-06-06 20:44:36 +09:00
parent 556a4f43a9
commit 2fabaf865a
4 changed files with 69 additions and 29 deletions

View File

@@ -7,6 +7,7 @@
# See https://docs.gitlab.com/ee/ci/variables/#cicd-variable-precedence # See https://docs.gitlab.com/ee/ci/variables/#cicd-variable-precedence
stages: stages:
- build - build
- build-sonar
- test - test
- deploy - deploy
- review - review
@@ -24,6 +25,7 @@ sast:
stage: test stage: test
include: include:
- template: Auto-DevOps.gitlab-ci.yml - template: Auto-DevOps.gitlab-ci.yml
- local: .gitlab/ci/*.gitlab-ci.yml
python_tests: python_tests:
stage: test stage: test

View File

@@ -0,0 +1,26 @@
image:
name: sonarsource/sonar-scanner-cli:11
entrypoint: [""]
variables:
SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar" # Defines the location of the analysis task cache
GIT_DEPTH: "0" # Tells git to fetch all the branches of the project, required by the analysis task
build-sonar:
stage: build-sonar
cache:
policy: pull-push
key: "sonar-cache-$CI_COMMIT_REF_SLUG"
paths:
- "${SONAR_USER_HOME}/cache"
- sonar-scanner/
script:
- sonar-scanner -Dsonar.host.url="${SONAR_HOST_URL}"
allow_failure: true
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
- if: $CI_COMMIT_BRANCH == 'master'
- if: $CI_COMMIT_BRANCH == 'main'
- if: $CI_COMMIT_BRANCH == 'develop'

View File

@@ -57,7 +57,9 @@ class PolicyBasedRoutingManager:
# 파일 내용에서 __version__ 라인 찾기 # 파일 내용에서 __version__ 라인 찾기
for line in response.text.splitlines(): for line in response.text.splitlines():
if "__version__" in line: if "__version__" in line:
match = re.search(r'__version__\s*=\s*["\'](\d+\.\d+\.\d+)["\']', line) match = re.search(
r'__version__\s*=\s*["\'](\d+\.\d+\.\d+)["\']', line
)
if match: if match:
return match.group(1) return match.group(1)
return None return None
@@ -72,7 +74,9 @@ class PolicyBasedRoutingManager:
current_version = __version__ current_version = __version__
if latest_version: if latest_version:
self.logger.info(f"현재 버전: {current_version}, 최신 버전: {latest_version}") self.logger.info(
f"현재 버전: {current_version}, 최신 버전: {latest_version}"
)
# 버전 비교 (간단한 문자열 비교, 실제로는 semantic versioning 라이브러리 사용 권장) # 버전 비교 (간단한 문자열 비교, 실제로는 semantic versioning 라이브러리 사용 권장)
if latest_version > current_version: if latest_version > current_version:
@@ -87,7 +91,9 @@ class PolicyBasedRoutingManager:
self.logger.info("현재 최신 버전을 사용 중입니다.") self.logger.info("현재 최신 버전을 사용 중입니다.")
return False return False
else: else:
self.logger.warning("최신 버전 정보를 가져올 수 없어 업데이트 확인을 건너뜁니다.") self.logger.warning(
"최신 버전 정보를 가져올 수 없어 업데이트 확인을 건너뜁니다."
)
return False return False
def perform_update(self): def perform_update(self):
@@ -101,7 +107,9 @@ class PolicyBasedRoutingManager:
current_script_path = Path(sys.argv[0]) # 현재 실행 중인 스크립트의 경로 current_script_path = Path(sys.argv[0]) # 현재 실행 중인 스크립트의 경로
# 현재 스크립트 파일을 백업 # 현재 스크립트 파일을 백업
backup_path = current_script_path.with_suffix(f".py.bak_{datetime.now().strftime('%Y%m%d%H%M%S')}") backup_path = current_script_path.with_suffix(
f".py.bak_{datetime.now().strftime('%Y%m%d%H%M%S')}"
)
current_script_path.rename(backup_path) current_script_path.rename(backup_path)
self.logger.info(f"현재 스크립트 백업 완료: {backup_path}") self.logger.info(f"현재 스크립트 백업 완료: {backup_path}")
@@ -112,7 +120,9 @@ class PolicyBasedRoutingManager:
# 실행 권한 유지 # 실행 권한 유지
current_script_path.chmod(0o755) current_script_path.chmod(0o755)
self.logger.info("스크립트 업데이트가 성공적으로 완료되었습니다. 스크립트를 다시 실행해주세요.") self.logger.info(
"스크립트 업데이트가 성공적으로 완료되었습니다. 스크립트를 다시 실행해주세요."
)
sys.exit(0) # 업데이트 후 스크립트 재시작을 위해 종료 sys.exit(0) # 업데이트 후 스크립트 재시작을 위해 종료
except requests.exceptions.RequestException as e: except requests.exceptions.RequestException as e:
self.logger.error(f"스크립트 다운로드 실패: {e}") self.logger.error(f"스크립트 다운로드 실패: {e}")

2
sonar-project.properties Normal file
View File

@@ -0,0 +1,2 @@
sonar.projectKey=dmslab_policy-routing_56aaf3b2-bfac-465c-8417-8c99edccf1c2
sonar.qualitygate.wait=true