본문 바로가기
AWS/ECS(Elastic Container Service)

Docker 를 이용해서 SonarQube 설치 및 SonarQube 이미지 Amazon ECR Repositories Upload 하기

by DBTechBiz 2022. 9. 21.

Docker 를 이용하여 SonarQube 설치 및 SonarQube 이미지 Amazon ECR Repositories 에 Upload 하기

SonarQube 이미지를 ECS 로 사용하기 위해 AWS ECR Repositories 에 업로드하기


1. Docker 를 이용하여 SonarQube 설치

  • 8.9.5-community 버전으로 설치하였으며 버전은 각 환경에 맞게 설정한다.
docker pull sonarqube:8.9.5-community

 

2. Docker 이미지 확인 및 SonarQube Container 실행

  • Amazon ECR Repositories 에 Upload 를 진행을 할 예정으로 따로 Optional settings 는 하지 않는다.

  • Container 이름을 클릭하면 Logs 를 확인할 수 있고 CLI 환경으로 접속할 수 있다.

 

3. Sonarqube Custom Ruleset 적용을 위한 Container ID 확인

  • Sonarqube Custom Ruleset 을 추가로 적용하기 위한 작업으로 추가 적용이 없을 경우는 3번과 4번 작업은 무시한다.
docker ps -a

 

4. Sonarqube Custom Ruleset 적용을 위한 SonarQube Container 에 룰셋 jar 파일 복사

  • SonarQube extension 폴더에 Custom Ruleset 복사한다.
docker cp checkstyle-sonar-plugin-4.29.jar 77d26847ec01:/opt/sonarqube/lib/extensions

  • 복사된 jar 파일 소유주, 권한을 변경한다.
chown sonarqube:sonarqube checkstyle-sonar-plugin-4.29.jar
chmod 644 checkstyle-sonar-plugin-4.29.jar

 

5. SonarQube 종료

 

6. Custom RuleSet 적용한 Docker Container 현 상태를 images 로 만들기

  • image 명을 sonarqube 로 하고 tag 명을 8.9.5-community-custom 으로 지정하였다.
docker ps -a
docker commit 77d26847ec01 sonarqube:8.9.5-community-custom
docker images

 

7. image(sonarqube:8.9.5-comminuty-custom) 를 AWS ECR 에 Push

  • AWS 화면은 보안 상 공유가 어려워 글로 적었으며, 아래의 메뉴를 따라가면 AWS 에서 제공하는 명령어를 통해 image Push 를 할 수 있다. (아래의 Sonarqube 리포지토리 영역은 각 환경에 맞는 위치를 선택하며 신규로 생성하는 경우는 "리포지토리 생성"을 클릭하여 새로 만든다.)

[AWS 웹 콘솔 → ECS(Elastic Container Service) → Amazon ECR 리포지토리 →
Sonarqube 리포지토리 이름(이미지를 Push할 위치) 클릭 → 푸시명령 보기]

  • 푸시명령 보기를 클릭하면 Docker 이미지를 Push 하기위한 명령어를 제공한다. 아래의 명령어는 저자가 "푸시명령 보기" 를 클릭했을 때 나오는 명령어로 1번~3번까지 순서대로 실행하면 ECR 리포지토리에 이미지가 Upload 된다.
1. Docker 클라이언트 인증
# 인증 토큰을 검색하고 레지스트리에 대해 Docker 클라이언트를 인증합니다.
# AWS CLI 사용:
 aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin 40338314583.dkr.ecr.ap-northeast-2.amazon.com
 
# 명령어가 정상적으로 동작했다고 하면 아래의 메시지가 표시된다.
# Login Succeeded
# Logging in with your password grants your terminal complete access to your account.

2. 리포지토리에 푸시할 수 있도록 이미지에 태크 지정
# 빌드가 완료되면 이미지에 태그를 지정하여 이 리포지토리에 푸시할 수 있습니다.
 docker tag sonarqube:8.9.5-community-custom 40338314583.dkr.ecr.ap-northeast-2.amazon.com/sonarqube:lastest
 
3. AWS 리포지토리로 푸시
# 다음 명령을 실행하여 이 이미지를 새로 생성한 AWS 리포지토리로 푸시합니다.
 docker push 40338314583.dkr.ecr.ap-northeast-2.amazon.com/sonarqube:lastest

 

8. Amazon ECR Repositories 에 Image가 정상적으로 올라갔는지 확인

 

9. 해당 Image 를 이용하여 SonarQube 를 ECS 로 기동

 

반응형

댓글