#!/usr/bin/env bash # 生成 jre-8.tar.gz 供 Dockerfile 中 ADD 使用: # 下载 Dragonwell 8(Standard,运行时包)→ 解包 → 删除体积大的 lib/src.zip → 重新打包 → 清理解包目录 # jdk.java.net 官方归档最早只到 JDK 9,JDK 8 没有官方 GA 二进制,故改用阿里 Dragonwell 发行版 # 下载的原包 SRC_PKG 保留在本地,重复执行时直接复用、不再重新下载 # 打包时不写入 macOS 扩展属性/ACL:BSD tar 会把 xattr 编码成 AppleDouble(./._*)条目放进包里, # BuildKit 的 ADD 解包这种包会报 lsetxattr ... xattr "com.apple.provenance": no such file or directory # 产物已存在时直接复用,重复执行不会重新下载 set -euo pipefail cd "$(dirname "$0")" # https://dragonwell.oss-cn-shanghai.aliyuncs.com/8.30.29/ VERSION=8.30.29 PKG=jre-8.tar.gz SRC_DIR=dragonwell-${VERSION} SRC_PKG=Alibaba_Dragonwell_Standard_${VERSION}_x64_linux.tar.gz URL=https://dragonwell.oss-cn-shanghai.aliyuncs.com/${VERSION}/${SRC_PKG} if [ -f "${PKG}" ]; then echo "${PKG} 已存在,跳过" exit 0 fi if [ ! -f "${SRC_PKG}" ]; then curl -fL -o "${SRC_PKG}" "${URL}" fi tar -xzf "${SRC_PKG}" rm -f "${SRC_DIR}/lib/src.zip" # macOS 解包会给文件带上 com.apple.provenance 等扩展属性,BSD tar 会把它们编码成 AppleDouble # (./._*)条目写进包内,BuildKit 的 ADD 解包时就报 lsetxattr ... no such file or directory # 注意:xattr -c 对 JDK 内 0444 的 legal/* 文件无权限清不掉,且清掉后也会再次被 macOS 打上, # 所以不能靠清 xattr,必须让 tar 不写扩展属性:--no-xattrs 不够,还要 COPYFILE_DISABLE=1 COPYFILE_DISABLE=1 tar --no-xattrs --no-acls -czf "${PKG}" "${SRC_DIR}" # 只清理解包出来的目录,保留下载的原包 SRC_PKG 以便复用 rm -rf "${SRC_DIR}" ./build.sh