https://kotlinlang.org logo
Title
t

Tech

01/31/2023, 6:04 PM
Hey I was wondering how to setup docker build with github actions just to see if my code actually compiles. It currently errors out with this
When using COPY with more than one source file, the destination must be a directory and end with a /
however if I add a
/
to the end of the copy statement it stops building locally. Here's the Dockerfile
FROM gradle 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/ktor-app.jar
ENTRYPOINT ["java", "-jar", "/app/ktor-app.jar"]
t

Trevor Stone

01/31/2023, 6:25 PM
Not sure if this wouldn't work for you, but there is https://ktor.io/docs/docker.html This uses a plugin which delegates to
jib
https://github.com/GoogleContainerTools/jib to build your container instead of using a Dockerfile. This adds gradle tasks to build and run the container
c

CLOVIS

01/31/2023, 7:33 PM
Alternatively, this is a Dockerfile that works: https://gitlab.com/opensavvy/formulaide/-/blob/main/.gitlab/backend.dockerfile Just run
./gradlew assembleDist
before building it
t

Tech

01/31/2023, 7:34 PM
Does it work with GitHub actions? That’s the main problem I’m experiencing at the moment
c

CLOVIS

01/31/2023, 7:34 PM
It's just a Dockerfile, it runs in whatever runs a Dockerfile
t

Tech

01/31/2023, 7:35 PM
With the error message I stated above that only occurs with GitHub actions however locally it’s fine, it’s weird
c

CLOVIS

01/31/2023, 7:35 PM
Old version of Docker in one of the two envs?
t

Tech

01/31/2023, 7:36 PM
Perhaps, let me quickly check my local docker version
I'm running 20.10.17
t

Trevor Stone

01/31/2023, 8:03 PM
using the ktor jib plugin builds without issue on github actions for me
also do you know which copy isn't working?
COPY --from=build /home/gradle/src/build/libs/*.jar /app/ktor-app.jar
This seems like it could be the problem due to that wildcard
t

Tech

01/31/2023, 11:14 PM
Yeah that's the copy that isn't working, do you by chance have a solution to that or just recommend me to use jib?
I don't have much experience with Docker/CD stuff so I'd prefer to stay away from things such as jib since I don't really understand it at the moment 😅
t

Trevor Stone

01/31/2023, 11:28 PM
using the ktor docker plugin would most likely be easiest tbh unless you really want to learn dockerfiles
This is a dockerfile that outputs similar to jib
this could probably guide you to fixing your problem though
t

Tech

01/31/2023, 11:30 PM
Interesting, I'll try it out thank you so much.