Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix jar cache from user.home to user.dir - Fixes official jenkins docker image #192

Open
wants to merge 2 commits into
base: master
from

Conversation

Projects
None yet
2 participants
@clouless
Copy link

commented Aug 25, 2017

Problem

  • ‼️ user.home info IS NOT TAKEN from $HOME EnvVar, but from /etc/passwd instead.
  • user.dir IS TAKEN from $HOME EnvVar

Due to most people using dockerized builds and setting HOME EnvVar it would be better to use user.dir instead of user.home for the JarCache to avoid errors like this one:

image

Where does it happen?

In official docker image jenkinsci/jenkins:2.75 (when working with kubernetes-plugin).

image

How to test

Test under Ubuntu 16.04

docker run -i -t ubuntu:16.04 bash

Inside Docker as root:

apt-get install openjdk-8-jdk vim
groupadd -g 10000 jenkins
useradd -c "Jenkins user" -d /home/jenkins -u 10000 -g 10000 -m jenkins

Change /etc/passwd from jenkins:x:10000:10000:Jenkins user:/home/jenkins: to jenkins:x:10000:10000:Jenkins user:/home/jenkins2:.

Switch to Jenkins User and create Test.java:

su - jenkins
cd /home/jenkins
vim /home/jenkins/Test.java
import java.io.File;

public class Test {

  public static void main(String[] args){
      System.out.println(System.getProperty("user.home"));
      System.out.println(System.getProperty("user.dir"));
      File file = new File(System.getProperty("user.dir"),".jenkins/cache/jars");
      file.mkdir();
      System.out.println(file.getAbsoluteFile());
    }
}

Compile and run:

javac Test.java
java Test

It Prints out:

/home/jenkins2
/home/jenkins
/home/jenkins/.jenkins/cache/jars

@clouless clouless changed the title fix jar cache from user.home to user.dir fix jar cache from user.home to user.dir - Fixes official jenkins docker image Aug 25, 2017

@oleg-nenashev

This comment has been minimized.

Copy link
Member

commented Aug 26, 2017

There was a ticket for that: https://issues.jenkins-ci.org/browse/JENKINS-18578

It was fixed in 3.8 by adding support of Work directories. So a correct approach would be to just define -workDir or -jarCache.

Regarding the change, I am aware about possible regressions in some cases with the default behavior

@clouless

This comment has been minimized.

Copy link
Author

commented Aug 26, 2017

This happens on the Jenkins (Master) side, not the Slave side. So do you suggest to add -workDir startup parameters to Jenkins, to have the jarCache default behaviour disabled? I think -workDir is just a parameter for the remoting.jar and will not be interpreted by OPTS for Jenkins?

@oleg-nenashev

This comment has been minimized.

Copy link
Member

commented Aug 26, 2017

This happens on the Jenkins (Master) side, not the Slave side.

Then yes, I should review it with Master in mind

@clouless

This comment has been minimized.

Copy link
Author

commented Aug 26, 2017

ok cool. Even though the error is unlikely to happen on wide spectrum. It is cleaner that way.
And this only happens when you start the docker image with an UID different than 1000.
I did this with kubernetes and everything else worked fine, but this error popped up, since a user with UID!=1000 has no /etc/passwd entry to point to homeDir.

@oleg-nenashev oleg-nenashev self-assigned this Sep 9, 2017

@oleg-nenashev

This comment has been minimized.

Copy link
Member

commented Sep 11, 2017

Sorry for the delay. I hope to find some time this week

@clouless

This comment has been minimized.

Copy link
Author

commented Sep 11, 2017

no worries :) I find the overall response time of you guys very fast. Regarding the amount of tickets and prs to handle for jenkins as a whole :) I have waited much much longer for a first reaction on issues/prs in other projects. So just take your time, we are in no rush :)

@oleg-nenashev

This comment has been minimized.

Copy link
Member

commented Sep 13, 2017

I have submitted #197, which probably fixes the root cause of the issue (JENKINS-45755) on the master side.

But maybe this enhancement makes sense anyway. @recena also proposed using "/tmp", so we could try several destinations when -workDir and -jarCache are not set

@clouless

This comment has been minimized.

Copy link
Author

commented Sep 14, 2017

@oleg-nenashev nice. The more directories tried out before giving up the better. But if you want to user userHome then please use user.dir because of the /etc/passwd problem. You can close this PR if you solved it elsewhere :)

@oleg-nenashev

This comment has been minimized.

Copy link
Member

commented Sep 14, 2017

This is something I would definitely want to integrate, but in more generic way. I will keep it open for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.