Commit d908e226 by ccran

feat: update Dockerfile and publish scripts.

parent 522456c3
FROM docker.m.daocloud.io/oven/bun:1.4.0@sha256:5ff609364c049b54eb0ff560ec96319729a972078ef2c755d758f0c6ef89c2d6 AS builder
# Frontend output is platform-independent; run Bun on the build host architecture.
FROM --platform=$BUILDPLATFORM docker.m.daocloud.io/oven/bun:1.4.0@sha256:5ff609364c049b54eb0ff560ec96319729a972078ef2c755d758f0c6ef89c2d6 AS builder
WORKDIR /build/web
COPY web/package.json web/bun.lock ./
RUN bun install --frozen-lockfile
COPY web/package.json web/bun.lock web/.npmrc ./
# Limit simultaneous downloads for more reliable installs through network proxies.
RUN bun install --frozen-lockfile --network-concurrency 4
COPY ./web ./
COPY ./VERSION /build/VERSION
RUN DISABLE_ESLINT_PLUGIN='true' VITE_REACT_APP_VERSION=$(cat /build/VERSION) bun run build
......
#!/bin/bash
# 在 Mac(包括 Apple Silicon)上构建目标架构镜像,上传到 Ubuntu 并导入。
# 用法:bash bin/docker-upload-ubuntu.sh [user@host]
# 示例:SSH_PORT=22 IMAGE_TAG=new-api:export bash bin/docker-upload-ubuntu.sh
# SSH 使用本机 ~/.ssh/config、密钥或交互式密码认证。
set -euo pipefail
if [[ "${1:-}" == "--help" || "${1:-}" == "-h" ]]; then
sed -n '2,5p' "$0"
exit 0
fi
if (( $# > 1 )); then
echo "用法:bash $0 [user@host]" >&2
exit 1
fi
remote_host=${1:-root@8.136.9.68}
ssh_port=${SSH_PORT:-22}
image_tag=${IMAGE_TAG:-new-api:export}
project_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
if [[ "$remote_host" == -* || "$remote_host" == *[[:space:]]* || -z "$remote_host" ]]; then
echo "无效的 SSH 目标:$remote_host" >&2
exit 1
fi
if [[ ! "$ssh_port" =~ ^[0-9]+$ ]]; then
echo "SSH_PORT 必须是端口号。" >&2
exit 1
fi
for command_name in docker ssh scp; do
command -v "$command_name" >/dev/null || {
echo "缺少命令:$command_name" >&2
exit 1
}
done
docker info >/dev/null
docker buildx version >/dev/null
echo "检查 Ubuntu 架构及 Docker 权限:$remote_host"
remote_arch=$(ssh -p "$ssh_port" "$remote_host" 'set -e; docker info >/dev/null; uname -m')
case "$remote_arch" in
x86_64) platform=linux/amd64 ;;
aarch64|arm64) platform=linux/arm64 ;;
*) echo "不支持的远端架构:$remote_arch" >&2; exit 1 ;;
esac
# 临时文件放在构建上下文之外,避免将导出的镜像再次打包进镜像。
export_dir=$(mktemp -d "${TMPDIR:-/tmp}/new-api-export.XXXXXX")
trap 'rm -rf -- "$export_dir"' EXIT
archive_path="$export_dir/new-api-export.tar"
echo "构建 ${image_tag},目标平台:${platform}(跨架构构建可能较慢)"
docker buildx build --platform "$platform" --load \
--tag "$image_tag" --file "$project_dir/Dockerfile" "$project_dir"
echo "导出镜像"
docker save -o "$archive_path" "$image_tag"
echo "上传至 $remote_host:~/new-api-export.tar"
scp -P "$ssh_port" "$archive_path" "$remote_host:new-api-export.tar"
echo "在 Ubuntu 导入镜像"
ssh -p "$ssh_port" "$remote_host" 'docker load -i "$HOME/new-api-export.tar"'
echo "完成:远端已导入 ${image_tag}${platform})。"
echo "远端归档保留在 ~/new-api-export.tar;本地临时归档会自动删除。"
echo "现有容器不会自动重启,请在确认部署配置后重新创建容器。"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment