카이도스의 Tech Blog

Jenkins를 이용한 CI/CD Pipeline - 3 본문

CI CD

Jenkins를 이용한 CI/CD Pipeline - 3

카이도스 2025. 2. 6. 14:12
728x90
반응형

2025.01.23 - [CI CD] - Jenkins를 이용한 CI/CD Pipeline - 1

 

Jenkins를 이용한 CI/CD Pipeline - 1

실습 구성 : VM Spec - vCPU 8, RAM 16GiB설치 및 설정 : Docker 로 설치# 이미지 가져오기docker pull jenkins/jenkinsdocker history jenkins/jenkins --format json --no-trunc | jq# 확인docker images | grep -i jenkinsjenkins/jenkins latest fe1

djdakf1234.tistory.com

2025.01.24 - [CI CD] - Jenkins를 이용한 CI/CD Pipeline - 2

 

Jenkins를 이용한 CI/CD Pipeline - 2

2025.01.23 - [CI CD] - Jenkins를 이용한 CI/CD Pipeline - 1 Jenkins를 이용한 CI/CD Pipeline - 1실습 구성 : VM Spec - vCPU 8, RAM 16GiB설치 및 설정 : Docker 로 설치# 이미지 가져오기docker pull jenkins/jenkinsdocker history jenkins

djdakf1234.tistory.com


Jenkins Job : Item My-Third-Project , maven

- 빌드 전 확인

watch -d "docker exec -it tomcat ls -l /usr/local/tomcat/webapps"
  • General : Deploy the Second project on Tomcat
  • 소스 코드 관리 : Git → Repo URL https://github.com/joneconsulting/cicd-web-project
  • Build : Root POM(pom.xml) , Goals and options (clean compile package)
  • Post-build Actions 빌드 후 조치 : Deploy war/ear to a container , files(**/*.war)

- Add Container 클릭 후 Tomcat 9.x Remote 계정 정보 입력

  • Username : deployer
  • Password : deployer
  • ID : deployer_user1
  • Description : user to deploy on tomcat

- 자신의 톰켓(컨테이너) 접속 주소 입력 : http://IP:8081/
→ Apply 후 저장 ⇒ 지금 빌드 후 확인

#
docker exec -it tomcat ls -l /usr/local/tomcat/webapps
total 7844
drwxr-xr-x 16 ubuntu ubuntu    4096 Jan 22 19:35 docs
drwxr-xr-x  7 ubuntu ubuntu      99 Jan 22 19:35 examples
drwxr-x---  4 root   root        37 Jan 23 04:02 hello-world
-rw-r-----  1 root   root   8025995 Jan 23 04:02 hello-world.war
drwxr-xr-x  6 ubuntu ubuntu      79 Jan 22 19:35 host-manager
drwxr-xr-x  6 ubuntu ubuntu     114 Jan 22 19:35 manager
drwxr-xr-x  3 ubuntu ubuntu     223 Jan 22 19:35 ROOT

docker exec -it tomcat ls -l /usr/local/tomcat/webapps/hello-world
total 0
drwxr-x--- 3 root root 57 Jan 23 04:02 META-INF
drwxr-x--- 5 root root 60 Jan 23 04:02 WEB-INF

- 콘솔 출력 확인

[INFO] --- maven-war-plugin:3.2.2:war (default-war) @ web ---
[INFO] Packaging webapp
[INFO] Assembling webapp [web] in [/var/jenkins_home/workspace/My-Third-Project/target/hello-world]
[INFO] Processing war project
[INFO] Copying webapp resources [/var/jenkins_home/workspace/My-Third-Project/src/main/webapp]
[INFO] Webapp assembled in [22 msecs]
[INFO] Building war: /var/jenkins_home/workspace/My-Third-Project/target/hello-world.war
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  5.483 s
[INFO] Finished at: 2025-01-23T04:02:16Z
[INFO] ------------------------------------------------------------------------
Waiting for Jenkins to finish collecting data
[JENKINS] Archiving /var/jenkins_home/workspace/My-Third-Project/pom.xml to com.njonecompany.web/web/1.0/web-1.0.pom
[JENKINS] Archiving /var/jenkins_home/workspace/My-Third-Project/target/hello-world.war to com.njonecompany.web/web/1.0/web-1.0.war
channel stopped
[DeployPublisher][INFO] Attempting to deploy 1 war file(s)
[DeployPublisher][INFO] Deploying /var/jenkins_home/workspace/My-Third-Project/target/hello-world.war to container Tomcat 9.x Remote with context null
  [/var/jenkins_home/workspace/My-Third-Project/target/hello-world.war] is not deployed. Doing a fresh deployment.
  Deploying [/var/jenkins_home/workspace/My-Third-Project/target/hello-world.war]
Finished: SUCCESS

#
ip -br -4 addr show dev eth0 | awk '{print $3}' | cut -d '/' -f1 | awk '{ print "App = http://"$1":8081/hello-world" }'
ip -br -4 addr show dev ens18 | awk '{print $3}' | cut -d '/' -f1 | awk '{ print "App = http://"$1":8081/hello-world" }'

- 웹 접속 후 확인 : http://VM_IP:8081/hello-world

- Tomcat 웹 애플리케이션 매니져 확인


사전 준비 : Dockerfile 작성, tomcat 컨테이너 중지 및 삭제

# Dockerfile 작성
cat << EOT > Dockerfile
FROM tomcat:9.0
LABEL org.opencontainers.image.authors="a@a.com"
COPY ./hello-world.war /usr/local/tomcat/webapps
EOT

# tomcat 컨테이너 중지 및 삭제
docker rm -f tomcat

pulish over ssh

plugins → available → publish over ssh 설치

- 관리 → System → Add SSH Servers 클릭 : 고급 선택 후 ‘Use password authentication..’ 체크 후 아래 입력 ⇒ Test Configuration 확인

- Apply 후 저장

- Item : My-Docker-Project , Copy from ( My-Third-Project )

- 빌드 전 확인

# 도커 이미지 확인 : cicd-project 없음 확인
docker images
REPOSITORY        TAG       IMAGE ID       CREATED        SIZE
jenkins/jenkins   latest    fe12c0bbe82f   37 hours ago   466MB
tomcat            9.0       39ad0bf0ff89   2 weeks ago    469MB

# Tomcat 컨테이너 없음 확인
docker ps 
CONTAINER ID   IMAGE             COMMAND                  CREATED          STATUS          PORTS                                                                                      NAMES
dc15a8b5563c   jenkins/jenkins   "/usr/bin/tini -- /u…"   39 minutes ago   Up 39 minutes   0.0.0.0:8080->8080/tcp, :::8080->8080/tcp, 0.0.0.0:50000->50000/tcp, :::50000->50000/tcp   jenkins-server

# 모니터링
watch -d "docker images; echo; docker ps"

- Project → Configure → Post Built Actions : Exec command

docker build --tag=cicd-project -f Dockerfile .;
docker run -d -p 8081:8080 --name mytomcat cicd-project:latest

- Apply 후 저장 → 지금 빌드 후 확인

#
docker images
REPOSITORY        TAG       IMAGE ID       CREATED              SIZE
cicd-project      latest    f810dc24e85b   About a minute ago   477MB
...

#
docker ps
CONTAINER ID   IMAGE                 COMMAND                  CREATED         STATUS          PORTS                                                                                      NAMES
55bad111bb8e   cicd-project:latest   "catalina.sh run"        2 minutes ago   Up 2 minutes    0.0.0.0:8081->8080/tcp, [::]:8081->8080/tcp                                                mytomcat
...

# 접속 확인
ip -br -4 addr show dev eth0 | awk '{print $3}' | cut -d '/' -f1 | awk '{ print "App = http://"$1":8081/hello-world" }'
ip -br -4 addr show dev ens18 | awk '{print $3}' | cut -d '/' -f1 | awk '{ print "App = http://"$1":8081/hello-world" }'
728x90
반응형

'CI CD' 카테고리의 다른 글

Jenkins를 이용한 CI/CD Pipeline - 2  (2) 2025.01.24
Jenkins를 이용한 CI/CD Pipeline - 1  (2) 2025.01.23
Sonarqube Upgrade  (2) 2024.02.27
Sonarqube 설치  (0) 2024.02.27
jenkins 설치  (0) 2024.02.26
Comments