【发布时间】:2021-09-06 07:26:02
【问题描述】:
我有 GitHub Actions,它使用 rust-cross 为 arm64 和其他硬件平台执行交叉编译。
我已经在主机上执行了交叉编译,并希望只使用要复制到Dockerfile 中的二进制文件和静态库并创建一个轻量级的 Alpine 容器。
警告
在rust-cross中发布的二进制文件在特定目录下,例如:
arm64 -> target/aarch64-unknown-linux-gnu/release/
amd64 -> target/x86_64-unknown-linux-musl/release/
armv7 -> target/armv7-unknown-linux-gnueabihf/release/
试验
我正在尝试在我的Dockerfile 中使用case,它依赖于docker buildx 套件提供并基于来自BretFisher/multi-platform-docker 的一些有据可查的存储库提供TARGETPLATFORM
FROM alpine as base
FROM --platform=${BUILDPLATFORM} alpine as tiny-project
# Use BuildKit to help translate architecture names
ARG TARGETPLATFORM
RUN case ${TARGETPLATFORM} in \
"linux/amd64") TARGET_DIR=x86_64-unknown-linux-musl ;; \
"linux/arm64") TARGET_DIR=aarch64-unknown-linux-gnu ;; \
*) exit 1 \ # ignore other architectures for now!
esac \
WORKDIR /app
RUN cp target/<HOW TO PASS VALUE TARGET_DIR>/release/myBinary .
RUN cp target/<HOW TO PASS VALUE TARGET_DIR>/release/*.so .
FROM base as release
COPY --from=tiny-project /app/* ./
RUN echo '#!/bin/ash' > /entrypoint.sh
RUN echo 'echo " * Starting: /myBinary $*"' >> /entrypoint.sh
RUN echo 'exec /myBinary $*' >> /entrypoint.sh
RUN chmod +x /entrypoint.sh
EXPOSE 7447/udp
EXPOSE 7447/tcp
EXPOSE 8000/tcp
ENV RUST_LOG info
ENTRYPOINT ["/entrypoint.sh"]
我尝试了很多变化,但似乎TARGET_DIR 在主机上没有被识别
RUN cp ./target/$(echo $TARGET_DIR)/release/myBinary /
RUN cp ./target/$(echo $TARGET_DIR)/release/*.so /
# as well as storing the value in a file and calling it
# echo aarch64-unknown-linux-gnu > /tmp/rust_target.txt
RUN cp ./target/$(cat /tmp/rust_target.txt)/release/zenohd /
RUN cp ./target/$(cat /tmp/rust_target.txt)/release/*.so /
但似乎文件和变量都不适用于主机,并且在我的 GitHub 操作工作流日志中不断收到错误
要求
我希望保留一个Dockerfile,并基于来自docker buildx build 命令的platform,我想将二进制文件从适当的源目录复制到Dockerfile 中的目标目录。
如何做到这一点?
【问题讨论】:
标签: docker rust dockerfile rust-cargo