Jenkins Docker Sidecar with Container Running a daemon command












0














I want to run ZAP as a proxy in my pipeline, and run my selenium tests through the proxy. Im just using curl in a container in place of selenium for my testing and was able to make this work locally using docker.



In my pipeline, zap starts up, but the pipeline just sits in the zap container after that, never progressing to the second container. I understand why, Ive launched a process as a daemon, its never going to finish, so the step never finished. I just dont understand how to accomplish what I need in jenkins.



stage('Run Zap Proxy'){
docker.image('owasp/zap2docker-weekly').withRun('-p 8090:8090') { c ->
docker.image('owasp/zap2docker-weekly').inside("-v $WORKSPACE:/zap/wrk:rw") {
/* Wait until mysql service is up */
sh """
zap.sh -daemon -port 8090 -host 0.0.0.0 -newsession testing -config api.addrs.addr.name=.* -config api.addrs.addr.regex=true -config api.disablekey=true
"""
}
docker.image('cfmanteiga/alpine-bash-curl-jq').inside("--link ${c.id}:proxy") {
sh 'curl -k -x http://proxy:8090 https://my.fqdn.net'
sh """
curl -k -x http://proxy:8090
-X POST https://my.fqdn.net/api/rest/sessions
-H 'Content-Type: application/json'
-H 'Accept: application/json'
-d '{"username":"username","password":"password"}'
"""
sh 'sleep 2m'
sh 'curl -o report.html http://zap/UI/core/other/htmlreport'
stash includes: 'report.html', name: 'report'
}
}
}


I essentially need to start zap with the command im using in the 'inside', and only kill the container when the second containers stages are complete.










