Jenkins on Docker

2015.9.6 / k16wire

여러분은 이미 Jenkins와

Docker는 알고있다.

이미 KOHSUKE가

OSCON에서 시연했다.

https://www.youtube.com/watch?v=PFCSSiT-UUQ

단계1

Jenkins를 Docker로

실행하자.

Docker 설치
Jenkins 이미지
Jenkins 컨테이너

$docker run -d -P jenkins

단계2

Jenkins로 Docker

컨테이너를 만들자.

Docker 소켓파일 접근권한
Docker 클라이언트

Docker 실행권한

소켓파일 공유

-v /var/run/docker.sock:/var/run/docker.sock

Docker 클라이언트

-v /usr/bin/docker:/usr/bin/docker

Docker 실행권한

$ docker run -privileged xxx

jenkins-master

FROM jenkins:latest
USER root
RUN apt-get update && \
  apt-get install -y sudo && \
  rm -rf /var/lib/apt/lists/*
RUN echo "jenkins ALL=NOPASSWD: ALL" >> /etc/sudoers
$ docker run -d -P \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /usr/bin/docker:/usr/bin/docker \
 jenkins-master

단계3

Jenkins Slave

Docker 컨테이너

docker-plugin
jenkins-slave 이미지

docker-plugin

https://wiki.jenkins-ci.org/display/JENKINS/Docker+Plugin

docker-slave

https://hub.docker.com/r/evarga/jenkins-slave/

FROM ubuntu:trusty
MAINTAINER Ervin Varga <ervin.varga@gmail.com>
 
# Make sure the package repository is up to date.
RUN apt-get update
RUN apt-get -y upgrade
 
# Install a basic SSH server
RUN apt-get install -y openssh-server
RUN sed -i 's|session    required     pam_loginuid.so|session    optional     pam_loginuid.so|g' /etc/pam.d/sshd
RUN mkdir -p /var/run/sshd
 
# Install JDK 7 (latest edition)
RUN apt-get install -y openjdk-7-jdk
 
# Add user jenkins to the image
RUN adduser --quiet jenkins
# Set password for the jenkins user (you may want to alter this).
RUN echo "jenkins:jenkins" | chpasswd
 
# Standard SSH port
EXPOSE 22
 
CMD ["/usr/sbin/sshd", "-D"]

Multi-config job

  • DEMO: https://youtu.be/YYG8DOE8Pco
  • 참고자료
    • http://pragmaticstory.com/2015/06/26/wget%EC%9C%BC%EB%A1%9C-docker-%EC%84%A4%EC%B9%98/
    • http://pragmaticstory.com/2015/07/13/docker%EB%A5%BC-jenkins-%EC%8A%AC%EB%A0%88%EC%9D%B4%EB%B8%8C%EB%A1%9C-%EC%82%AC%EC%9A%A9%ED%95%98%EC%9E%90/

Jenkins on Docker

By k16wire

Jenkins on Docker

  • 5,830