Ballerina本地构建返回UUID包错误。

huangapple go评论96阅读模式
英文:

Ballerina Native Build Returns an Error for UUID Package

问题

我正在使用Ballerina本机构建我的微服务。本机构建失败,并显示以下日志。

ERROR [ballerina/uuid/1.3.0::/root/.ballerina/repositories/central.ballerina.io/bala/ballerina/uuid/1.3.0/java11/modules/uuid/utils.bal:(23:28,23:46)] '0x8000000000000000' is out of range for 'int'
ERROR [ballerina/uuid/1.3.0::/root/.ballerina/repositories/central.ballerina.io/bala/ballerina/uuid/1.3.0/java11/modules/uuid/utils.bal:(23:28,23:46)] '0x8000000000000000' is out of range for 'int'

dependencies.toml引用了以下的uuid模块:

[[package]]
org = "ballerina"
name = "uuid"
version = "1.3.0"
dependencies = [
    {org = "ballerina", name = "crypto"},
    {org = "ballerina", name = "jballerina.java"},
    {org = "ballerina", name = "lang.int"},
    {org = "ballerina", name = "regex"},
    {org = "ballerina", name = "time"}
]
modules = [
    {org = "ballerina", packageName = "uuid", moduleName = "uuid"}
]

Dockerfile如下所示:

FROM ubuntu AS ballerina-builder
USER root
ADD . /src
WORKDIR /src

RUN apt-get update && apt-get -y install wget curl build-essential libz-dev zlib1g-dev && \
    wget https://dist.ballerina.io/downloads/2201.3.2/ballerina-2201.3.2-swan-lake-linux-x64.deb && \
    dpkg -i ballerina-2201.3.2-swan-lake-linux-x64.deb && rm ballerina-2201.3.2-swan-lake-linux-x64.deb && \
    curl -sL https://get.graalvm.org/jdk > install-graalvm.sh && chmod a+x install-graalvm.sh && ./install-graalvm.sh && \
    export PATH="/src/graalvm-ce-java17-22.3.1/bin:$PATH" && export JAVA_HOME="/src/graalvm-ce-java17-22.3.1" && \
    bal build --native

FROM adoptopenjdk/openjdk11:jre-11.0.14.1_1-alpine
WORKDIR /home/ballerina

