Im trying to cache my maven dependencies.
after step one succeeded (log):Cache "maven: /root/.m2/repository": Skipping upload for empty cache
My configs:
#Dockerfile# Stage 1: Build StageFROM maven:3.8.2-openjdk-17-slim AS buildWORKDIR /app# Copy the pom.xml fileCOPY pom.xml .# Create the .m2 directory and copy settings.xmlRUN mkdir -p /root/.m2COPY settings.xml /root/.m2/# Download dependenciesRUN mvn dependency:go-offline# Copy the rest of the applicationCOPY . .# Build the applicationRUN mvn clean install -DskipTests# Stage 2: Run StageFROM amazoncorretto:17.0.9-alpine3.18WORKDIR /app# Copy only the necessary files from the build stageCOPY --from=build /app/target/admin-api.jar admin-api.jarENTRYPOINT ["java", "-jar", "admin-api.jar"]
# bitbucket-pipelines.ymlimage: alpine:latestdefinitions:caches:maven: /root/.m2/repositoryservices:docker:image: docker:dindmemory: 3072pipelines:custom:office-server: - step:fail-fast: trueuser: rootruns-on: - self.hosted - linux - officename: Docker build & Pushservices: - dockercaches: - maven - dockerscript: - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin harbor.medsoft.care - TAG=$(echo $BITBUCKET_COMMIT | head -c 8) # Use the first 8 characters of the commit hash as the tag - echo $TAG - DOCKER_BUILDKIT=1 docker build -t harbor.medsoft.care/medsoft8/admin-service:$TAG . - docker push harbor.medsoft.care/medsoft8/admin-service:$TAG - docker tag harbor.medsoft.care/medsoft8/admin-service:$TAG harbor.medsoft.care/medsoft8/admin-service:latest - docker push harbor.medsoft.care/medsoft8/admin-service:latest - step:fail-fast: trueuser: rootruns-on: - self.hosted - linux - officename: Deploy to Kubernetesscript: - TAG=$(echo $BITBUCKET_COMMIT | head -c 8) # Use the first 8 characters of the commit hash as the tag - pipe: atlassian/kubectl-run:3.10.0variables:KUBE_CONFIG: $KUBE_CONFIGKUBECTL_COMMAND: set image deployment/admin-service admin-service=harbor.medsoft.care/medsoft8/admin-service:$TAG
Hi @bayarkhuu,
Caches can be used for directories in the build container. Your build doesn't download the maven dependencies in the build container, but in the Docker image that you are building. Therefore, there is nothing in the directory /root/.m2/repository of the build container to cache.
You can use a Docker cache, but the predefined docker cache used for caching the layers produced during Docker Build operations does not cache layers produced when using BuildKit.
If Docker BuildKit is enabled and the build layers need to be cached, we recommend using the Docker Build --cache-from option. This allows one or more tagged images stored in an external image registry to be used as a cache source. You can find more details here:
Kind regards,Theodora
It looks like you're new here. Sign in or register to get started.