简体   繁体   English

创建一个包含预安装的Spring Boot依赖项的Docker映像

[英]Create a docker image contains pre-installed spring boot dependencies

I have a spring-boot java application build with gradle, run by gitlab CI on gitlab.com that works just fine. 我有一个使用gradle的spring-boot java应用程序构建,由gitlab.com在gitlab.com上运行,效果很好。 But every time the CI run, it takes so much time to download dependencies (because I'm using gitlab shared-runner from gitlab.com which is docker-auto-scale runner and it doesn't cache anything for the next run). 但是每次CI运行时,都需要花费大量时间来下载依赖项(因为我使用的是gitlab.com的gitlab shared-runner,它是docker docker-auto-scale Runner,并且在下次运行时不会缓存任何内容)。

My idea is create a docker image base on docker:latest (because build jobs needs to interact with docker daemon while running) and pre-install or add gradle caches to the image so that images contains all dependencies that my app needs and when the CI run, it doesn't need to re-download dependencies. 我的想法是在docker:latest上创建一个docker映像(因为构建作业需要在运行时与docker守护程序进行交互),然后在映像中预安装添加gradle缓存 ,以便映像包含我的应用程序需要的所有依赖项以及CI运行时,不需要重新下载依赖项。

Has anyone done it before? 有人做过吗?

I had the exact idea as you did, but for Maven. 我和您一样有确切的想法,但对于Maven。 During the docker image build, I copy my project files in the image and run mvn clean install and upload it to my gitlab registry. 在docker映像构建期间,我将映像中的项目文件复制并运行mvn clean install并将其上传到我的gitlab注册表中。

CI pipeline execution time is considerably reduced. CI管道执行时间大大减少。

But you of course need to do this everytime you have new dependencies, or at least when there is a large difference between what is already in the cache and the dependencies required by your app. 但是,当然,每当您有新的依赖项时,或者至少在缓存中已有的内容与应用程序所需的依赖项之间有很大差异时,您当然都需要这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM