From fb7862baff214bed11248b7ee7da81482a10fd0f Mon Sep 17 00:00:00 2001 From: henry yo Date: Thu, 25 Jun 2026 21:23:58 +0800 Subject: [PATCH] fix: change docker-compose.yml --- .gitea/workflows/deploy.yaml | 29 +++++++++++++++++--------- docker-compose.yml | 40 +++++++++++++++++++----------------- 2 files changed, 40 insertions(+), 29 deletions(-) diff --git a/.gitea/workflows/deploy.yaml b/.gitea/workflows/deploy.yaml index 4432146..846a85d 100644 --- a/.gitea/workflows/deploy.yaml +++ b/.gitea/workflows/deploy.yaml @@ -16,14 +16,23 @@ jobs: - name: Create .env file run: echo "${{ secrets.ENV_FILE }}" > .env - - name: Deploy Backend Container + - name: Main Deploy Backend Container run: | - echo "📂 目前目錄底下的檔案列表:" - ls -la - - echo "🚀 開始執行純淨容器化部屬流程..." - # 如果本機的檔名不小心變小寫,我們強制讓 docker compose 指定目前現有的 Dockerfile 檔名 - # 同時移除 obsolete 的 version 屬性警告 - docker compose up -d --build --remove-orphans - - echo "🎉 部屬指令已發送!" \ No newline at end of file + # 1. 刪除舊容器 + docker rm -f finance-laravel-backend || true + + # 2. 啟動最乾淨的新容器 + docker run -d \ + --name finance-laravel-backend \ + --network 1panel-network \ + -p 8081:8000 \ + finance_app-finance-backend:latest + + # 3. 🎯 終極一指通:直接把整坨 ENV_FILE Secret 的文字,凌空灌進容器內變成實體檔案! + # 這樣管它有幾百個變數,通通一秒就定位,而且完全不留痕跡! + docker exec -i finance-laravel-backend sh -c "cat > .env" << 'EOF' + ${{ secrets.ENV_FILE }} + EOF + + # 4. 刷新 Laravel 快取 + docker exec -i finance-laravel-backend php artisan optimize:clear \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 54490f7..bfb7d5f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,26 +1,28 @@ -version: "3" services: - backend: - image: finance_app-finance-backend:latest + # 🐘 1. 你的 Laravel 後端服務 + finance-backend: + build: + context: . + dockerfile: Dockerfile container_name: finance-laravel-backend + restart: always + ports: + - "8081:9000" + environment: + - APP_ENV=production + - APP_DEBUG=false + - DB_CONNECTION=pgsql + - DB_HOST=finance-laravel-backend-postgres # 🎯 關鍵:改用資料庫的服務名稱當作 Host! + - DB_PORT=5432 + - DB_DATABASE=myfinance + - DB_USERNAME=myfinance_henry4682 + - DB_PASSWORD=DwmQ78PB networks: - 1panel-network - ports: - - "8081:8000" - environment: - APP_ENV: production - APP_DEBUG: "false" - APP_URL: https://fin-buddy.duckdns.org - DB_CONNECTION: pgsql - DB_HOST: finance-laravel-backend-postgres - DB_PORT: 5432 - DB_DATABASE: myfinance - DB_USERNAME: myfinance_henry4682 - DB_PASSWORD: DwmQ78PB - GOOGLE_REDIRECT_URI: https://fin-buddy.duckdns.org/auth/google/callback - GOOGLE_CLIENT_ID: 909352259943-vr216oea79h706ru7imm4lfdftej8qe0.apps.googleusercontent.com - GOOGLE_CLIENT_SECRET: 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 + depends_on: + - finance-postgres # 🎯 確保資料庫先開,後端才開 + # 🐬 2. 直接在這裡把消失的 PostgreSQL 生回來! finance-postgres: image: postgres:15-alpine # 使用穩定的 15-alpine 版本 container_name: finance-laravel-backend-postgres @@ -42,4 +44,4 @@ networks: # 🎯 定義資料庫的儲存卷 volumes: - finance_db_data: + finance_db_data: \ No newline at end of file