[Docker] - 젠킨스 CI/CD (2) - 실습

📖 젠킨스 서버(컨테이너)환경 및 Jobs 구성 요약

Jenkins Version : Jenkins 2.332.2
(Docker Img : jenkins/jenkins:lts - https://hub.docker.com/r/jenkins/jenkins)

Installed App : Docker version 20.10.14, build a224086

-Jenkins Jobs-

Build Trigger : GitHub hook trigger for GITScm polling

Build Process: Maven targets -> Shell script

⚙ CI/CD 과정 요약

Github push (Web Hook) -> Clone source from Github repository (To Jenkins)

-> Package as War (On Jenkins's Maven) -> Build Docker's Tomcat Img (From new source)

-> Run Tomcat (With new WAR)

⚙ 젠킨스 컨테이너 구동 정보

docker run -d --name myjenkins \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -v jenkins:/var/jenkins_home \
    -p 8080:8080  \
    -u root \
    -d jenkins/jenkins:lts

⚙ 톰캣 컨테이너 DockerFile

FROM tomcat:9.0.58
LABEL maintainer="[email protected]"
ENV TZ=Asia/Seoul
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN rm -Rf /usr/local/tomcat/webapps/ROOT
RUN rm /usr/local/tomcat/conf/server.xml
COPY server.xml /usr/local/tomcat/conf/
COPY FinalPrj/target/final-1.0.0-BUILD-SNAPSHOT.war /usr/local/tomcat/webapps/ott.war
EXPOSE 80
CMD ["catalina.sh", "run"]

⚙ 젠킨스 Build Process - Script Shell

#!/bin/sh
cd /var/jenkins_home/workspace/OTT #Docker 파일이 존재하는 경로
docker rm  -f mytomcat || true
docker build -t mytomcatimg .
docker run -d -p 80:80 --name mytomcat mytomcatimg

좋은 웹페이지 즐겨찾기