[Jenkins] Docker로 Jenkins 빌드 및 설치
계속 미뤄왔던 젠킨스 도입.
지속적인 빌드와 배포 자동화를 의미하는 CI/CD 쪽에서 jenkins는 대다수 개발자들이 이용하는 툴이다.
매번 war 수동으로 말아서 서버로 밀어 넣고 restart 하는 삶은 이제 그만,,
한번 공부하고 써보자! 무중단배포하는 그날까지~~~~~~~
1. 공식 이미지 존재 여부 확인
docker hub에 Jenkins 공식 이미지가 존재한다.
https://github.com/jenkinsci/docker/blob/master/README.md
2. Volume 폴더 생성
jenkins 폴더에 접근할 수 있도록 volume 폴더를 만들고 권한을 주자
$ mkdir -p /opt/docker/volume/jenkins && chmod -R 777 "$_"
3. Dockerfile 생성
FROM jenkins/jenkins:centos7
USER root
일단 dockerfile쪽은 작성할 게 별로 없는데 나중에 추가하도록 하자
추가.
FROM jenkins/jenkins:centos7
#metadata
LABEL name="minggu"
LABEL email="minha1002@gmail.com"
LABEL description="jenkins test"
USER root
# Install docker
RUN yum update -y && yum install -y docker wget
4. docker-compose.yml
# docker-compose.yml
version: "3.8"
services:
wildfly:
...
jenkins:
container_name: jenkinsC
enviroment:
TZ: "Asia/Seoul"
build:
context: ./dockerfiles/jenkins/
dockerfile: jenkins.Dockerfile
ports:
- 5080:8080
- 50000:50000
volumes:
- /opt/docker/volume/jenkins:/var/jenkins_home
- /var/run/docker.sock:/var/run/docker.sock
저번에 만들어 둔 wildfly 밑에 새로 jenkins라는 이름의 service를 만들었다. 간단간단
5. docker compose up을 통한 build
#특정 service 명 입력
$ docker compose up jenkins
[+] Building 4.0s (6/6) FINISHED
=> [internal] load build definition from jenkins.Dockerfile 0.4s
=> => transferring dockerfile: 144B 0.0s
=> [internal] load .dockerignore 0.6s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/jenkins/jenkins:centos7 2.2s
=> [auth] jenkins/jenkins:pull token for registry-1.docker.io 0.0s
=> CACHED [1/1] FROM docker.io/jenkins/jenkins:centos7@sha256:84290087666555a858d5540a46875e59a0ac1ea9e18683b51972d8bf27f05e78 0.2s
=> => resolve docker.io/jenkins/jenkins:centos7@sha256:84290087666555a858d5540a46875e59a0ac1ea9e18683b51972d8bf27f05e78 0.2s
=> exporting to image 0.8s
=> => exporting layers 0.0s
=> => writing image sha256:72aeccf15a60e47a9bfec4986b18762bd255f5da9bec60562579acc5349c3f53 0.0s
=> => naming to docker.io/library/docker_jenkins 0.1s
Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
[+] Running 1/1
⠿ Container jenkinsC Created 0.5s
Attaching to jenkinsC
jenkinsC | Running from: /usr/share/jenkins/jenkins.war
jenkinsC | webroot: EnvVars.masterEnvVars.get("JENKINS_HOME")
jenkinsC | 2022-04-04 06:18:58.532+0000 [id=1] INFO org.eclipse.jetty.util.log.Log#initialized: Logging initialized @1443ms to org.eclipse.jetty.util.log.JavaUtilLog
jenkinsC | 2022-04-04 06:18:58.783+0000 [id=1] INFO winstone.Logger#logInternal: Beginning extraction from war file
jenkinsC | 2022-04-04 06:19:02.344+0000 [id=1] WARNING o.e.j.s.handler.ContextHandler#setContextPath: Empty contextPath
jenkinsC | 2022-04-04 06:19:02.500+0000 [id=1] INFO org.eclipse.jetty.server.Server#doStart: jetty-9.4.45.v20220203; built: 2022-02-03T09:14:34.105Z; git: 4a0c91c0be53805e3fcffdcdcc9587d5301863db; jvm 11.0.14.1+1
jenkinsC | 2022-04-04 06:19:03.180+0000 [id=1] INFO o.e.j.w.StandardDescriptorProcessor#visitServlet: NO JSP Support for /, did not find org.eclipse.jetty.jsp.JettyJspServlet
jenkinsC | 2022-04-04 06:19:03.276+0000 [id=1] INFO o.e.j.s.s.DefaultSessionIdManager#doStart: DefaultSessionIdManager workerName=node0
jenkinsC | 2022-04-04 06:19:03.277+0000 [id=1] INFO o.e.j.s.s.DefaultSessionIdManager#doStart: No SessionScavenger set, using defaults
jenkinsC | 2022-04-04 06:19:03.279+0000 [id=1] INFO o.e.j.server.session.HouseKeeper#startScavenging: node0 Scavenging every 660000ms
jenkinsC | 2022-04-04 06:19:04.470+0000 [id=1] INFO hudson.WebAppMain#contextInitialized: Jenkins home directory: /var/jenkins_home found at: EnvVars.masterEnvVars.get("JENKINS_HOME")
jenkinsC | 2022-04-04 06:19:05.530+0000 [id=1] INFO o.e.j.s.handler.ContextHandler#doStart: Started w.@6fca5907{Jenkins v2.341,/,file:///var/jenkins_home/war/,AVAILABLE}{/var/jenkins_home/war}
jenkinsC | 2022-04-04 06:19:05.591+0000 [id=1] INFO o.e.j.server.AbstractConnector#doStart: Started ServerConnector@2002348{HTTP/1.1, (http/1.1)}{0.0.0.0:8080}
jenkinsC | 2022-04-04 06:19:05.593+0000 [id=1] INFO org.eclipse.jetty.server.Server#doStart: Started @8508ms
jenkinsC | 2022-04-04 06:19:05.596+0000 [id=24] INFO winstone.Logger#logInternal: Winstone Servlet Engine running: controlPort=disabled
jenkinsC | 2022-04-04 06:19:06.257+0000 [id=29] INFO hudson.PluginManager#loadDetachedPlugins: Upgrading Jenkins. The last running version was 2.332.1. This Jenkins is version 2.341.
jenkinsC | 2022-04-04 06:19:06.361+0000 [id=31] INFO jenkins.InitReactorRunner$1#onAttained: Started initialization
jenkinsC | 2022-04-04 06:19:06.371+0000 [id=29] INFO hudson.PluginManager#loadDetachedPlugins: Upgraded Jenkins from version 2.332.1 to version 2.341. Loaded detached plugins (and dependencies): []
jenkinsC | 2022-04-04 06:19:06.391+0000 [id=29] INFO jenkins.InitReactorRunner$1#onAttained: Listed all plugins
jenkinsC | 2022-04-04 06:19:08.524+0000 [id=36] INFO jenkins.InitReactorRunner$1#onAttained: Prepared all plugins
jenkinsC | 2022-04-04 06:19:08.535+0000 [id=36] INFO jenkins.InitReactorRunner$1#onAttained: Started all plugins
jenkinsC | 2022-04-04 06:19:08.575+0000 [id=36] INFO jenkins.InitReactorRunner$1#onAttained: Augmented all extensions
jenkinsC | 2022-04-04 06:19:09.174+0000 [id=37] INFO jenkins.InitReactorRunner$1#onAttained: System config loaded
jenkinsC | 2022-04-04 06:19:09.175+0000 [id=37] INFO jenkins.InitReactorRunner$1#onAttained: System config adapted
jenkinsC | 2022-04-04 06:19:09.176+0000 [id=37] INFO jenkins.InitReactorRunner$1#onAttained: Loaded all jobs
jenkinsC | 2022-04-04 06:19:09.180+0000 [id=37] INFO jenkins.InitReactorRunner$1#onAttained: Configuration for all jobs updated
jenkinsC | 2022-04-04 06:19:09.217+0000 [id=51] INFO hudson.model.AsyncPeriodicWork#lambda$doRun$1: Started Download metadata
jenkinsC | 2022-04-04 06:19:09.236+0000 [id=51] INFO hudson.model.AsyncPeriodicWork#lambda$doRun$1: Finished Download metadata. 13 ms
jenkinsC | 2022-04-04 06:19:09.447+0000 [id=38] INFO jenkins.install.SetupWizard#init:
jenkinsC |
jenkinsC | *************************************************************
jenkinsC | *************************************************************
jenkinsC | *************************************************************
jenkinsC |
jenkinsC | Jenkins initial setup is required. An admin user has been created and a password generated.
jenkinsC | Please use the following password to proceed to installation:
jenkinsC |
jenkinsC | 38e626cc44dd4db89484ba29c29e8da6
jenkinsC |
jenkinsC | This may also be found at: /var/jenkins_home/secrets/initialAdminPassword
jenkinsC |
jenkinsC | *************************************************************
jenkinsC | *************************************************************
jenkinsC | *************************************************************
jenkinsC |
금방 설치되더니 하단에 generate 된 password 가 보인다.
혹시라도 background로 docker를 실행했다면 docker logs [docker name]으로 로그를 다시 찍어보면 된다.
6. jenkins console 접속
아까 열어둔 서버:5080 포트로 접속해보면
짜잔 접속이 된다.
방금 전 패스워드를 입력하고
플러그인을 설치해주자.
admin 계정을 생성해주고 고정 URL을 정해주면
<참고>
https://github.com/jenkinsci/docker/blob/master/README.md
'Server & Infra' 카테고리의 다른 글
[Jenkins] Slack으로 Jenkins 알림받기 (0) | 2022.04.06 |
---|---|
[Jenkins] Jenkins - SVN 연동 (0) | 2022.04.05 |
[Docker] docker-compose 사용 (Compose V2) (0) | 2022.03.28 |
[Docker] wildfly Dockerfile을 이용한 Container 생성 (+Admin) (0) | 2022.03.25 |
[Docker] Failed to get D-Bus connection: Operation not permitted (systemctl 명령어 사용실패) (0) | 2022.03.22 |