RUN addgroup troupe \
    && adduser -S -s /bin/bash -g 'ballerina' -G troupe -D ballerina \
    && apk add --update --no-cache bash \
    && apk update && apk add --upgrade busybox libcrypto1.1 libssl1.1 \
    && chown -R ballerina:troupe /opt/java/openjdk/bin/java \
    && rm -rf /var/cache/apk/*

COPY --from=ballerina-builder /src/target/bin/myservice.api.jar /home/ballerina
COPY --from=ballerina-builder /src/Config.toml /home/ballerina
RUN chown ballerina /home/ballerina/myservice.api.jar

USER ballerina

CMD java -XX:InitialRAMPercentage=50.0 -XX:+UseContainerSupport -XX:MinRAMPercentage=75.0 -XX:MaxRAMPercentage=75.0 -jar myservice.api.jar \
    || cat ballerina-internal.log

如何解决这个错误?

英文:

I am in the process of utilizing ballerina native build in my microservice. The native build fails with the following log.

ERROR [ballerina/uuid/1.3.0::/root/.ballerina/repositories/central.ballerina.io/bala/ballerina/uuid/1.3.0/java11/modules/uuid/utils.bal:(23:28,23:46)] '0x8000000000000000' is out of range for 'int'
ERROR [ballerina/uuid/1.3.0::/root/.ballerina/repositories/central.ballerina.io/bala/ballerina/uuid/1.3.0/java11/modules/uuid/utils.bal:(23:28,23:46)] '0x8000000000000000' is out of range for 'int'

The dependencies.toml refers to the following uuid module/s

[[package]]
org = "ballerina"
name = "uuid"
version = "1.3.0"
dependencies = [
	{org = "ballerina", name = "crypto"},
	{org = "ballerina", name = "jballerina.java"},
	{org = "ballerina", name = "lang.int"},
	{org = "ballerina", name = "regex"},
	{org = "ballerina", name = "time"}
]
modules = [
	{org = "ballerina", packageName = "uuid", moduleName = "uuid"}
]

The Dockerfile is as follows.

FROM ubuntu AS ballerina-builder
USER root
ADD . /src
WORKDIR /src

RUN apt-get update && apt-get -y install wget curl build-essential libz-dev zlib1g-dev && \
    wget https://dist.ballerina.io/downloads/2201.3.2/ballerina-2201.3.2-swan-lake-linux-x64.deb && \
    dpkg -i ballerina-2201.3.2-swan-lake-linux-x64.deb && rm ballerina-2201.3.2-swan-lake-linux-x64.deb && \
    curl -sL https://get.graalvm.org/jdk >install-graalvm.sh && chmod a+x install-graalvm.sh && ./install-graalvm.sh && \
    export PATH="/src/graalvm-ce-java17-22.3.1/bin:$PATH" && export JAVA_HOME="/src/graalvm-ce-java17-22.3.1" && \
    bal build --native

FROM adoptopenjdk/openjdk11:jre-11.0.14.1_1-alpine
WORKDIR /home/ballerina

RUN addgroup troupe \
    && adduser -S -s /bin/bash -g 'ballerina' -G troupe -D ballerina \
    && apk add --update --no-cache bash \
    && apk update && apk add --upgrade busybox libcrypto1.1 libssl1.1 \ 
    && chown -R ballerina:troupe /opt/java/openjdk/bin/java \
    && rm -rf /var/cache/apk/*

COPY --from=ballerina-builder /src/target/bin/myservice.api.jar /home/ballerina
COPY --from=ballerina-builder /src/Config.toml /home/ballerina
RUN chown ballerina /home/ballerina/myservice.api.jar

USER ballerina

CMD java -XX:InitialRAMPercentage=50.0 -XX:+UseContainerSupport -XX:MinRAMPercentage=75.0 -XX:MaxRAMPercentage=75.0 -jar myservice.api.jar \
    || cat ballerina-internal.log

How do I fix this error?

答案1

得分: 2

GraalVM native-image 构建支持 Ballerina 2201.3.0(SwanLake)或更高版本。因此,GraalVM 兼容的 uuid 版本是 1.4.0

您的 Dependencies.toml 已更新为较低版本。这可能是因为您在本地使用比 2201.3.0 更低版本的 Ballerina 构建它。

在 Docker 文件中,您正在拉取 Ballerina 2201.3.2。因此,我认为您提到的错误是由编译器引发的。这是预期的,因为您的 Dependencies.toml 指向不兼容的版本。您可以尝试删除 Dependencies.toml 文件,或者将其更新为 Docker 文件中使用的版本。

除了上述问题之外,Docker 文件中拉取的 GraalVM 版本与 Ballerina 不兼容。您应该安装 GraalVM java 11 支持的版本,并设置 GRAALVM_HOME

Ballerina 提供了一个 --cloud 选项,用于为您生成 Docker 文件。您可以使用 bal build --native --cloud=docker。有关更多信息,请参阅 构建本机可执行文件

英文:

The GraalVM native-image build is supported in Ballerina 2201.3.0(SwanLake) or greater. So the GraalVM compatible uuid version is 1.4.0.

Your Dependencies.toml has been updated with a lower version. This might be because you have build it locally with a Ballerina version lower than 2201.3.0.

In the docker file you are pulling Ballerina 2201.3.2. So I believe the error you mentioned is thrown from the compiler. This is expected as your Dependencies.toml is pointing to the incompatible versions. You can try by deleting the Dependencies.toml or update it with the version used in the docker file.

In addition to the above issue, the GraalVM version pulled in the docker file is incompatible with Ballerina. You should install GraalVM java 11 supported version with native-image build tool and set GRAALVM_HOME.

Ballerina provides a --cloud option to generate the docker file for you. You could use bal build --native --cloud=docker. For more information, see Build a native executable.

huangapple
  • 本文由 发表于 2023年5月29日 17:19:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/76356094.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定