diff --git a/.gitea/SETUP.md b/.gitea/SETUP.md index 5cf82b51..323a4d2c 100644 --- a/.gitea/SETUP.md +++ b/.gitea/SETUP.md @@ -15,9 +15,11 @@ After pushing, the pipeline will run automatically. The following steps are requ | Variable Name | Default | Description | |---|---|---| | `SSH_PORT` | `22` | SSH port for the deployment server | -| `SSH_TARGET_DIR` | — | Absolute path on the server where the project is deployed | +| `SSH_TARGET_DIR` | — | Absolute path on the server where the Laravel app root goes | | `PRODUCTION_URL` | — | Public URL of the production site | +> **Note:** The deploy job runs `php artisan migrate`, `config:cache`, `route:cache`, `view:cache`, and `optimize` via SSH after uploading. The PHP CLI binary must be available on the shared hosting server. + ## 3. Allow Gitea Actions - Go to **Settings → Actions** in your Gitea repository diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index 8db8cce3..cbaf4ec6 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -245,11 +245,13 @@ jobs: fi # ────────────────────────────────────────────── - # DEPLOY (manual): to production via SSH + # DEPLOY (manual): to shared hosting via SSH # ────────────────────────────────────────────── deploy: - name: Deploy to production + name: Deploy to shared hosting (PHP) runs-on: ubuntu-latest + container: + image: php:8.3-cli if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' needs: [test, build, security] environment: @@ -259,21 +261,58 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 - - name: Install SSH client + - name: Install system dependencies run: | apt-get update - apt-get install -y --no-install-recommends openssh-client sshpass rsync + apt-get install -y --no-install-recommends \ + git unzip curl libzip-dev libpng-dev libonig-dev libxml2-dev \ + openssh-client sshpass rsync + docker-php-ext-install mbstring zip gd pdo_mysql - - name: Deploy via rsync + - name: Install Composer + run: | + php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" + php composer-setup.php --install-dir=/usr/local/bin --filename=composer + rm composer-setup.php + + - name: Install production PHP dependencies + run: | + composer install --no-dev --optimize-autoloader --no-interaction --no-progress + + - name: Download frontend build artifacts + uses: actions/download-artifact@v4 + with: + name: frontend-assets + path: ./ + + - name: Deploy Laravel app to shared hosting run: | sshpass -p "${{ secrets.SSH_PASSWORD }}" rsync -avz --delete \ -e "ssh -p ${{ vars.SSH_PORT || 22 }} -o StrictHostKeyChecking=no" \ --exclude='.env' \ --exclude='.git' \ + --exclude='.gitea' \ --exclude='tests' \ --exclude='storage/logs/*' \ - --exclude='database/sqlite' \ + --exclude='database/database.sqlite' \ --exclude='node_modules' \ - --exclude='vendor' \ + --exclude='.npm' \ + --exclude='reports' \ + --exclude='.phpunit.result.cache' \ + --exclude='package-lock.json' \ + --exclude='.composer-cache' \ ./ \ ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:${{ vars.SSH_TARGET_DIR }}/ + + - name: Post-deploy artisan commands + run: | + sshpass -p "${{ secrets.SSH_PASSWORD }}" ssh \ + -o StrictHostKeyChecking=no \ + -p ${{ vars.SSH_PORT || 22 }} \ + ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} \ + "cd ${{ vars.SSH_TARGET_DIR }} && \ + php artisan migrate --force && \ + php artisan config:cache && \ + php artisan route:cache && \ + php artisan view:cache && \ + php artisan optimize"