public String buildImage ( Map < String , File > plugins ) throws IOException , InterruptedException { LOG . debug ( "Building image for {}" , plugins ) ; // final File tempDirectory = TempFileHelper.createTempDirectory("build-image", targetDir().toPath()); final File buildDir = new File ( targetDir ( ) . getAbsolutePath ( ) + "/docker-it/build-image" ) ; if ( buildDir . exists ( ) ) { deleteDirectory ( buildDir ) ; } if ( ! buildDir . mkdirs ( ) ) { throw new IllegalStateException ( "Can't create temp directory " + buildDir . getAbsolutePath ( ) ) ; } final String dockerfile = generateDockerfileFor ( plugins ) ; final File dockerfileFile = new File ( buildDir , "Dockerfile" ) ; writeStringToFile ( dockerfileFile , dockerfile ) ; final File buildHomePath = new File ( buildDir , JenkinsDockerImage . JENKINS_DEFAULT . homePath ) ; final File jenkinsConfig = new File ( buildHomePath , "config.xml" ) ; DockerHPIContainerUtil . copyResourceFromClass ( DockerHPIContainerUtil . class , "config.xml" , jenkinsConfig ) ; writeStringToFile ( new File ( buildHomePath , "jenkins.install.UpgradeWizard.state" ) , "2.19.4" ) ; writeStringToFile ( new File ( buildHomePath , "jenkins.install.InstallUtil.lastExecVersion" ) , "2.19.4" ) ; final File pluginDir = new File ( buildHomePath , "/plugins/" ) ; if ( ! pluginDir . mkdirs ( ) ) { throw new IllegalStateException ( "Can't create dirs " + pluginDir . getAbsolutePath ( ) ) ; } for ( Map . Entry < String , File > entry : plugins . entrySet ( ) ) { final File dst = new File ( pluginDir + "/" + entry . getKey ( ) ) ; copyFile ( entry . getValue ( ) , dst ) ; } try { LOG . info ( "Building data-image..." ) ; return getDockerCli ( ) . buildImageCmd ( buildDir ) . withTag ( DATA_IMAGE ) . withForcerm ( true ) . exec ( new BuildImageResultCallback ( ) { public void onNext ( BuildResponseItem item ) { String text = item . getStream ( ) ; if ( nonNull ( text ) ) { LOG . debug ( StringUtils . removeEnd ( text , NL ) ) ; } super . onNext ( item ) ; } } ) . awaitImageId ( ) ; } finally { buildDir . delete ( ) ; } }
Build docker image containing specified plugins .