Quantcast

kubernetes-plugin: containertemplate with shell-script in entrypoint

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

kubernetes-plugin: containertemplate with shell-script in entrypoint

Jenkins users mailing list
Hello developers,

i don't know if i use the kubernetes-plugin correct:

My jenkinsfile looks like:

podTemplate(label: 'mypod', containers: [
        containerTemplate
(name: 'maven', image: 'myOwnMavenImage:latest'', ttyEnabled: true, command: 'cat')
      ]) {

        node ('
mypod') {
            stage '
Get a Maven project'
            git '
https://github.com/jenkinsci/kubernetes-plugin.git'
            container('maven') {
                stage
'Build a Maven project'
                sh
'mvn clean install'
           
}
       
}
   
}


My Dockerfile uses a script-file as entrypoint:


run-script:


export JENKINS_HOME=/var/lib/jenkins

# Setup nss_wrapper so the random user OpenShift will run this container
# has an entry in /etc/passwd.
# This is needed for 'git' and other tools to work properly.
#
export USER_ID=$(id -u)
export GROUP_ID=$(id -g)
envsubst
< ${JENKINS_HOME}/passwd.template > ${JENKINS_HOME}/passwd
export LD_PRELOAD=libnss_wrapper.so
export NSS_WRAPPER_PASSWD=${JENKINS_HOME}/passwd
export NSS_WRAPPER_GROUP=/etc/group

exec "$@"


dockerfile:


FROM openjdk8:stable

ENV MAVEN_HOME
/usr/share/maven
ENV M2_HOME
/usr/share/maven
ENV JENKINS_HOME
=/var/lib/jenkins

COPY
./contrib/.m2 $JENKINS_HOME/.m2/
COPY
./contrib/maven $M2_HOME
COPY
./contrib/fix-permissions /usr/local/bin/fix-permissions
COPY
./contrib/passwd.template $JENKINS_HOME/passwd.template
COPY
./contrib/run /var/lib/jenkins/run

USER root

RUN yum
-config-manager --disable epel >/dev/null || : && \
    yum
-config-manager --enable rhel-7-server-ose-3.3-rpms || : && \
    INSTALL_PKGS
="nss_wrapper gettext git lsof rsync tar unzip which zip" && \
    yum install
-y --setopt=tsflags=nodocs install $INSTALL_PKGS && \
    rpm
-V $INSTALL_PKGS && \
    yum clean all
   
RUN    localedef
-f UTF-8 -i en_US en_US.UTF-8
RUN    ln
-s $M2_HOME/bin/mvn /usr/bin/mvn
RUN    chmod a
+x /usr/local/bin/fix-permissions
RUN    chown
-R 1001:0 $M2_HOME
RUN    chmod
775 $M2_HOME/bin/*
RUN    /usr/local/bin/fix-permissions $M2_HOME/bin
   
RUN chown -R 1001:0 $JENKINS_HOME && \
    chmod -R g+rw $JENKINS_HOME

USER 1001

ENTRYPOINT [
"/var/lib/jenkins/run"]

If i start the jenkins-job the pod is started with the jnlp- and the maven-container, but my shellscript in the maven-container is not used. I think thats because i use a cmd in the containertemplate of the maven-container.


If i delete the cmd an set tty to 'false' the shellskript is used but the container stops after executing the shell-skript in the maven-container.


Is there a posibility to have a long-running process in a container with executing a shell-script in the entrypoint of a container ?


Thank you for your help.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/7f2d3e30-0409-4ddc-a8a5-159987246b16%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: kubernetes-plugin: containertemplate with shell-script in entrypoint

Carlos Sanchez


On Fri, Mar 17, 2017 at 12:40 PM, 'Sascha Vujevic' via Jenkins Users <[hidden email]> wrote:
Hello developers,

i don't know if i use the kubernetes-plugin correct:

My jenkinsfile looks like:

podTemplate(label: 'mypod', containers: [
        containerTemplate
(name: 'maven', image: 'myOwnMavenImage:latest'', ttyEnabled: true, command: 'cat')
      ]) {

        node ('
mypod') {
            stage '
Get a Maven project'
            git '
https://github.com/jenkinsci/kubernetes-plugin.git'
            container('maven') {
                stage
'Build a Maven project'
                sh
'mvn clean install'
           
}
       
}
   
}


My Dockerfile uses a script-file as entrypoint:


run-script:


export JENKINS_HOME=/var/lib/jenkins

# Setup nss_wrapper so the random user OpenShift will run this container
# has an entry in /etc/passwd.
# This is needed for 'git' and other tools to work properly.
#
export USER_ID=$(id -u)
export GROUP_ID=$(id -g)
envsubst
< ${JENKINS_HOME}/passwd.template > ${JENKINS_HOME}/passwd
export LD_PRELOAD=libnss_wrapper.so
export NSS_WRAPPER_PASSWD=${JENKINS_HOME}/passwd
export NSS_WRAPPER_GROUP=/etc/group

exec "$@"


dockerfile:


FROM openjdk8:stable

ENV MAVEN_HOME
/usr/share/maven
ENV M2_HOME
/usr/share/maven
ENV JENKINS_HOME
=/var/lib/jenkins

COPY
./contrib/.m2 $JENKINS_HOME/.m2/
COPY
./contrib/maven $M2_HOME
COPY
./contrib/fix-permissions /usr/local/bin/fix-permissions
COPY
./contrib/passwd.template $JENKINS_HOME/passwd.template
COPY
./contrib/run /var/lib/jenkins/run

USER root

RUN yum
-config-manager --disable epel >/dev/null || : && \
    yum
-config-manager --enable rhel-7-server-ose-3.3-rpms || : && \
    INSTALL_PKGS
="nss_wrapper gettext git lsof rsync tar unzip which zip" && \
    yum install
-y --setopt=tsflags=nodocs install $INSTALL_PKGS && \
    rpm
-V $INSTALL_PKGS && \
    yum clean all
   
RUN    localedef
-f UTF-8 -i en_US en_US.UTF-8
RUN    ln
-s $M2_HOME/bin/mvn /usr/bin/mvn
RUN    chmod a
+x /usr/local/bin/fix-permissions
RUN    chown
-R 1001:0 $M2_HOME
RUN    chmod
775 $M2_HOME/bin/*
RUN    /usr/local/bin/fix-permissions $M2_HOME/bin
   
RUN chown -R 1001:0 $JENKINS_HOME && \
    chmod -R g+rw $JENKINS_HOME

USER 1001

ENTRYPOINT [
"/var/lib/jenkins/run"]

If i start the jenkins-job the pod is started with the jnlp- and the maven-container, but my shellscript in the maven-container is not used. I think thats because i use a cmd in the containertemplate of the maven-container.


If i delete the cmd an set tty to 'false' the shellskript is used but the container stops after executing the shell-skript in the maven-container.


Is there a posibility to have a long-running process in a container with executing a shell-script in the entrypoint of a container ?


yes, don't use 'cmd' in the pod template so your entrypoint is executed. Your entrypoint has to be long-running, the container needs to be running all time until pod is killed


Thank you for your help.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/7f2d3e30-0409-4ddc-a8a5-159987246b16%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CALHFn6NQNmzUVJOVzEFf-B9qUmmde9mE4HKp_JhHqy00rhHm6Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: kubernetes-plugin: containertemplate with shell-script in entrypoint

Jenkins users mailing list
Thank you for the fast answer.

How can i achive the long running process ?

I set 'exec "$@"' in my shellscript for my entrypoint. Isn't this wright ?

Maybe you have an advice.

Thank you.

Am Freitag, 17. März 2017 12:46:27 UTC+1 schrieb Carlos Sanchez:


On Fri, Mar 17, 2017 at 12:40 PM, 'Sascha Vujevic' via Jenkins Users <<a onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;" href="javascript:" target="_blank" rel="nofollow" gdf-obfuscated-mailto="GRIaPLUyBwAJ">jenkins...@googlegroups.com> wrote:
Hello developers,

i don't know if i use the kubernetes-plugin correct:

My jenkinsfile looks like:

podTemplate(label: 'mypod', containers: [
        containerTemplate
(name: 'maven', image: 'myOwnMavenImage:latest'', ttyEnabled: true, command: 'cat')
      ]) {

        node ('
mypod') {
            stage '
Get a Maven project'
            git '
https://<a onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgithub.com%2Fjenkinsci%2Fkubernetes-plugin.git\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEpJdXdmpsm8DUFz1CiHteb0l5LZw&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgithub.com%2Fjenkinsci%2Fkubernetes-plugin.git\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEpJdXdmpsm8DUFz1CiHteb0l5LZw&#39;;return true;" href="http://github.com/jenkinsci/kubernetes-plugin.git" target="_blank" rel="nofollow">github.com/jenkinsci/kubernetes-plugin.git'
            container('maven') {
                stage
'Build a Maven project'
                sh
'mvn clean install'
           
}
       
}
   
}


My Dockerfile uses a script-file as entrypoint:


run-script:


export JENKINS_HOME=/var/lib/jenkins

# Setup nss_wrapper so the random user OpenShift will run this container
# has an entry in /etc/passwd.
# This is needed for 'git' and other tools to work properly.
#
export USER_ID=$(id -u)
export GROUP_ID=$(id -g)
envsubst
< ${JENKINS_HOME}/passwd.template > ${JENKINS_HOME}/passwd
export LD_PRELOAD=libnss_wrapper.so
export NSS_WRAPPER_PASSWD=${JENKINS_HOME}/passwd
export NSS_WRAPPER_GROUP=/etc/group

exec "$@"


dockerfile:


FROM openjdk8:stable

ENV MAVEN_HOME
/usr/share/maven
ENV M2_HOME
/usr/share/maven
ENV JENKINS_HOME
=/var/lib/jenkins

COPY
./contrib/.m2 $JENKINS_HOME/.m2/
COPY
./contrib/maven $M2_HOME
COPY
./contrib/fix-permissions /usr/local/bin/fix-permissions
COPY
./contrib/passwd.template $JENKINS_HOME/passwd.template
COPY
./contrib/run /var/lib/jenkins/run

USER root

RUN yum
-config-manager --disable epel >/dev/null || : && \
    yum
-config-manager --enable rhel-7-server-ose-3.3-rpms || : && \
    INSTALL_PKGS
="nss_wrapper gettext git lsof rsync tar unzip which zip" && \
    yum install
-y --setopt=tsflags=nodocs install $INSTALL_PKGS && \
    rpm
-V $INSTALL_PKGS && \
    yum clean all
   
RUN    localedef
-f UTF-8 -i en_US en_US.UTF-8
RUN    ln
-s $M2_HOME/bin/mvn /usr/bin/mvn
RUN    chmod a
+x /usr/local/bin/fix-permissions
RUN    chown
-R 1001:0 $M2_HOME
RUN    chmod
775 $M2_HOME/bin/*
RUN    /usr/local/bin/fix-permissions $M2_HOME/bin
   
RUN chown -R 1001:0 $JENKINS_HOME && \
    chmod -R g+rw $JENKINS_HOME

USER 1001

ENTRYPOINT [
"/var/lib/jenkins/run"]

If i start the jenkins-job the pod is started with the jnlp- and the maven-container, but my shellscript in the maven-container is not used. I think thats because i use a cmd in the containertemplate of the maven-container.


If i delete the cmd an set tty to 'false' the shellskript is used but the container stops after executing the shell-skript in the maven-container.


Is there a posibility to have a long-running process in a container with executing a shell-script in the entrypoint of a container ?


yes, don't use 'cmd' in the pod template so your entrypoint is executed. Your entrypoint has to be long-running, the container needs to be running all time until pod is killed


Thank you for your help.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;" href="javascript:" target="_blank" rel="nofollow" gdf-obfuscated-mailto="GRIaPLUyBwAJ">jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit <a onmousedown="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/7f2d3e30-0409-4ddc-a8a5-159987246b16%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/7f2d3e30-0409-4ddc-a8a5-159987246b16%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" href="https://groups.google.com/d/msgid/jenkinsci-users/7f2d3e30-0409-4ddc-a8a5-159987246b16%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow">https://groups.google.com/d/msgid/jenkinsci-users/7f2d3e30-0409-4ddc-a8a5-159987246b16%40googlegroups.com.
For more options, visit <a onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" href="https://groups.google.com/d/optout" target="_blank" rel="nofollow">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/ffdff072-4a45-43a6-a45d-e3e6d6968175%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...