构建 Quarkus Native 问题
Building Quarkus Native issue
我正在尝试构建 Quarkus Native 应用程序,但在 Docker 内的进程构建期间访问被拒绝。我正在关注这个 doc
Docker文件:
# Limit memory of build
ARG BUILD_MEMORY=4g
## Stage 1: build native sources
FROM gradle:7.3-jdk11 AS gradle-build
COPY --chown=gradle:gradle build.gradle /code/
COPY --chown=gradle:gradle settings.gradle /code/
COPY --chown=gradle:gradle gradle.properties /code/
USER gradle
WORKDIR /code
COPY --chown=gradle:gradle src /code/src
RUN gradle clean assemble -Dquarkus.package.type=native-sources
## Stage 2: build quarkus-native
FROM quay.io/quarkus/ubi-quarkus-mandrel:21.2-java11 AS native-build
ARG BUILD_MEMORY
WORKDIR /build
COPY --from=gradle-build /code/build/native-sources /build/
RUN native-image $(cat native-image.args) -J-Xmx$BUILD_MEMORY
## Stage 3 : create the docker final image
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.5
WORKDIR /work/
COPY --from=native-build /build/*-runner /work/application
COPY docker-entrypoint.sh /work/entrypoint.sh
RUN chmod 775 /work && chmod 755 /work/entrypoint.sh
EXPOSE 8080
ENTRYPOINT [ "/work/entrypoint.sh" ]
CMD ["./application", "-Dquarkus.http.host=0.0.0.0"]
错误:
Step 14/22 : RUN native-image $(cat native-image.args) -J-Xmx$BUILD_MEMORY
---> Running in 5bda535214b1
[app-1.0.0-runner:73] classlist: 3,624.96 ms, 1.20 GB
...
[app-1.0.0-runner:73] write: 692.61 ms, 5.85 GB
Fatal error:java.lang.RuntimeException: There was an error linking the native image: Linker command exited with 1
Linker command executed:
/usr/bin/gcc -z noexecstack -Wl,--gc-sections -Wl,--dynamic-list -Wl,/tmp/SVM-4069521364666676056/exported_symbols.list -Wl,--exclude-libs,ALL -Wl,-x -o /build/app-1.0.0-runner app-1.0.0-runner.o /opt/mandrel/lib/svm/clibraries/linux-amd64/liblibchelper.a /opt/mandrel/lib/static/linux-amd64/glibc/libawt_headless.a /opt/mandrel/lib/static/linux-amd64/glibc/libawt.a /opt/mandrel/lib/static/linux-amd64/glibc/libnet.a /opt/mandrel/lib/static/linux-amd64/glibc/libextnet.a /opt/mandrel/lib/static/linux-amd64/glibc/libnio.a /opt/mandrel/lib/static/linux-amd64/glibc/libjava.a /opt/mandrel/lib/static/linux-amd64/glibc/libfdlibm.a /opt/mandrel/lib/static/linux-amd64/glibc/libsunec.a /opt/mandrel/lib/static/linux-amd64/glibc/libzip.a /opt/mandrel/lib/svm/clibraries/linux-amd64/libjvm.a -v -L/tmp/SVM-4069521364666676056 -L/opt/mandrel/lib/static/linux-amd64/glibc -L/opt/mandrel/lib/svm/clibraries/linux-amd64 -lstdc++ -lstdc++ -lm -lpthread -ldl -lz -lrt
Linker command output:
Using built-in specs.
COLLECT_GCC=/usr/bin/gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/8/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --disable-libmpx --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 8.5.0 20210514 (Red Hat 8.5.0-4) (GCC)
...
/usr/bin/ld: cannot open output file /build/app-1.0.0-runner: Permission denied
collect2: error: ld returned 1 exit status
...
[app-1.0.0-runner:73] [total]: 122,312.28 ms, 5.85 GB
Exception in thread "main" jdk.vm.ci.common.JVMCIError: java.nio.file.AccessDeniedException: /build/app-1.0.0-runner.build_artifacts.txt
Error: Image build request failed with exit status 1
似乎 native-image 命令没有创建 app-1.0.0-runner.build_artifacts.txt.
你能帮帮我吗?
此致。
问题是由复制指令前的 WORKDIR 子句引起的。
修复了 Dockerfile:
# Limit memory of build
ARG BUILD_MEMORY=4g
## Stage 1: build native sources
FROM gradle:7.3-jdk11 AS gradle-build
COPY --chown=gradle:gradle build.gradle /code/
COPY --chown=gradle:gradle settings.gradle /code/
COPY --chown=gradle:gradle gradle.properties /code/
USER gradle
WORKDIR /code
COPY --chown=gradle:gradle src /code/src
RUN gradle clean assemble -Dquarkus.package.type=native-sources
## Stage 2: build quarkus-native
FROM quay.io/quarkus/ubi-quarkus-mandrel:21.3-java11 AS native-build
ARG BUILD_MEMORY
COPY --chown=quarkus:quarkus --from=gradle-build /code/build/native-sources /build
USER quarkus
WORKDIR /build
RUN native-image $(cat native-image.args) -J-Xmx$BUILD_MEMORY
## Stage 3 : create the docker final image
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.5
WORKDIR /work/
COPY --from=native-build /build/*-runner /work/application
COPY docker-entrypoint.sh /work/entrypoint.sh
RUN chmod 775 /work && chmod 755 /work/entrypoint.sh
EXPOSE 8080
ENTRYPOINT [ "/work/entrypoint.sh" ]
CMD ["./application", "-Dquarkus.http.host=0.0.0.0"]
我正在尝试构建 Quarkus Native 应用程序,但在 Docker 内的进程构建期间访问被拒绝。我正在关注这个 doc
Docker文件:
# Limit memory of build
ARG BUILD_MEMORY=4g
## Stage 1: build native sources
FROM gradle:7.3-jdk11 AS gradle-build
COPY --chown=gradle:gradle build.gradle /code/
COPY --chown=gradle:gradle settings.gradle /code/
COPY --chown=gradle:gradle gradle.properties /code/
USER gradle
WORKDIR /code
COPY --chown=gradle:gradle src /code/src
RUN gradle clean assemble -Dquarkus.package.type=native-sources
## Stage 2: build quarkus-native
FROM quay.io/quarkus/ubi-quarkus-mandrel:21.2-java11 AS native-build
ARG BUILD_MEMORY
WORKDIR /build
COPY --from=gradle-build /code/build/native-sources /build/
RUN native-image $(cat native-image.args) -J-Xmx$BUILD_MEMORY
## Stage 3 : create the docker final image
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.5
WORKDIR /work/
COPY --from=native-build /build/*-runner /work/application
COPY docker-entrypoint.sh /work/entrypoint.sh
RUN chmod 775 /work && chmod 755 /work/entrypoint.sh
EXPOSE 8080
ENTRYPOINT [ "/work/entrypoint.sh" ]
CMD ["./application", "-Dquarkus.http.host=0.0.0.0"]
错误:
Step 14/22 : RUN native-image $(cat native-image.args) -J-Xmx$BUILD_MEMORY
---> Running in 5bda535214b1
[app-1.0.0-runner:73] classlist: 3,624.96 ms, 1.20 GB
...
[app-1.0.0-runner:73] write: 692.61 ms, 5.85 GB
Fatal error:java.lang.RuntimeException: There was an error linking the native image: Linker command exited with 1
Linker command executed:
/usr/bin/gcc -z noexecstack -Wl,--gc-sections -Wl,--dynamic-list -Wl,/tmp/SVM-4069521364666676056/exported_symbols.list -Wl,--exclude-libs,ALL -Wl,-x -o /build/app-1.0.0-runner app-1.0.0-runner.o /opt/mandrel/lib/svm/clibraries/linux-amd64/liblibchelper.a /opt/mandrel/lib/static/linux-amd64/glibc/libawt_headless.a /opt/mandrel/lib/static/linux-amd64/glibc/libawt.a /opt/mandrel/lib/static/linux-amd64/glibc/libnet.a /opt/mandrel/lib/static/linux-amd64/glibc/libextnet.a /opt/mandrel/lib/static/linux-amd64/glibc/libnio.a /opt/mandrel/lib/static/linux-amd64/glibc/libjava.a /opt/mandrel/lib/static/linux-amd64/glibc/libfdlibm.a /opt/mandrel/lib/static/linux-amd64/glibc/libsunec.a /opt/mandrel/lib/static/linux-amd64/glibc/libzip.a /opt/mandrel/lib/svm/clibraries/linux-amd64/libjvm.a -v -L/tmp/SVM-4069521364666676056 -L/opt/mandrel/lib/static/linux-amd64/glibc -L/opt/mandrel/lib/svm/clibraries/linux-amd64 -lstdc++ -lstdc++ -lm -lpthread -ldl -lz -lrt
Linker command output:
Using built-in specs.
COLLECT_GCC=/usr/bin/gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/8/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --disable-libmpx --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 8.5.0 20210514 (Red Hat 8.5.0-4) (GCC)
...
/usr/bin/ld: cannot open output file /build/app-1.0.0-runner: Permission denied
collect2: error: ld returned 1 exit status
...
[app-1.0.0-runner:73] [total]: 122,312.28 ms, 5.85 GB
Exception in thread "main" jdk.vm.ci.common.JVMCIError: java.nio.file.AccessDeniedException: /build/app-1.0.0-runner.build_artifacts.txt
Error: Image build request failed with exit status 1
似乎 native-image 命令没有创建 app-1.0.0-runner.build_artifacts.txt.
你能帮帮我吗?
此致。
问题是由复制指令前的 WORKDIR 子句引起的。
修复了 Dockerfile:
# Limit memory of build
ARG BUILD_MEMORY=4g
## Stage 1: build native sources
FROM gradle:7.3-jdk11 AS gradle-build
COPY --chown=gradle:gradle build.gradle /code/
COPY --chown=gradle:gradle settings.gradle /code/
COPY --chown=gradle:gradle gradle.properties /code/
USER gradle
WORKDIR /code
COPY --chown=gradle:gradle src /code/src
RUN gradle clean assemble -Dquarkus.package.type=native-sources
## Stage 2: build quarkus-native
FROM quay.io/quarkus/ubi-quarkus-mandrel:21.3-java11 AS native-build
ARG BUILD_MEMORY
COPY --chown=quarkus:quarkus --from=gradle-build /code/build/native-sources /build
USER quarkus
WORKDIR /build
RUN native-image $(cat native-image.args) -J-Xmx$BUILD_MEMORY
## Stage 3 : create the docker final image
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.5
WORKDIR /work/
COPY --from=native-build /build/*-runner /work/application
COPY docker-entrypoint.sh /work/entrypoint.sh
RUN chmod 775 /work && chmod 755 /work/entrypoint.sh
EXPOSE 8080
ENTRYPOINT [ "/work/entrypoint.sh" ]
CMD ["./application", "-Dquarkus.http.host=0.0.0.0"]