What can be the reason?
# server
s
What can be the reason?
a
Is libs from
settings.gradle.kts
via a plugin or dependency catalog? Are you sure that's been imported into your build container? Personally, I don't build the jar with my Dockerfile; I have my CI container build the jar and then copy it into the production container. So I don't really know what gotchas to expect when doing it this way.
s
I’m new in server side world, have created mobile app with kotlin multiplatform, and decided to crete server app as well. Have done a few things and decided to deploy somewhere(in Render in this case) to test.
When I build the server and run everything is ok
But when I run the docker file it cant understand version catalog
a
Where is your version catalog defined? Is it right next to your
build.gradle.kts
?
s
It is inside ROOT/gradle/
a
Is that your system root? Or your repository root?
s
Repo root
a
Hmm, I'm not really sure why it wouldn't get picked up then. 🤷
👍 1
e
If it builds right outside of a docker build step check that the docker copy step takes all the files it should and that the right files are copied to the docker context. Check also if the build gradle file is connected to the build in settings.gradle.kts
s
this is my
settings.gradle.kts
Copy code
rootProject.name = "COAF"
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")

pluginManagement {
    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}

dependencyResolutionManagement {
    repositories {
        google()
        mavenCentral()
    }
}

include(":composeApp")
include(":server")
include(":shared")
what files should docker copy?
I have done as ktor documentation suggested
e
i assume you are using the standar version catalog name
libs.versions.toml
?
s
Screenshot 2024-08-12 at 10.01.26.png
e
Can you build it with out docker and it works?
gradlew build
It looks right structure and gradle file
Im abit unsure about you docker file. In the copy step do you only copy the
server
in that case you would only have the server and the build file on the route. Disconnected from the rest of the build
And that would cause the error you have now
So i think this line is wrong
COPY --chown=gradle:gradle server /home/gradle/src
Change it to copy inn you repo root mybe something like this
COPY --chown=gradle:gradle . /home/gradle/src
The rest of the Gradle stuff looks ok, so Docker problem
s
Thst fixed, thank you very much
but now it throws error on last copy:
Copy code
FROM gradle:8.7-jdk17 AS build
COPY --chown=gradle:gradle . /home/gradle/src
WORKDIR /home/gradle/src
RUN gradle buildFatJar --no-daemon

FROM openjdk:17
EXPOSE 8080:8080
RUN mkdir /app
COPY --from=build /home/gradle/src/build/libs/*.jar /app/COAF.jar
ENTRYPOINT ["java","-jar","/app/COAF.jar"]
Copy code
=> [build 4/4] RUN gradle buildFatJar --no-daemon                                                                                                     235.7s
 => ERROR [stage-1 3/3] COPY --from=build /home/gradle/src/build/libs/*.jar /app/COAF.jar                                                                0.0s
------
 > [stage-1 3/3] COPY --from=build /home/gradle/src/build/libs/*.jar /app/COAF.jar:
------
Dockerfile:9
--------------------
   7 |     EXPOSE 8080:8080
   8 |     RUN mkdir /app
   9 | >>> COPY --from=build /home/gradle/src/build/libs/*.jar /app/COAF.jar
  10 |     ENTRYPOINT ["java","-jar","/app/COAF.jar"]
--------------------
ERROR: failed to solve: lstat /var/lib/docker/tmp/buildkit-mount2456974331/home/gradle/src/build/libs: no such file or directory

View build details: <docker-desktop://dashboard/build/default/default/h427w3geohbcldcfjime1tnds>
Failed to deploy '<unknown> Dockerfile: Dockerfile': Image build failed with exit code 1.
e
Check that the path is right now that you are copying form a different structure form the build image. Could also be more specific and copy just the fat jar.
This is a nice tool for inspecting docker files. https://github.com/wagoodman/dive
I think you can see the name of the build container in you docker file and inspect that one to see how the product is