Jenkins Docker image

From Tizen Wiki
Jump to: navigation, search

Tizen Infra : Jenkins with Docker

Introduction

Welcome to Jenkins . (http://jenkins-ci.org/)

Version

ver 1.580.3-1.2.0.4 ( Jenkins : 1.580.3-1.2 Docker Image : 0.4)

Tested on Host OS.

===== Host OS : ubuntu 14.04 =====
docker version : 1.4.1
docker version : 1.6.2     
docker version : 1.7.0
docker version : 1.8.1
Host OS : opensuse 13.1
docker version : 1.3.2
docker version : 1.6.2 

Pre-installed Packages

===== Image OS : flavio/opensuse-12-3 =====
vim tar wget telnet supervisor sudo
mozilla-nss
http://mirrors.jenkins-ci.org/opensuse-stable/jenkins-1.580.3-1.2.noarch.rpm
jenkins-plugins jenkins-jobs jenkins-scripts
kvm libvirt libvirt-python qemu virt-manager qemu-linux-user
redis gbs
http://download.tizen.org/tools/mic-appliance/15.01/mic-appliance.tar.bz2
apache2 php5 php5-mysql apache2-mod_php5 php5-gd php5-gettext 
php5-mbstring php5-pear php5-curl php5-suhosin apache2-mod_proxy_html

Download docker image (already created)

Url : http://download.tizen.org/docker/jenkins/

Execution

Download Jenkins image

URL : http://cdn.download.tizen.org/docker/obsserver/

$ wget http://cdn.download.tizen.org/docker/jenkins/jenkins-1.580.3-1.2.0.4-docker-script.tar.gz

--2015-09-09 13:45:30--  http://cdn.download.tizen.org/docker/obsserver/jenkins-1.580.3-1.2.0.4-docker-script.tar.gz
Length: 1597525429 (1.5G) [application/x-gzip]
Saving to: `jenkins-1.580.3-1.2.0.4-docker-script.tar.gz'

100%[========================================================================>] 1,597,525,429 11.2M/s   in 58s     

2015-09-09 13:48:12 (10.2 MB/s) - `jenkins-1.580.3-1.2.0.4-docker-script.tar.gz' saved [1597525429/1597525429]
Decompress Jenkins image
$ tar -xvf jenkins-1.580.3-1.2.0.4-docker-script.tar.gz

clientjenkins/
clientjenkins/djenkins.sh
clientjenkins/root/
clientjenkins/root/jobs/
clientjenkins/root/jobs/configuration
clientjenkins/jenkins-1.580.3-1.2.0.4-docker-image.tar.gz
clientjenkins/env/
clientjenkins/env/env.list
clientjenkins/README.md
clientjenkins/config.conf
clientjenkins/COPYING
  • clientjenkins/config.conf  : Metaconfig file of container
  • clientjenkins/env/env.list  : Environment variables of container
  • clientjenkins/jenkins-1.580.3-1.2.0.4-docker-image.tar.gz  : Docker image
  • clientjenkins/root/  : Specific configuration files to be applied on container</pre>


Load Jenkins image on system
$ sudo ./djenkins.sh load

IMAGES:tizendocker:443/jenkins:1.580.3-1.2.0.4
CONTAINER:jenkins
PORT:-p 8080:8080 -p 8888:8888 -p 6379:6379 -p 873:873
ENV LIST:--env-file /home/g5kim/test2/re_infra/clientjenkins/env/env.list
VOLUMES:-v /etc/localtime:/etc/localtime:ro -v /home/jenkins/var/lib/jenkins/:/var/lib/jenkins/ -v /home/jenkins/var/lib/redis/default/:/var/lib/redis/default/ -v /home/jenkins/srv/obs/:/srv/obs/ -v /home/g5kim/test2/re_infra/clientjenkins/root/jobs/:/root/jobs/
HOST NAME:-h Jenkins
PRIVILEGED:--privileged
AUTOSTART:--restart=always
LINKS:
VOLUMES-FROM:
ADD_HOST:
CAP_ADD:
Load an image from a tar archive
Load jenkins-1.580.3-1.2.0.4

$ sudo docker images

REPOSITORY                TAG                 IMAGE ID            CREATED            VIRTUAL SIZE
tizendocker:443/jenkins   1.580.3-1.2.0.4     abb8652606a6        1 hours ago        2.851 GB

$ docker images

$ docker images 
tizendocker:443/jenkins            1.580.3-1.2.0.4

$ vi env/env.list

#If you are use the proxy in your enviroment, pleaese add below line.
ftp_proxy=ftp://123.456.789.012
http_proxy=http://123.456.789.012
https_proxy=https://123.456.789.012
socks_proxy=socks://123.456.789.012

#If you are use the proxy in your enviroment, pleaese add below line.
ftp_proxy=
http_proxy=
https_proxy=
socks_proxy=

$ vi config.conf

Configuration a config.conf of the djenkins.sh
VOLUMES : "/home/jenkins/" is a directory of your Host PC.and mounted a directory of the Container
/home/jenkins/var/lib/jenkins/:/var/lib/jenkins/
/home/jenkins/var/lib/redis/:/var/lib/redis/
/home/jenkins/srv/obs/:/srv/obs/

ADD_HOSTS:  Add a custom host-to-IP mapping (host:ip)
ADD_HOSTS="OBSServer:ip"


$ vi $(pwd)/root/jobs/configuration

 
 ===== Jenkins job configuration file =====
 ${JENKINS_HOME}/jobs/configuration is used to keep all necessary parameters for
 jenkins jobs. Set all incomplete keys, like gerrit and obs parameters, in this
 file. Below is an example.
 
 # OBS related parameters
 OBS_URL=http://123.456.789.012  ##Web url of OBS
 OBS_API_URL=http://123.456.789.012:81 ##Api url of OBS
 OBS_API_USERNAME=Admin
 OBS_API_PASSWD=xxxxxxxxx
 OBS_OSCRC_PATH=/var/lib/jenkins/.oscrc
 # Gerrit related parameters
 GERRIT_USERNAME=jenkins
 GERRIT_HOSTNAME=123.456.789.012  ## gerrit ip
 GERRIT_SSHPORT=29418
 GERRIT_SILENT_MODE=0
 # Redis server
 REDIS_HOST=123.456.789.012       ## download server ip
 REDIS_PORT=6379
 # Git related parameters
 GIT_CACHE_DIR=/var/lib/jenkins/git-cache
 MAPPING_PROJECTS=
 MAPPING_PRJ=scm/git-obs-mapping
 REPOSYAML_PRJ=scm/meta/snapshot-repo-conf
 # Image Testing parameters
 TESTABLE_IMAGES=ivi-mbr-i586$
 TESTABLE_IMAGE_DOWNLOADABLES=bz2,bmap
 TESTABLE_IMAGE_FILTER=*.bz2
 #Host name of smtp server
 SMTP_SERVER=
 #The name displayed in mail for jenkins usage
 NOREPLY_EMAIL_SENDER=
 #Mailinglist which jenkins will send SR notification to it
 MAILINGLIST=
 # Download server configuration
 URL_PUBLIC_REPO_BASE=http://123.456.789.012:8888  ## download server ip
 PATH_REPO_BASE=/srv/obs/repos/
 PATH_LIVE_REPO_BASE=/srv/obs/repos/live
 ## Image sync configuration
 IMG_SYNC_DEST_BASE=rsync://123.456.789.012/_repos_RW_    ## jenkins server ip
 ## VM configuration
 USE_VM=1
 VM_IMAGE=/var/lib/jenkins/mic-appliance
 VM_MEMORY=8192
 VM_CPUS=8
 ## Manifest content configuraion
 GERRIT_FETCH_URL=ssh://123.456.789.012                       ## gerrit server ip
 GERRIT_REVIEW_URL=http://123.456.789.012/gerrit           ## gerrit server url

## Remote build logfile
PATH_OBS_BUILD_BASE=rsync://123.456.789.012/_build_R_   ## OBS server ip
 

$ ./djenkins.sh start

If you use a firewall on host OS, you have to allow a port number.(8080 8888 6379 873)

 $sudo ufw allow 8080
 $sudo ufw allow 8888
 $sudo ufw allow 6379
 $sudo ufw allow 873

Connect Jenkins

Jenkins Web page : http://localhost:8080
Snapshot Download page : http://localhost:8888

#### Rsync Info (It needs for the Snapshot) /etc/rsyncd.conf ####
[_live_RW_]
   path = /srv/obs/repos/live/
[_repos_RW_]
   path = /srv/obs/repos/

Additional settings

Setting up for Redis
 $./djenkins.sh attach
 jenkins# chown -R redis:redis /var/lib/redis/
Setting up for Gerrit accessing
After you register the email, you will receive an email which contains a link. Please copy the link to your browser to activate the account.
Create SSH keys

$./djenkins.sh attach

jenkins# sudo su -l -p jenkins

jenkins@Jenkins:~> ssh-keygen -t rsa

jenkins@Jenkins:~> cat .ssh/id_rsa.pub

 after pressing the Enter key at several prompts, an SSH key-pair will be created in /root/.ssh/id_rsa.pub .
Upload SSH pubkey to Gerrit Click the links below to set up the Gerrit WebUI.
Settings --> SSH Public Keys --> Add Key...
Paste your SSH public key there, and then click 'Add'.
Verify your SSH connection You can verify your Gerrit connection by executing this command:
Make sure to add the server RSA key fingerprint to the known hosts of jenkins account if connect to gerrit server in the first time.
If your settings are correct, you'll see the message below.
If not, check SSH proxy and SSH public key on Gerrit.

$ jenkins@Jenkins:~> ssh -p 29418 username@gerrit_hostname

 **** Welcome to Gerrit Code Review ****

$ jenkins@Jenkins:~> vi .ssh/config

 Host gerrit_hostname
 Port 29418
 User gerrit_username
 IdentityFile ~/.ssh/id_rsa


Gerrit-trigger-plugin:
 Click "Manage Jenkins" --> "Gerrit Trigger" --> "Add New Server"
 Input Gerrit Server info: Hostname, Frontend URL, SSH port, Username, SSH Keyfile 
 (local private SSH keyfile location), SSH Keyfile Password (if SSH keyfile contains
 a password).
 Click Test Connection to make sure the connection to Gerrit works well.
 Click the Save button at the bottom.
 
 # gerrit server ip
 name : gerrit
 Hostname : 123.456.789.012
 Frontend URL : http://123.456.789.012/
 SSH Port : 29418
 Username : gerrit_username
 SSH Keyfile : /var/lib/jenkins/.ssh/id_rsa
 

Initialize

$ ./djenkins.sh stop
<br>
$ sudo rm -rf /home/jenkins/
<br>
$ ./djenkins.sh rm
<br>
$ ./djenkins.sh start

CLI

USAGE: ./djenkins.sh COMMAND
-e 
Commands:
    start     Start a stopped container
    attach    Attach to a running container
    stop      Stop a running container
    status    Status a running container
    rm        Remove this containers
    restart   stop , start a container
    kill      Kill a running container
    logs      Fetch the logs of a container
    cp        Copy files/folders from a container's filesystem to the host path
    pull      Pull an image or a repository from a Docker registry server;
    inspect   Return low-level information on a containe
    top       Lookup the running processes of a container
    save      Save an image to a tar archive
    load      Load an image from a tar archive
    help      help

Troubleshooting

If you receive an error message that is displayed below,

HTTP ERROR: 503
Problem accessing /. Reason:
    Service Unavailable
Powered by Jetty://

Solution :
$ ./djenkins.sh attach
# chown -R jenkins:jenkins /var/lib/jenkins/
# rcjenkins restart

Dockerfile

If you want to build an image from a Dockerfile, you can find a Dockerfile from review.tizen.org.

License

https://jenkins-ci.org/mit-license

References

https://wiki.tizen.org/wiki/Jenkins_Installation_and_Setup
https://wiki.tizen.org/wiki/Jenkins/Gerrit/OBS_Interworking_Setup

Back to Setup of Tizen Infrastructure with Docker