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

Redesign the multi-stage docker build #16881

Closed
cescoffier opened this issue Apr 28, 2021 · 7 comments · Fixed by #16938
Closed

Redesign the multi-stage docker build #16881

cescoffier opened this issue Apr 28, 2021 · 7 comments · Fixed by #16938
Labels
area/housekeeping Issue type for generalized tasks not related to bugs or enhancements
Milestone

Comments

@cescoffier
Copy link
Member

cescoffier commented Apr 28, 2021

Description

Our documentation contains an example of a multi-stages docker file to build a container running a native executable. That example is on https://quarkus.io/guides/building-native-image#using-a-multi-stage-docker-build.

That example is using a Quarkus image as based that we would like to retire (quay.io/quarkus/centos-quarkus-maven:21.0.0-java11).

Implementation ideas

Here is another working variant that uses an image that we will continue to produce regularly:

## Stage 1 : build with maven builder image with native capabilities
FROM quay.io/quarkus/ubi-quarkus-native-image:21.0.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.3
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 idea is to rely on the maven wrapper instead of expecting Maven to be provided by the base image. First, it allows the user to decide which version of Maven should be used (3.6.3 vs. 3.8.1). It also makes the usage of Gradle straightforward.
That new requirement demand the user to run mvn -N io.takari:maven:0.7.7:wrapper first to install the maven wrapper if not already there.

@maxandersen @n1hility @geoand @mkouba WDYT? (I didn't create a PR yet, because I want to discuss it first).

NOTE: The go-offline is used to provision in its own layer the required dependencies, meaning that if you change your code and re-build it will recover from the layer COPY src ...

@cescoffier cescoffier added the area/housekeeping Issue type for generalized tasks not related to bugs or enhancements label Apr 28, 2021
@geoand
Copy link
Contributor

geoand commented Apr 28, 2021

I personally like it a lot!

@cescoffier
Copy link
Member Author

Should we move forward?

@mkouba
Copy link
Contributor

mkouba commented Apr 30, 2021

I'm not a big fan of maven wrapper but it sounds reasonable if we document this requirement properly.

@maxandersen
Copy link
Member

I'm +1

I do think we will evolve this in future anyway if buildpack becomes viable.

But removing need for this monster of image is worth more than having mvn wrapper use imo.

Users who need/want that can customize as need.

@cescoffier
Copy link
Member Author

Ok, I will open a PR tomorrow.

@cescoffier cescoffier changed the title Redesign the multi-staged docker build Redesign the multi-stage docker build May 2, 2021
cescoffier added a commit to cescoffier/quarkus that referenced this issue May 2, 2021
The change follows the discussion from quarkusio#16881.
It avoids relying on the centos-quarkus-maven image that should be deprecated.
Instead, it relies on the native-image image, and uses the maven/gradle wrappers.
It also allows using Mandrel easily.

Fix quarkusio#16881.
cescoffier added a commit to cescoffier/quarkus that referenced this issue May 3, 2021
The change follows the discussion from quarkusio#16881.
It avoids relying on the centos-quarkus-maven image that should be deprecated.
Instead, it relies on the native-image image, and uses the maven/gradle wrappers.
It also allows using Mandrel easily.

Fix quarkusio#16881.
@quarkus-bot quarkus-bot bot added this to the 2.0 - main milestone May 3, 2021
@ThoSap
Copy link

ThoSap commented Jun 8, 2021

RHEL 8.4 was released on 2021-05-21 😉
Can we update the base image to registry.access.redhat.com/ubi8/ubi-minimal:8.4?

@geoand
Copy link
Contributor

geoand commented Jun 8, 2021

#17764 should take care of it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/housekeeping Issue type for generalized tasks not related to bugs or enhancements
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants