1

I have this a Spring Boot application with the following configurations

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                    <image>
                        <builder>paketobuildpacks/builder:tiny</builder>
                        
                        <name>test.com/microservice/${project.artifactId}:${project.version}</name>
                        <pullPolicy>IF_NOT_PRESENT</pullPolicy>
                        <publish>true</publish>
                        <env>
                            <BP_NATIVE_IMAGE>false</BP_NATIVE_IMAGE>
                            <BPL_DEBUG_ENABLED>false</BPL_DEBUG_ENABLED>
                            <!--<JAVA_TOOL_OPTIONS></JAVA_TOOL_OPTIONS>-->
                        </env>
                    </image>
                    <docker>
                        <publishRegistry>
                            
                            <username>test</username>
                            
                            <password>test</password>
                            
                            <url>https://test.com</url>
                        </publishRegistry>
                    </docker>
                </configuration>

            </plugin>
        </plugins>
    </build>

And .gitlab-cy.yml

image: test.com/docker:18.06
services:
  - name: test.com/docker:dind

variables:
  DOCKER_DRIVER: overlay
  MAVEN_OPTS: "-Dhttps.protocols=TLSv1.2 -Dmaven.repo.local=$CI_PROJECT_DIR/.m2 -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN -Dorg.slf4j.simpleLogger.showDateTime=true -Djava.awt.headless=true"
  MAVEN_CLI_OPTS: "--batch-mode --errors --fail-at-end --show-version -DinstallAtEnd=true -DdeployAtEnd=true"
  
maven-build:
  image: test.com/maven:3.6.3-openjdk-17-slim
  stage: build
  tags:
    - shared-runner
  only:
    - staging
    - master

  script:
    - mvn -DAPP_VERSION=${CI_COMMIT_SHA:0:8} $MAVEN_CLI_OPTS clean spring-boot:build-image -DskipTests

Always when job is run

paketobuilder download BellSoft Liberica JRE 17.0.4

logs

5221 [INFO]     [creator]         $JAVA_TOOL_OPTIONS                                                                        the JVM launch flags
5222 [INFO]     [creator]         Using Java version 17.* from BP_JVM_VERSION
5222 [INFO]     [creator]       BellSoft Liberica JRE 17.0.4: Contributing to layer
5222 [INFO]     [creator]         Downloading from https://github.com/bell-sw/Liberica/releases/download/17.0.4+8/bellsoft-jre17.0.4+8-linux-amd64.tar.gz
111299 [INFO]     [creator]         Verifying checksum
111455 [INFO]     [creator]         Expanding to /layers/paketo-buildpacks_bellsoft-liberica/jre

How Can I cache these downloads in gitlab runner?

Navigator
  • 2,871
  • 4
  • 17
  • 27
  • Can you expand on what you mean by "catch these"? Are you trying to prevent Maven from downloading them from the Internet? – Daniel Mikusa Aug 02 '22 at 17:23
  • sorry its "cache" . I dont want to download every time the job is running – Navigator Aug 03 '22 at 07:15
  • 1
    In a nutshell, you need to make a directory on your CI that's being cached from run-to-run. Then volume map that directory as read-write into your build under `/home/cnb/.m2`. In the Spring Boot plugin's configuration section, you need to add ``, https://docs.spring.io/spring-boot/docs/2.7.2/maven-plugin/reference/htmlsingle/#build-image. When the build runs, the buildpack will execute Maven and Maven will be configured to write to `/home/cnb/.m2` for all it's caching. The first run, it'll populate your cache and it'll reuse it on subsequent builds (assuming your CI caches it). – Daniel Mikusa Aug 03 '22 at 12:29
  • See also https://paketo.io/docs/howto/java/#share-local-maven-or-gradle-cache – Daniel Mikusa Aug 03 '22 at 12:30

0 Answers0