turnbullpress / dockerbook-code

The code and configuration examples from The Docker Book (http://www.dockerbook.com)
929 stars 580 forks source link

CI Chapter - Image getting created in Host machine #49

Closed venkatesh-cv closed 6 years ago

venkatesh-cv commented 6 years ago

Context

I'm reading the Continuous Integration Chapter and following the Jenkins + Ruby setup. I'm able to launch Jenkins and configure & run the build. However, the build fails. Appreciate your help to understand what is going on.

Error Description

No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb, Rakefile.rb)

Debugging attempts

` Tagged the imag as 'myapp' to see whats happening. Noticed that the image is actually getting created on the host machine & not inside the jenkins container. I'm not sure if this should the case. Having created a docker server inside Jenkins container, the image should have been created in there. Is suspect that possibly this could be the a reason for issue described above

Container startup script

docker run -i -p 8080:8080 -p 50000:50000  -v /var/run/docker.sock:/var/run/docker.sock --name jenkins cvenkatesh/jenkins-docker-server
-- if you are wondering about the missing config folder, its deliberately skipped. I'm planning to get to it later.

Execute Shell Script

IMAGE=$(sudo docker build -t myapp . |tail -l |awk '{ print $NF }')
IMAGE=$(sudo docker images myapp -q)
MNT="/var/jenkins_home/jobs/${JOB_NAME}"
ls -l $MNT
ls -l $MNT/workspace
CONTAINER=$(sudo docker run -d -v $MNT:/opt/project -w /opt/project/workspace $IMAGE /bin/bash -c 'cd /opt/project/workspace;rake spec --trace')
sudo docker attach $CONTAINER
RC=$(sudo docker wait $CONTAINER)
sudo docker rm $CONTAINER
exit $RC

JENKINS-OUTPUT

+ MNT=/var/jenkins_home/jobs/test_build
+ ls -l /var/jenkins_home/jobs/test_build
total 16
drwxr-xr-x 46 jenkins jenkins 4096 Feb 10 10:54 builds
-rw-r--r--  1 jenkins jenkins 2011 Feb 10 10:54 config.xml
lrwxrwxrwx  1 jenkins jenkins   22 Feb 10 10:54 lastStable -> builds/lastStableBuild
lrwxrwxrwx  1 jenkins jenkins   26 Feb 10 10:54 lastSuccessful -> builds/lastSuccessfulBuild
-rw-r--r--  1 jenkins jenkins    3 Feb 10 10:54 nextBuildNumber
drwxr-xr-x  8 jenkins jenkins 4096 Feb 10 09:37 workspace
+ ls -l /var/jenkins_home/jobs/test_build/workspace
total 52
-rw-r--r-- 1 jenkins jenkins   202 Feb 10 08:57 Dockerfile
-rw-r--r-- 1 jenkins jenkins    61 Feb 10 08:57 Gemfile
-rw-r--r-- 1 jenkins jenkins   418 Feb 10 08:57 Gemfile.lock
-rw-r--r-- 1 jenkins jenkins 10273 Feb 10 08:57 LICENSE
-rw-r--r-- 1 jenkins jenkins   142 Feb 10 08:57 README.md
-rw-r--r-- 1 jenkins jenkins   265 Feb 10 08:57 Rakefile
drwxr-xr-x 2 jenkins jenkins  4096 Feb 10 08:57 centos
drwxr-xr-x 2 jenkins jenkins  4096 Feb 10 08:57 debian
drwxr-xr-x 3 root    root     4096 Feb 10 09:37 opt
drwxr-xr-x 2 jenkins jenkins  4096 Feb 10 08:57 spec
drwxr-xr-x 2 jenkins jenkins  4096 Feb 10 08:57 ubuntu
+ sudo docker run -d -v /var/jenkins_home/jobs/test_build:/opt/project -w /opt/project/workspace e7d8c91df2b0 /bin/bash -c cd /opt/project/workspace;rake spec --trace

+ CONTAINER=476087fc73cafeffed7639332c5cff7541ca89efeb2b3e5f1b168c408c4ebee0
+ sudo docker attach 476087fc73cafeffed7639332c5cff7541ca89efeb2b3e5f1b168c408c4ebee0
rake aborted!
No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb, Rakefile.rb)
/usr/lib/ruby/vendor_ruby/rake/application.rb:684:in `raw_load_rakefile'
/usr/lib/ruby/vendor_ruby/rake/application.rb:94:in `block in load_rakefile'
/usr/lib/ruby/vendor_ruby/rake/application.rb:176:in `standard_exception_handling'
/usr/lib/ruby/vendor_ruby/rake/application.rb:93:in `load_rakefile'
/usr/lib/ruby/vendor_ruby/rake/application.rb:77:in `block in run'
/usr/lib/ruby/vendor_ruby/rake/application.rb:176:in `standard_exception_handling'
/usr/lib/ruby/vendor_ruby/rake/application.rb:75:in `run'
/usr/bin/rake:27:in `<main>'
Build step 'Execute shell' marked build as failure
Recording test results
ERROR: Step ‘Publish JUnit test result report’ failed: No test report files were found. Configuration error?
Finished: FAILURE

Images on the host machine (trimmed list)

REPOSITORY                         TAG                 IMAGE ID            CREATED             SIZE
myapp                              latest              998203e99399        6 seconds ago       188MB
cvenkatesh/jenkins-docker-server   latest              1600db4417b8        6 hours ago         1.05GB
cvenkatesh/ubuntu-node-mongo       latest              586d8cfd0062        45 hours ago        562MB
venkatesh-cv commented 6 years ago

Ok, I got it to work finally today.

Here are my observations

venkatesh-cv commented 6 years ago

I encountered another issue when running the jenkins job multiple times. git had trouble checking out code the second time as it got permission denied on the /spec/report/*.xml folder

Finished: FAILURE