欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

2021 最新的多阶段构建 dockerfile 实现 java 源代码编译成 jar 包,并制作成图像

最编程 2024-07-14 21:41:51
...
[root@localhost ~/myems]# docker build -t ems1:1.0 . Sending build context to Docker daemon 32.77kB Step 1/8 : FROM maven:3.6.3-openjdk-8 AS builder ---> d1b3f61d61f2 Step 2/8 : RUN mkdir /build ---> Running in 08cadf2db7b4 Removing intermediate container 08cadf2db7b4 ---> 836eeb13f7fe Step 3/8 : ADD src /build/src ---> b5d73ef7ed79 Step 4/8 : ADD pom.xml /build ---> 5e9a5ce77859 Step 5/8 : RUN cd /build && mvn -B -ntp package ---> Running in d92bbcd7ab54 [INFO] Scanning for projects... [INFO] [INFO] ---------------------------< com.baizhi:ems >--------------------------- [INFO] Building ems 0.0.1-SNAPSHOT [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ ems --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Using 'UTF-8' encoding to copy filtered properties files. [INFO] Copying 1 resource [INFO] Copying 1 resource [INFO] [INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ ems --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 6 source files to /build/target/classes [INFO] [INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) @ ems --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Using 'UTF-8' encoding to copy filtered properties files. [INFO] skip non existing resourceDirectory /build/src/test/resources [INFO] [INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ ems --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 1 source file to /build/target/test-classes [INFO] [INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ ems --- [INFO] [INFO] ------------------------------------------------------- [INFO] T E S T S [INFO] ------------------------------------------------------- [INFO] Running com.baizhi.EmsApplicationTests 12:11:00.101 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate] 12:11:00.200 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating BootstrapContext using constructor [public org.springframework.test.context.support.DefaultBootstrapContext(java.lang.Class,org.springframework.test.context.CacheAwareContextLoaderDelegate)] 12:11:02.814 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating TestContextBootstrapper for test class [com.baizhi.EmsApplicationTests] from class [org.springframework.boot.test.context.SpringBootTestContextBootstrapper] 12:11:03.386 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Neither @ContextConfiguration nor @ContextHierarchy found for test class [com.baizhi.EmsApplicationTests], using SpringBootContextLoader 12:11:03.427 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.baizhi.EmsApplicationTests]: class path resource [com/baizhi/EmsApplicationTests-context.xml] does not exist 12:11:03.428 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.baizhi.EmsApplicationTests]: class path resource [com/baizhi/EmsApplicationTestsContext.groovy] does not exist 12:11:03.428 [main] INFO org.springframework.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [com.baizhi.EmsApplicationTests]: no resource found for suffixes {-context.xml, Context.groovy}. 12:11:03.456 [main] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils - Could not detect default configuration classes for test class [com.baizhi.EmsApplicationTests]: EmsApplicationTests does not declare any static, non-private, non-final, nested classes annotated with @Configuration. 12:11:03.870 [main] DEBUG org.springframework.test.context.support.ActiveProfilesUtils - Could not find an 'annotation declaring class' for annotation type [org.springframework.test.context.ActiveProfiles] and class [com.baizhi.EmsApplicationTests] 12:11:07.746 [main] DEBUG org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider - Identified candidate component class: file [/build/target/classes/com/baizhi/EmsApplication.class] 12:11:07.812 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Found @SpringBootConfiguration com.baizhi.EmsApplication for test class com.baizhi.EmsApplicationTests 12:11:11.875 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - @TestExecutionListeners is not present for class [com.baizhi.EmsApplicationTests]: using defaults. 12:11:11.876 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener, org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.event.ApplicationEventsTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener, org.springframework.test.context.event.EventPublishingTestExecutionListener] 12:11:12.008 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@29215f06, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@59505b48, org.springframework.test.context.event.ApplicationEventsTestExecutionListener@4efac082, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@6bd61f98, org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener@48aca48b, org.springframework.test.context.support.DirtiesContextTestExecutionListener@13fd2ccd, org.springframework.test.context.transaction.TransactionalTestExecutionListener@b9b00e0, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@506ae4d4, org.springframework.test.context.event.EventPublishingTestExecutionListener@7d4f9aae, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@72e5a8e, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@54e1c68b, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener@53aac487, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@52b1beb6, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@273e7444, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener@7db12bb6] 12:11:12.022 [main] DEBUG org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener - Before test class: context [DefaultTestContext@5d534f5d testClass = EmsApplicationTests, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [WebMergedContextConfiguration@2e3967ea testClass = EmsApplicationTests, locations = '{}', classes = '{class com.baizhi.EmsApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@670002, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@56528192, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@460d0a57, org.springframework.boot.test.autoconfigure.actuate.metrics.MetricsExportContextCustomizerFactory$DisableMetricExportContextCustomizer@6af93788, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@4a22f9e2, org.springframework.boot.test.context.SpringBootTestArgs@1, org.springframework.boot.test.context.SpringBootTestWebEnvironment@21bcffb5], resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map['org.springframework.test.context.web.ServletTestExecutionListener.activateListener' -> true]], class annotated with @DirtiesContext [false] with mode [null]. 12:11:12.467 [main] DEBUG org.springframework.test.context.support.TestPropertySourceUtils - Adding inlined properties to environment: {spring.jmx.enabled=false, org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true} . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.5.2) 2021-06-29 12:12:10.365 INFO 69 --- [ main] com.baizhi.EmsApplicationTests : Starting EmsApplicationTests using Java 1.8.0_282 on d92bbcd7ab54 with PID 69 (started by root in /build) 2021-06-29 12:12:10.368 INFO 69 --- [ main] com.baizhi.EmsApplicationTests : No active profile set, falling back to default profiles: default 2021-06-29 12:18:11.149 INFO 69 --- [ main] com.baizhi.EmsApplicationTests : Started EmsApplicationTests in 418.516 seconds (JVM running for 494.655) [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 514.628 s - in com.baizhi.EmsApplicationTests 2021-06-29 12:19:24.357 INFO 69 --- [ionShutdownHook] com.alibaba.druid.pool.DruidDataSource : {dataSource-0} closing ... [INFO] [INFO] Results: [INFO] [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 [INFO] [INFO] [INFO] --- maven-jar-plugin:3.2.0:jar (default-jar) @ ems --- [INFO] Building jar: /build/target/ems-0.0.1-SNAPSHOT.jar [INFO] [INFO] --- spring-boot-maven-plugin:2.5.2:repackage (repackage) @ ems --- [INFO] Replacing main artifact with repackaged archive [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 19:22 min [INFO] Finished at: 2021-06-29T12:20:33Z [INFO] ------------------------------------------------------------------------ Removing intermediate container d92bbcd7ab54 ---> e19081a12cd6 Step 6/8 : FROM adoptopenjdk/openjdk8:alpine-jre alpine-jre: Pulling from adoptopenjdk/openjdk8 540db60ca938: Pull complete 9fc18144b37f: Pull complete cc610e703026: Pull complete Digest: sha256:4e7f3fc23cfd6e9751a1465fc4daa2073a3987c72b178ba467b41f3971751205 Status: Downloaded newer image for adoptopenjdk/openjdk8:alpine-jre ---> 32011de768b3 Step 7/8 : COPY --from=builder /build/target/ems-0.0.1-SNAPSHOT.jar /ems.jar --->32011de768b3 Step 8/8 : CMD ["java", "-jar", "/ems.jar"] ---> Running in cc75371d3a8f Removing intermediate container cc75371d3a8f ---> 32011de768b3 Successfully built 32011de768b3 Successfully tagged ems:1.0