The "sidecar container" pattern is a popular one for setting up dependent containers for running tests/builds. 

       

      It would be nice to have support for this pattern in declarative to avoid the need to drop to script. 

       

      To investigate...

       

      In scope: 

      testing: 

      • Should be able to be fully automated using ci.jenkins.io 
      • check sidecar containers are shut down in all scenarios possible

          [JENKINS-46336] Sidecar docker containers for declarative

          Michael Neale added a comment -

          just bumped priority mostly as it is not a small amount of effort, some planning needed 

          Michael Neale added a comment - just bumped priority mostly as it is not a small amount of effort, some planning needed 

          James Dumay added a comment -

          michaelneale how much of this is just replicating docker compose? Perhaps we should be able to define a docker compose yml?

          James Dumay added a comment - michaelneale how much of this is just replicating docker compose? Perhaps we should be able to define a docker compose yml?

          Michael Neale added a comment -

          jamesdumay good question - I think docker compose may do a poor job at cleaning up after if things went wrong, btu that may be one way to implement this yes (although it does require they install it, and not sure how widely it is used). 

          Michael Neale added a comment - jamesdumay good question - I think docker compose may do a poor job at cleaning up after if things went wrong, btu that may be one way to implement this yes (although it does require they install it, and not sure how widely it is used). 

          James Dumay added a comment -

          ack

          James Dumay added a comment - ack

          Michael Neale added a comment -

          jamesdumay other tools tend to build in sidecar functionality, probably for a reason like this... 

          Michael Neale added a comment - jamesdumay other tools tend to build in sidecar functionality, probably for a reason like this... 

          Duplicate of JENKINS-41581?

          Christopher Orr added a comment - Duplicate of  JENKINS-41581 ?

          James Dumay added a comment -

          orrc good eye Thank you!

          James Dumay added a comment - orrc good eye Thank you!

          There is an implementation for Kubernetes in review at https://github.com/jenkinsci/kubernetes-plugin/pull/306 (JENKINS-48135)

          Carlos Sanchez added a comment - There is an implementation for Kubernetes in review at https://github.com/jenkinsci/kubernetes-plugin/pull/306 ( JENKINS-48135 )

          kubernetes plugin now supports Pods in declarative, using yaml definition

          Carlos Sanchez added a comment - kubernetes plugin now supports Pods in declarative, using yaml definition

          Here is a way of doing it until proper support is added

              stages {
                  stage('Run Tests') {
                      parallel {
                          stage("RSpec") {
                            agent { label 'docker' }
                            steps {
                              script {
                                docker.image('postgres').withRun('-e POSTGRES_DB=xxxx_test') { container ->
                                  docker.build('netadmin-jenkins',' --build-arg http_proxy=$http_proxy --build-arg https_proxy=$https_proxy --build-arg no_proxy=$no_proxy -f Dockerfile.jenkins --pull .').inside("--link=${container.id}:postgres -e DATABASE_URL=postgresql://postgres:postgres@postgres:5432/xxxx_test") {
                                    withEnv(['DATABASE_URL=postgres://postgres@postgres:5432/','PGHOST=postgres','PGUSER=postgres','RAILS_ENV=test']) {
                                        sh 'yarn install'
                                        rake 'db:create'
                                        rake 'db:migrate'
                                        rake 'db:seed'
                                        rake 'spec'
                                    }
                                  }
                                }
                              }
                            }
                            post {
                                always {
                                    junit '**/reports/*.xml'
                                }
                            }
                          }
                          stage("RuboCop") {
                              agent {
                                  dockerfile {
                                    additionalBuildArgs '--pull --build-arg http_proxy=$http_proxy --build-arg https_proxy=$https_proxy --build-arg no_proxy=$no_proxy'
                                    filename 'Dockerfile.jenkins'
                                  }
                              }
                              steps {
                                  rake 'rubocop | tee rubocop.log'
                              }
                              post {
                                  always {
                                      warnings canResolveRelativePaths: false, failedTotalHigh: '0', healthy: '0', parserConfigurations: [[parserName: 'RuboCop', pattern: 'rubocop.log']], unHealthy: '100', unstableTotalAll: '0'
                                  }
                              }
                          }
          

          David van Laatum added a comment - Here is a way of doing it until proper support is added stages { stage( 'Run Tests' ) { parallel { stage( "RSpec" ) { agent { label 'docker' } steps { script { docker.image( 'postgres' ).withRun( '-e POSTGRES_DB=xxxx_test' ) { container -> docker.build( 'netadmin-jenkins' , ' --build-arg http_proxy=$http_proxy --build-arg https_proxy=$https_proxy --build-arg no_proxy=$no_proxy -f Dockerfile.jenkins --pull .' ).inside( "--link=${container.id}:postgres -e DATABASE_URL=postgresql: //postgres:postgres@postgres:5432/xxxx_test" ) { withEnv([ 'DATABASE_URL=postgres: //postgres@postgres:5432/' , 'PGHOST=postgres' , 'PGUSER=postgres' , 'RAILS_ENV=test' ]) { sh 'yarn install' rake 'db:create' rake 'db:migrate' rake 'db:seed' rake 'spec' } } } } } post { always { junit '**/reports/*.xml' } } } stage( "RuboCop" ) { agent { dockerfile { additionalBuildArgs '--pull --build-arg http_proxy=$http_proxy --build-arg https_proxy=$https_proxy --build-arg no_proxy=$no_proxy' filename 'Dockerfile.jenkins' } } steps { rake 'rubocop | tee rubocop.log' } post { always { warnings canResolveRelativePaths: false , failedTotalHigh: '0' , healthy: '0' , parserConfigurations: [[parserName: 'RuboCop' , pattern: 'rubocop.log' ]], unHealthy: '100' , unstableTotalAll: '0' } } }

            Unassigned Unassigned
            michaelneale Michael Neale
            Votes:
            32 Vote for this issue
            Watchers:
            48 Start watching this issue

              Created:
              Updated: