mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-02-20 22:11:01 +08:00
@@ -1,50 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# 用法:
|
||||
# ./deploy.sh staging
|
||||
# ./deploy.sh prod
|
||||
env="${1:-staging}" # staging | prod
|
||||
project="openisle_${env}"
|
||||
|
||||
repo_dir="/opt/openisle/OpenIsle-${env}"
|
||||
compose_file="${repo_dir}/docker/docker-compose.yaml"
|
||||
env_file="${repo_dir}/.env.${env}"
|
||||
|
||||
echo "👉 Enter repo..."
|
||||
cd "$repo_dir"
|
||||
|
||||
echo "👉 Sync & checkout..."
|
||||
git fetch --all --prune
|
||||
git checkout -B "main" "origin/main"
|
||||
git reset --hard "origin/main"
|
||||
|
||||
echo "👉 Ensure env file: $env_file"
|
||||
[ -f "$env_file" ] || { echo "❌ $env_file missing"; exit 1; }
|
||||
|
||||
export COMPOSE_PROJECT_NAME="$project"
|
||||
export ENV_FILE="$env_file"
|
||||
|
||||
echo "👉 Validate compose..."
|
||||
docker compose -f "$compose_file" --env-file "$env_file" config >/dev/null
|
||||
|
||||
echo "👉 Pull images..."
|
||||
docker compose -f "$compose_file" --env-file "$env_file" pull --ignore-pull-failures
|
||||
|
||||
echo "👉 Build custom images..."
|
||||
docker compose -f "$compose_file" --env-file "$env_file" \
|
||||
build --pull \
|
||||
--build-arg NUXT_ENV="$env" \
|
||||
frontend_service opensearch
|
||||
|
||||
echo "👉 Up services..."
|
||||
docker compose -f "$compose_file" --env-file "$env_file" up -d --force-recreate --remove-orphans \
|
||||
mysql redis rabbitmq opensearch dashboards websocket-service springboot frontend_service
|
||||
|
||||
echo "👉 Status"
|
||||
docker compose -f "$compose_file" --env-file "$env_file" ps
|
||||
|
||||
echo "👉 Prune dangling images"
|
||||
docker image prune -f
|
||||
|
||||
echo "✅ ${env} stack deployed at $(date)"
|
||||
57
deploy/deploy_staging.sh
Normal file
57
deploy/deploy_staging.sh
Normal file
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# 可用法:
|
||||
# ./deploy-staging.sh
|
||||
# ./deploy-staging.sh feature/docker
|
||||
deploy_branch="${1:-feature/docker}"
|
||||
|
||||
repo_dir="/opt/openisle/OpenIsle-staging"
|
||||
compose_file="${repo_dir}/docker/docker-compose.yaml"
|
||||
# 使用仓库根目录的 .env(CI 预先写好),也可以改成绝对路径
|
||||
env_file="${repo_dir}/.env"
|
||||
project="openisle_staging"
|
||||
|
||||
echo "👉 Enter repo..."
|
||||
cd "$repo_dir"
|
||||
|
||||
echo "👉 Syncing code & switching to branch: $deploy_branch"
|
||||
git fetch --all --prune
|
||||
git checkout -B "$deploy_branch" "origin/$deploy_branch"
|
||||
git reset --hard "origin/$deploy_branch"
|
||||
|
||||
echo "👉 Ensuring env file: $env_file"
|
||||
if [ ! -f "$env_file" ]; then
|
||||
echo "❌ ${env_file} not found. Create it based on .env.example (with staging domains)."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
export COMPOSE_PROJECT_NAME="$project"
|
||||
# 供 compose 内各 service 的 env_file 使用
|
||||
export ENV_FILE="$env_file"
|
||||
|
||||
echo "👉 Validate compose..."
|
||||
docker compose -f "$compose_file" --env-file "$env_file" config >/dev/null
|
||||
|
||||
echo "👉 Pull base images (for image-based services)..."
|
||||
docker compose -f "$compose_file" --env-file "$env_file" pull --ignore-pull-failures
|
||||
|
||||
echo "👉 Build images (staging)..."
|
||||
# 前端 + OpenSearch 都是自建镜像;--pull 更新其基础镜像
|
||||
docker compose -f "$compose_file" --env-file "$env_file" \
|
||||
build --pull \
|
||||
--build-arg NUXT_ENV=staging \
|
||||
frontend_service opensearch
|
||||
|
||||
echo "👉 Recreate & start all target services (no dev profile)..."
|
||||
docker compose -f "$compose_file" --env-file "$env_file" \
|
||||
up -d --force-recreate --remove-orphans \
|
||||
mysql redis rabbitmq opensearch dashboards websocket-service springboot frontend_service
|
||||
|
||||
echo "👉 Current status:"
|
||||
docker compose -f "$compose_file" --env-file "$env_file" ps
|
||||
|
||||
echo "👉 Pruning dangling images..."
|
||||
docker image prune -f
|
||||
|
||||
echo "✅ Staging stack deployed at $(date)"
|
||||
Reference in New Issue
Block a user