#!/bin/bash

# 泉友米车友会 - Docker 构建脚本
# 版本: 0.0.1

set -e

echo "=========================================="
echo "泉友米车友会 Docker 镜像构建"
echo "版本: 0.0.1"
echo "=========================================="

# 检查 Docker 是否安装
if ! command -v docker &> /dev/null; then
    echo "错误: Docker 未安装，请先安装 Docker"
    exit 1
fi

# 构建镜像
echo ""
echo "开始构建 Docker 镜像..."
docker build -t quanyoumi-app:0.0.1 -t quanyoumi-app:latest .

echo ""
echo "=========================================="
echo "构建完成！"
echo "=========================================="
echo ""
echo "镜像信息:"
docker images | grep quanyoumi-app
echo ""

# 标记镜像到阿里云仓库
echo "正在标记镜像到阿里云仓库..."
docker tag quanyoumi-app:0.0.1 registry.cn-hangzhou.aliyuncs.com/yvan329/quanyoumi-app:0.0.1
docker tag quanyoumi-app:latest registry.cn-hangzhou.aliyuncs.com/yvan329/quanyoumi-app:latest

echo ""
echo "正在推送镜像到阿里云仓库..."
docker push registry.cn-hangzhou.aliyuncs.com/yvan329/quanyoumi-app:0.0.1
docker push registry.cn-hangzhou.aliyuncs.com/yvan329/quanyoumi-app:latest

echo ""
echo "=========================================="
echo "推送完成！"
echo "=========================================="
echo ""
echo "镜像地址:"
echo "  registry.cn-hangzhou.aliyuncs.com/yvan329/quanyoumi-app:0.0.1"
echo "  registry.cn-hangzhou.aliyuncs.com/yvan329/quanyoumi-app:latest"
echo ""
echo "在 NAS 上使用:"
echo "  docker pull registry.cn-hangzhou.aliyuncs.com/yvan329/quanyoumi-app:0.0.1"
echo "  docker-compose up -d"
echo ""