share|improve this question



























    0














    I want to run ZAP as a proxy in my pipeline, and run my selenium tests through the proxy. Im just using curl in a container in place of selenium for my testing and was able to make this work locally using docker.



    In my pipeline, zap starts up, but the pipeline just sits in the zap container after that, never progressing to the second container. I understand why, Ive launched a process as a daemon, its never going to finish, so the step never finished. I just dont understand how to accomplish what I need in jenkins.



    stage('Run Zap Proxy'){
    docker.image('owasp/zap2docker-weekly').withRun('-p 8090:8090') { c ->
    docker.image('owasp/zap2docker-weekly').inside("-v $WORKSPACE:/zap/wrk:rw") {
    /* Wait until mysql service is up */
    sh """
    zap.sh -daemon -port 8090 -host 0.0.0.0 -newsession testing -config api.addrs.addr.name=.* -config api.addrs.addr.regex=true -config api.disablekey=true
    """
    }
    docker.image('cfmanteiga/alpine-bash-curl-jq').inside("--link ${c.id}:proxy") {
    sh 'curl -k -x http://proxy:8090 https://my.fqdn.net'
    sh """
    curl -k -x http://proxy:8090
    -X POST https://my.fqdn.net/api/rest/sessions
    -H 'Content-Type: application/json'
    -H 'Accept: application/json'
    -d '{"username":"username","password":"password"}'
    """
    sh 'sleep 2m'
    sh 'curl -o report.html http://zap/UI/core/other/htmlreport'
    stash includes: 'report.html', name: 'report'
    }
    }
    }


    I essentially need to start zap with the command im using in the 'inside', and only kill the container when the second containers stages are complete.










    share|improve this question

























      0












      0








      0







      I want to run ZAP as a proxy in my pipeline, and run my selenium tests through the proxy. Im just using curl in a container in place of selenium for my testing and was able to make this work locally using docker.



      In my pipeline, zap starts up, but the pipeline just sits in the zap container after that, never progressing to the second container. I understand why, Ive launched a process as a daemon, its never going to finish, so the step never finished. I just dont understand how to accomplish what I need in jenkins.



      stage('Run Zap Proxy'){
      docker.image('owasp/zap2docker-weekly').withRun('-p 8090:8090') { c ->
      docker.image('owasp/zap2docker-weekly').inside("-v $WORKSPACE:/zap/wrk:rw") {
      /* Wait until mysql service is up */
      sh """
      zap.sh -daemon -port 8090 -host 0.0.0.0 -newsession testing -config api.addrs.addr.name=.* -config api.addrs.addr.regex=true -config api.disablekey=true
      """
      }
      docker.image('cfmanteiga/alpine-bash-curl-jq').inside("--link ${c.id}:proxy") {
      sh 'curl -k -x http://proxy:8090 https://my.fqdn.net'
      sh """
      curl -k -x http://proxy:8090
      -X POST https://my.fqdn.net/api/rest/sessions
      -H 'Content-Type: application/json'
      -H 'Accept: application/json'
      -d '{"username":"username","password":"password"}'
      """
      sh 'sleep 2m'
      sh 'curl -o report.html http://zap/UI/core/other/htmlreport'
      stash includes: 'report.html', name: 'report'
      }
      }
      }


      I essentially need to start zap with the command im using in the 'inside', and only kill the container when the second containers stages are complete.










      share|improve this question













      I want to run ZAP as a proxy in my pipeline, and run my selenium tests through the proxy. Im just using curl in a container in place of selenium for my testing and was able to make this work locally using docker.



      In my pipeline, zap starts up, but the pipeline just sits in the zap container after that, never progressing to the second container. I understand why, Ive launched a process as a daemon, its never going to finish, so the step never finished. I just dont understand how to accomplish what I need in jenkins.



      stage('Run Zap Proxy'){
      docker.image('owasp/zap2docker-weekly').withRun('-p 8090:8090') { c ->
      docker.image('owasp/zap2docker-weekly').inside("-v $WORKSPACE:/zap/wrk:rw") {
      /* Wait until mysql service is up */
      sh """
      zap.sh -daemon -port 8090 -host 0.0.0.0 -newsession testing -config api.addrs.addr.name=.* -config api.addrs.addr.regex=true -config api.disablekey=true
      """
      }
      docker.image('cfmanteiga/alpine-bash-curl-jq').inside("--link ${c.id}:proxy") {
      sh 'curl -k -x http://proxy:8090 https://my.fqdn.net'
      sh """
      curl -k -x http://proxy:8090
      -X POST https://my.fqdn.net/api/rest/sessions
      -H 'Content-Type: application/json'
      -H 'Accept: application/json'
      -d '{"username":"username","password":"password"}'
      """
      sh 'sleep 2m'
      sh 'curl -o report.html http://zap/UI/core/other/htmlreport'
      stash includes: 'report.html', name: 'report'
      }
      }
      }


      I essentially need to start zap with the command im using in the 'inside', and only kill the container when the second containers stages are complete.







      docker jenkins zap






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 20 '18 at 13:53









      Justin SeiserJustin Seiser

      245




      245
























          1 Answer
          1






          active

          oldest

          votes


















          0














          You could directly pass the zap command in the withRun part:



          stage('Run Zap Proxy'){
          docker.image('owasp/zap2docker-weekly').withRun('-p 8090:8090 -v $WORKSPACE:/zap/wrk:rw', 'zap.sh -daemon -port 8090 -host 0.0.0.0 -newsession testing -config api.addrs.addr.name=.* -config api.addrs.addr.regex=true -config api.disablekey=true') { c ->
          docker.image('cfmanteiga/alpine-bash-curl-jq').inside("--link ${c.id}:proxy") {
          sh 'curl -k -x http://proxy:8090 https://my.fqdn.net'
          sh """
          curl -k -x http://proxy:8090
          -X POST https://my.fqdn.net/api/rest/sessions
          -H 'Content-Type: application/json'
          -H 'Accept: application/json'
          -d '{"username":"username","password":"password"}'
          """
          sh 'sleep 2m'
          sh 'curl -o report.html http://zap/UI/core/other/htmlreport'
          stash includes: 'report.html', name: 'report'
          }
          }
          }


          withRun allows you to overwrite the CMD of the zap-container. Check this API-documentation.






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53394538%2fjenkins-docker-sidecar-with-container-running-a-daemon-command%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            You could directly pass the zap command in the withRun part:



            stage('Run Zap Proxy'){
            docker.image('owasp/zap2docker-weekly').withRun('-p 8090:8090 -v $WORKSPACE:/zap/wrk:rw', 'zap.sh -daemon -port 8090 -host 0.0.0.0 -newsession testing -config api.addrs.addr.name=.* -config api.addrs.addr.regex=true -config api.disablekey=true') { c ->
            docker.image('cfmanteiga/alpine-bash-curl-jq').inside("--link ${c.id}:proxy") {
            sh 'curl -k -x http://proxy:8090 https://my.fqdn.net'
            sh """
            curl -k -x http://proxy:8090
            -X POST https://my.fqdn.net/api/rest/sessions
            -H 'Content-Type: application/json'
            -H 'Accept: application/json'
            -d '{"username":"username","password":"password"}'
            """
            sh 'sleep 2m'
            sh 'curl -o report.html http://zap/UI/core/other/htmlreport'
            stash includes: 'report.html', name: 'report'
            }
            }
            }


            withRun allows you to overwrite the CMD of the zap-container. Check this API-documentation.






            share|improve this answer


























              0














              You could directly pass the zap command in the withRun part:



              stage('Run Zap Proxy'){
              docker.image('owasp/zap2docker-weekly').withRun('-p 8090:8090 -v $WORKSPACE:/zap/wrk:rw', 'zap.sh -daemon -port 8090 -host 0.0.0.0 -newsession testing -config api.addrs.addr.name=.* -config api.addrs.addr.regex=true -config api.disablekey=true') { c ->
              docker.image('cfmanteiga/alpine-bash-curl-jq').inside("--link ${c.id}:proxy") {
              sh 'curl -k -x http://proxy:8090 https://my.fqdn.net'
              sh """
              curl -k -x http://proxy:8090
              -X POST https://my.fqdn.net/api/rest/sessions
              -H 'Content-Type: application/json'
              -H 'Accept: application/json'
              -d '{"username":"username","password":"password"}'
              """
              sh 'sleep 2m'
              sh 'curl -o report.html http://zap/UI/core/other/htmlreport'
              stash includes: 'report.html', name: 'report'
              }
              }
              }


              withRun allows you to overwrite the CMD of the zap-container. Check this API-documentation.






              share|improve this answer
























                0












                0








                0






                You could directly pass the zap command in the withRun part:



                stage('Run Zap Proxy'){
                docker.image('owasp/zap2docker-weekly').withRun('-p 8090:8090 -v $WORKSPACE:/zap/wrk:rw', 'zap.sh -daemon -port 8090 -host 0.0.0.0 -newsession testing -config api.addrs.addr.name=.* -config api.addrs.addr.regex=true -config api.disablekey=true') { c ->
                docker.image('cfmanteiga/alpine-bash-curl-jq').inside("--link ${c.id}:proxy") {
                sh 'curl -k -x http://proxy:8090 https://my.fqdn.net'
                sh """
                curl -k -x http://proxy:8090
                -X POST https://my.fqdn.net/api/rest/sessions
                -H 'Content-Type: application/json'
                -H 'Accept: application/json'
                -d '{"username":"username","password":"password"}'
                """
                sh 'sleep 2m'
                sh 'curl -o report.html http://zap/UI/core/other/htmlreport'
                stash includes: 'report.html', name: 'report'
                }
                }
                }


                withRun allows you to overwrite the CMD of the zap-container. Check this API-documentation.






                share|improve this answer












                You could directly pass the zap command in the withRun part:



                stage('Run Zap Proxy'){
                docker.image('owasp/zap2docker-weekly').withRun('-p 8090:8090 -v $WORKSPACE:/zap/wrk:rw', 'zap.sh -daemon -port 8090 -host 0.0.0.0 -newsession testing -config api.addrs.addr.name=.* -config api.addrs.addr.regex=true -config api.disablekey=true') { c ->
                docker.image('cfmanteiga/alpine-bash-curl-jq').inside("--link ${c.id}:proxy") {
                sh 'curl -k -x http://proxy:8090 https://my.fqdn.net'
                sh """
                curl -k -x http://proxy:8090
                -X POST https://my.fqdn.net/api/rest/sessions
                -H 'Content-Type: application/json'
                -H 'Accept: application/json'
                -d '{"username":"username","password":"password"}'
                """
                sh 'sleep 2m'
                sh 'curl -o report.html http://zap/UI/core/other/htmlreport'
                stash includes: 'report.html', name: 'report'
                }
                }
                }


                withRun allows you to overwrite the CMD of the zap-container. Check this API-documentation.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 20 '18 at 16:03









                fabfab

                90811224




                90811224






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53394538%2fjenkins-docker-sidecar-with-container-running-a-daemon-command%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

                    Alcedinidae

                    Origin of the phrase “under your belt”?