mirror of
https://github.com/jung-geun/policy-routing.git
synced 2025-12-20 02:34:39 +09:00
GitLab CI 구성 업데이트: 빌드 단계에 SonarQube 분석 추가 및 관련 설정 파일 생성
This commit is contained in:
@@ -6,24 +6,26 @@
|
|||||||
# Note that environment variables can be set in several places
|
# Note that environment variables can be set in several places
|
||||||
# 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
|
||||||
- test
|
- build-sonar
|
||||||
- deploy
|
- test
|
||||||
- review
|
- deploy
|
||||||
- dast
|
- review
|
||||||
- staging
|
- dast
|
||||||
- canary
|
- staging
|
||||||
- production
|
- canary
|
||||||
- incremental rollout 10%
|
- production
|
||||||
- incremental rollout 25%
|
- incremental rollout 10%
|
||||||
- incremental rollout 50%
|
- incremental rollout 25%
|
||||||
- incremental rollout 100%
|
- incremental rollout 50%
|
||||||
- performance
|
- incremental rollout 100%
|
||||||
- cleanup
|
- performance
|
||||||
|
- cleanup
|
||||||
sast:
|
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
|
||||||
|
|||||||
26
.gitlab/ci/sonarqube.gitlab-ci.yml
Normal file
26
.gitlab/ci/sonarqube.gitlab-ci.yml
Normal 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'
|
||||||
@@ -4,7 +4,7 @@ Ubuntu 22.04 Multi-NIC Policy Based Routing Setup Script
|
|||||||
Python Implementation
|
Python Implementation
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__version__ = "0.3" # 현재 스크립트 버전
|
__version__ = "0.3" # 현재 스크립트 버전
|
||||||
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import logging
|
import logging
|
||||||
@@ -15,7 +15,7 @@ import re
|
|||||||
import ipaddress
|
import ipaddress
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import requests # requests 라이브러리 추가
|
import requests # requests 라이브러리 추가
|
||||||
|
|
||||||
|
|
||||||
class PolicyBasedRoutingManager:
|
class PolicyBasedRoutingManager:
|
||||||
@@ -52,12 +52,14 @@ class PolicyBasedRoutingManager:
|
|||||||
"""GitHub에서 최신 버전 정보 가져오기"""
|
"""GitHub에서 최신 버전 정보 가져오기"""
|
||||||
try:
|
try:
|
||||||
response = requests.get(self.github_repo_url)
|
response = requests.get(self.github_repo_url)
|
||||||
response.raise_for_status() # HTTP 오류 발생 시 예외 발생
|
response.raise_for_status() # HTTP 오류 발생 시 예외 발생
|
||||||
|
|
||||||
# 파일 내용에서 __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):
|
||||||
@@ -95,13 +101,15 @@ class PolicyBasedRoutingManager:
|
|||||||
self.logger.info("스크립트 업데이트를 시작합니다...")
|
self.logger.info("스크립트 업데이트를 시작합니다...")
|
||||||
try:
|
try:
|
||||||
response = requests.get(self.github_repo_url)
|
response = requests.get(self.github_repo_url)
|
||||||
response.raise_for_status() # HTTP 오류 발생 시 예외 발생
|
response.raise_for_status() # HTTP 오류 발생 시 예외 발생
|
||||||
|
|
||||||
script_content = response.text
|
script_content = response.text
|
||||||
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,8 +120,10 @@ 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}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
2
sonar-project.properties
Normal file
2
sonar-project.properties
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
sonar.projectKey=dmslab_policy-routing_56aaf3b2-bfac-465c-8417-8c99edccf1c2
|
||||||
|
sonar.qualitygate.wait=true
|
||||||
Reference in New Issue
Block a user