I am trying to run Open Trip Planner on Cloud Run. I have three files: Dockerfile, graph.obj, andotp-2.4.0-shaded.jar file. By running the following command OTP server runs and listens:
java -Xmx2G -jar otp-2.4.0-shaded.jar --load .
I manage to build my docker file and run it locally, all works fine, but when I try to build it into cloud run using cloud build then I get this error: Error: Invalid or corrupt jarfile otp-2.4.0-shaded.jar. This happens on the deploy stage of cloud build, after it builds and pushes the image.
At the moment cloud build is linked to GitHub and whenever I push a change to the repository it loads the files and try to build. In terms of size, the jar file is 178 mb, this meant that to push it to GitHub I had to use a special command for pushing large files (anything greater than 100mb needs this to be pushed to GitHub). So I wonder if this has to do with the issue.
Here is the docker file:
FROM openjdk:23-slim
WORKDIR /app
ENV HOST 0.0.0.0
COPY otp-2.4.0-shaded.jar .
COPY graph.obj .
EXPOSE 8080
ENTRYPOINT ["java", "-Xmx2G", "-jar", "otp-2.4.0-shaded.jar", "--load", "."]
Hi @manusilver,
Welcome to Google Cloud Community!
You're getting this error as you need to point out the correct jar file. The format should be like this:
COPY ${JAR_FILE} app.jar
Your code should appear like this:
FROM openjdk:23-slim
WORKDIR /app
ENV HOST 0.0.0.0
COPY ${otp-2.4.0-shaded.jar} . //should be similar to this
COPY graph.obj .
EXPOSE 8080
ENTRYPOINT ["java", "-Xmx2G", "-jar", "otp-2.4.0-shaded.jar", "--load", "."]
Or you can just follow the common Docker technique for better readability:
FROM openjdk:8-jdk-alpine
EXPOSE 8080
ARG JAR_FILE=target/otp-2.4.0-shaded.jar //should be similar to this
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java", "-Xmx2G", "-jar", "otp-2.4.0-shaded.jar", "--load", "."]
Hope this helps.