6a7d98b0fe
Run Tests / test (pull_request) Successful in 32s
Dockerfile 改 multi-stage(app + web),app/scheduler/queue-worker/ reverb/nginx 五個服務都不再依賴 ./:/var/www bind mount 取得程式碼; nginx 改本地 build 從 app 階段 COPY --from 取得 public/,public/storage symlink 在兩階段各自於 build 時建立。docker-compose.yml 新增具名 volume storage-app-public 讓上傳檔案跨 image 重建保留;env_file: 取代原本 bind mount 帶入 .env 的方式,只給四個 Laravel runtime 服務。 compose.override.yml 補上開發用 bind mount 維持改 code 立即生效; docker-entrypoint.sh 收斂到只剩目錄權限設定,migration/cache/swagger 移到 deploy.yml 統一負責,避免職責重疊。 實作驗證時發現並修復三個規劃階段沒預見的問題:app 服務的 build: 缺 target: app 導致預設建到最後一個 stage(image 實際變成 nginx); .dockerignore 需排除本機既有的 public/storage 符號連結(Windows 上 會讓 build context 打包失敗);env_file: 讓 .env 全部變數變成真實 環境變數、蓋掉 phpunit.xml 的測試隔離設定,已擴大 tests/bootstrap.php 的強制覆蓋清單修復(239 tests 全綠)。 本機 dev 模式與 production 模式(無 override)皆完整驗證:healthcheck、 migration/cache/swagger、上傳檔案持久性、nginx 獨立於 app 服務靜態檔 與 storage 檔案、.env 熱更新、nginx 無 .env 存取權。 openspec change: bake-image-remove-bind-mount Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0142LC1kQb8EyV59TjHDkhWS
68 lines
2.0 KiB
YAML
68 lines
2.0 KiB
YAML
name: Deploy Production
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- master
|
|
|
|
jobs:
|
|
deploy:
|
|
runs-on: self-hosted
|
|
steps:
|
|
- name: Pull latest code
|
|
run: |
|
|
cd /root/myproject/CFDivePlatform
|
|
flock /tmp/cfdive-deploy.lock git fetch origin
|
|
git reset --hard origin/master
|
|
|
|
- name: Build images
|
|
run: |
|
|
cd /root/myproject/CFDivePlatform
|
|
docker compose build
|
|
|
|
- name: Start containers with new images
|
|
run: |
|
|
cd /root/myproject/CFDivePlatform
|
|
docker compose up -d --remove-orphans
|
|
|
|
- name: Wait for app container healthy
|
|
run: |
|
|
cd /root/myproject/CFDivePlatform
|
|
for i in $(seq 1 30); do
|
|
status=$(docker inspect --format='{{.State.Health.Status}}' cfdive-app 2>/dev/null || echo "starting")
|
|
if [ "$status" = "healthy" ]; then
|
|
echo "✅ app container healthy"
|
|
exit 0
|
|
fi
|
|
echo "⏳ waiting for app healthy... ($status)"
|
|
sleep 2
|
|
done
|
|
echo "❌ app container did not become healthy in time"
|
|
exit 1
|
|
|
|
- name: Run migrations
|
|
run: |
|
|
cd /root/myproject/CFDivePlatform
|
|
docker compose exec -T app php artisan migrate --force
|
|
|
|
- name: Cache configs
|
|
run: |
|
|
cd /root/myproject/CFDivePlatform
|
|
docker compose exec -T app php artisan config:cache
|
|
docker compose exec -T app php artisan route:cache
|
|
docker compose exec -T app php artisan view:cache
|
|
docker compose exec -T app php artisan event:cache
|
|
|
|
- name: Generate Swagger docs
|
|
run: |
|
|
cd /root/myproject/CFDivePlatform
|
|
docker compose exec -T app php artisan l5-swagger:generate
|
|
|
|
- name: Rebuild frontend (if changed)
|
|
run: |
|
|
cd /root/myproject/CFDivePlatform
|
|
if git diff --name-only HEAD~1 HEAD | grep -q '^frontend/'; then
|
|
docker compose build frontend
|
|
docker compose up -d frontend
|
|
fi
|