diff --git a/deploy/deploy.sh b/deploy/deploy.sh new file mode 100644 index 000000000..25b9a3979 --- /dev/null +++ b/deploy/deploy.sh @@ -0,0 +1,50 @@ +#!/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)" diff --git a/deploy/deploy_staging.sh b/deploy/deploy_staging.sh deleted file mode 100644 index f2d623259..000000000 --- a/deploy/deploy_staging.sh +++ /dev/null @@ -1,57 +0,0 @@ -#!/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)" \ No newline at end of file