Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static Builds for Netlify etc #99

Closed
edjw opened this issue Dec 6, 2024 · 1 comment
Closed

Static Builds for Netlify etc #99

edjw opened this issue Dec 6, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@edjw
Copy link

edjw commented Dec 6, 2024

I've been experimenting with making a static build with "spatie/laravel-export" so that a Prezet site could go on a service like Netlify.

I haven't tried to make search work. It might be possible to use a tool like Pagefind either in the after hook of laravel-export or in the Github action, along with some clientside JS to get that working.

I think this below is working now though for static builds of a Prezet site.

  1. Run composer require spatie/laravel-export

  2. Use a Github Action like this below. Set NETLIFY_AUTH_TOKEN and NETLIFY_SITE_ID as secrets and DEPLOY_URL as a variable in your Github Action.

It's a bit hacky. The issue is that laravel-export seems to need APP_URL to be set to localhost for its server to work. But then you want hrefs etc to be set to your Netlify production URL in the html files that laravel-export generates.

name: Build and Deploy

on:
  push:
    branches: [main]
  workflow_dispatch:

jobs:
  deploy:
    runs-on: ubuntu-latest
    environment:
      name: production
      url: ${{ vars.DEPLOY_URL }}

    steps:
      - uses: actions/checkout@v4

      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: "8.3"
          extensions: dom, curl, libxml, mbstring, zip

      - name: Install PHP Dependencies
        run: composer install --prefer-dist --no-progress --optimize-autoloader --no-interaction

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: "22"

      - name: Install Node Dependencies
        run: npm ci

      - name: Build Assets
        run: npm run build

      - name: Create env
        run: |
          cp .env.example .env
          php artisan key:generate
          sed -i "s|APP_URL=.*|APP_URL=http://localhost|" .env
          sed -i "s|ASSET_URL=.*|ASSET_URL=http://localhost|" .env
          touch database/database.sqlite
          php artisan migrate

      - name: Directory Permissions
        run: chmod -R 777 storage bootstrap/cache

      - name: Export Pages
        run: php artisan export --skip-before --skip-after

      - name: Update URLs
        run: |
          find dist -type f -name "*.html" -exec sed -i "s|http://localhost|${{ vars.DEPLOY_URL }}|g" {} +
          find dist -type f -name "*.css" -exec sed -i "s|http://localhost|${{ vars.DEPLOY_URL }}|g" {} +
          find dist -type f -name "*.js" -exec sed -i "s|http://localhost|${{ vars.DEPLOY_URL }}|g" {} +
          find dist -type f -name "*.xml" -exec sed -i "s|http://localhost|${{ vars.DEPLOY_URL }}|g" {} +

      - name: Deploy to Netlify
        env:
          NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
          NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
        run: npx netlify-cli deploy --dir=dist --prod --message "${GITHUB_SHA::8}"

      - uses: actions/upload-artifact@v4
        if: failure()
        with:
          name: laravel-logs
          path: storage/logs/laravel.log
@edjw edjw added the bug Something isn't working label Dec 6, 2024
@edjw
Copy link
Author

edjw commented Dec 6, 2024

Sorry I can't remove the bug label

@benbjurstrom benbjurstrom added enhancement New feature or request and removed bug Something isn't working labels Dec 21, 2024
Repository owner locked and limited conversation to collaborators Jan 24, 2025
@benbjurstrom benbjurstrom converted this issue into discussion #128 Jan 24, 2025

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants