From 2488b5eea71a807042bcc2c6afd3399010390a58 Mon Sep 17 00:00:00 2001 From: liubocheng <22913113@qq.com> Date: Tue, 25 Mar 2025 17:40:13 +0800 Subject: [PATCH] =?UTF-8?q?dev:=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/deploy-dev.yml | 43 +++++++++++++++++++++++++++++++++ docker-compose.yml | 23 ++++++++++++++++++ nginx.conf | 15 ++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 .gitea/workflows/deploy-dev.yml create mode 100644 docker-compose.yml create mode 100644 nginx.conf diff --git a/.gitea/workflows/deploy-dev.yml b/.gitea/workflows/deploy-dev.yml new file mode 100644 index 0000000..15e9bb0 --- /dev/null +++ b/.gitea/workflows/deploy-dev.yml @@ -0,0 +1,43 @@ +name: Deploy to Test +on: + push: + branches: [dev] # 根据实际分支调整 + +jobs: + deploy: + runs-on: php7.3 # 必须同时包含两个标签 + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Prepare SSH environment + env: + SSH_PRIVATE_KEY: ${{ secrets.TEST_SSH_KEY }} # 从 Gitea Secrets 读取私钥[2](@ref) + run: | + mkdir -p ~/.ssh + echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa + chmod 600 ~/.ssh/id_rsa + # 将服务器指纹加入已知主机(规避首次连接确认) + ssh-keyscan 43.142.97.39 >> ~/.ssh/known_hosts + + - name: Sync code to server + run: | + rsync -avz --delete --exclude=".env" \ + ./ deploy-user@43.142.97.39:/data/laravel_test/ + + - name: Deploy Docker containers + run: | + ssh -o StrictHostKeyChecking=no deploy-user@43.142.97.39 << 'EOF' + cd /data/laravel_test + + # 启动/重建 Docker 容器(需预置 docker-compose.yml) + docker compose -p laravel_test down --volumes + docker compose -p laravel_test up -d --build + + # 在 PHP 容器内执行 Laravel 命令 + docker exec laravel_test-php-1 php artisan config:cache + docker exec laravel_test-php-1 php artisan migrate --force + + # 重载 Nginx 容器配置 + docker exec laravel_test-nginx-1 nginx -s reload + EOF diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..03bf6c1 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,23 @@ +version: '3.8' +services: + php: + image: php:7.3-fpm + volumes: + - /data/laravel_test:/var/www/html + working_dir: /var/www/html + networks: + - laravel_net + + nginx: + image: nginx:1.18 + ports: + - "80:80" + volumes: + - /data/laravel_test:/var/www/html + - ./nginx.conf:/etc/nginx/conf.d/default.conf + networks: + - laravel_net + +networks: + laravel_net: + driver: bridge diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..d5e29ed --- /dev/null +++ b/nginx.conf @@ -0,0 +1,15 @@ +server { + listen 80; + root /var/www/html/public; + index index.php; + + location / { + try_files $uri $uri/ /index.php?$query_string; + } + + location ~ \.php$ { + fastcgi_pass php:9000; + include fastcgi_params; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + } +}