Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to build on linux (Volume in Dockerfile) #164

Closed
d3473r opened this issue Jul 31, 2021 · 3 comments
Closed

Unable to build on linux (Volume in Dockerfile) #164

d3473r opened this issue Jul 31, 2021 · 3 comments

Comments

@d3473r
Copy link
Contributor

d3473r commented Jul 31, 2021

Hi,

i am unable to build a quarkus application with these base images as the build directory /project is defined as a volume here:

volumes:
- name: "volume.project"
path: "/project"

and here:

volumes:
- name: "volume.project"
path: "/project"

I am using the sample maven Dockerfile from the docs

## Stage 1 : build with maven builder image with native capabilities
FROM quay.io/quarkus/ubi-quarkus-native-image:21.1.0-java11 AS build
COPY pom.xml /project/
COPY mvnw /project/mvnw
COPY .mvn /project/.mvn
USER quarkus
WORKDIR /project
RUN ./mvnw -B org.apache.maven.plugins:maven-dependency-plugin:3.1.2:go-offline
COPY src /project/src
RUN ./mvnw package -Pnative

## Stage 2 : create the docker final image
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.4
WORKDIR /work/
COPY --from=build /project/target/*-runner /work/application

# set up permissions for user `1001`
RUN chmod 775 /work /work/application \
  && chown -R 1001 /work \
  && chmod -R "g+rwX" /work \
  && chown -R 1001:root /work

EXPOSE 8080
USER 1001

CMD ["./application", "-Dquarkus.http.host=0.0.0.0"]

The error is thrown in the final image as it tries to copy the compiled native application:

Step 12/16 : COPY --from=build /project/target/*-runner /work/application
COPY failed: no source files were specified

If I am doing an ls after the maven native build, all generated files are missing:

Step 9/17 : RUN ./mvnw package -Pnative
 ---> Using cache
 ---> 027af17a1511
Step 10/17 : RUN ls -lsh
 ---> Running in 06d8cda085b9
total 24K
 12K -rwxrwxr-x 1 root root 9.9K Jul 31 11:37 mvnw
8.0K -rw-rw-r-- 1 root root 4.3K Jul 31 11:37 pom.xml
4.0K drwxr-xr-x 4 root root 4.0K Jul 31 12:42 src

This is because any data that is written in the Dockerfile will be discarded in the next layer because the directory is specified as a volume: https://docs.docker.com/engine/reference/builder/#notes-about-specifying-volumes

The build is working fine on a mac though, I think Docker is doing some magic in the vm so it works there, but this is not in spec and does not work native with linux.

I would like to try and fix it myself, but I don't know exactely how your github actions work and i can't really test it in a fork :/

EDIT:

If i change the build directory to a directory outside the /project volume everything is working fine (But this should be fixed in the base images):

## Stage 1 : build with maven builder image with native capabilities
FROM quay.io/quarkus/ubi-quarkus-native-image:21.1.0-java11 AS build
USER root
WORKDIR /code
RUN chown quarkus:quarkus -R /code
USER quarkus
COPY pom.xml .
COPY mvnw mvnw
COPY .mvn .mvn
RUN ./mvnw -B org.apache.maven.plugins:maven-dependency-plugin:3.1.2:go-offline
COPY src src
RUN ./mvnw package -Pnative

Regards,
Fabian

@cescoffier
Copy link
Member

So, if I understand correctly, the Quarkus documentation should be updated to not use /project but /code. Am I right?

@d3473r
Copy link
Contributor Author

d3473r commented Aug 16, 2021

Yeah, any directory except /project will work fine. The better fix would be to change the base image, so this image doesn't have to use the

USER root 
WORKDIR /code 
RUN chown quarkus:quarkus -R /code 
USER quarkus

fix which looks more like a hack

cescoffier added a commit to cescoffier/quarkus that referenced this issue Aug 16, 2021
…content get erased between the two stages. It works on Mac for an unknown reason, but fails on Linux. See quarkusio/quarkus-images#164.
@cescoffier
Copy link
Member

I've opened a PR in the Quarkus doc.
Yes, looks a bit hackish, but not sure we can do better at the moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants