My CI executes the following steps in sequence:
earthly +compile
(first make the code compiles)earthly --push +package-and-containerize-all
(package to containers and push to registry)
The Earthfile code for targets looks like this:
resolve-gradle-dependencies: # <-- this step is to download dependencies only and reuse the result unless build configuration gets changed
COPY gradle gradle
COPY gradlew* .
RUN ./gradlew --version
COPY +collect-gradle-context/gradle_context .
RUN ./gradlew
compile:
FROM +resolve-gradle-dependencies
COPY . . # <-- there is an appropriate .earthlyignore
RUN ./gradlew classes
package-jar:
FROM +compile
RUN ./gradlew bootJar
SAVE ARTIFACT build/libs/application.jar application.jar AS LOCAL build/libs/application.jar
SAVE ARTIFACT build/libs/application.jar application.jar
extract-jar:
COPY +package-jar/application.jar .
RUN java -Djarmode=layertools -jar application.jar extract
SAVE ARTIFACT . extracted-app
containerize-the-app:
FROM jvm-runtime-distroless
WORKDIR /opt/app
COPY +extract-jar/extracted-app/dependencies/ ./
COPY +extract-jar/extracted-app/spring-boot-loader/ ./
COPY +extract-jar/extracted-app/snapshot-dependencies/ ./
COPY +extract-jar/extracted-app/application/ ./
ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher"]
SAVE IMAGE --push my-registry/my-service:latest
package-and-containerize-all:
BUILD +containerize-the-app
BUILD +containerize-e2e-tests # the code for this is omitted, because it's not involve in the error
Here is the .earthlyignore
:
.git
.gitignore
.gradle/
**/build/
README.md
Earthfile
.earthlyignore
Getting this weird error on CI node after executing the pipeline several times:
+compile | *cached* --> COPY . .
+compile | *cached* --> RUN ./gradlew classes
+package-jar | *cached* --> RUN ./gradlew bootJar
+package-e2e-tests-jar | WARN: Canceled
1/4 | WARN: Canceled
+package-jar | WARN: Canceled
Share your logs with an Earthly account (experimental)! Register for one at https://ci.earthly.dev.
Error: build target: build main: failed to solve: async force execution for +extract-jar: unlazy force execution: failed to compute cache key: failed to get state for index 1 on [eyJpdHJubCI6dHJ1ZX0=] (fakecopy2) +extract-jar depends on +package-jar
I never face this error locally while developing the pipeline (I am using Mac + Docker for Mac), but it gets reproduced very quickly on CI node (which is a custom node, preserving it's state between runs to benefit from caching earthly targets). It takes 2-3 runs to reproduce the problem without source code change.
From the log above you can see that extract-jar
has failed (which was invoked transitively for +package-and-containerize-all
)
After that I am only able to bring my pipeline back to life on that particular CI node by inserting earthly prune --all --reset
step in the very beginning of the pipeline.
To me the error message (failed to compute cache key: failed to get state for index
) does not look very descriptive. What can cause the problem? I've also tried to a apply --verbose
flag, but it did not give me more details on the error.