From f8a89cfa61b7effdd663a187023df1121b54e1cc Mon Sep 17 00:00:00 2001 From: Ata Sasmaz Date: Fri, 13 Oct 2023 13:29:18 +0100 Subject: [PATCH] Introduce dev server (#2) * . * test deploy * Update build-deploy.yml --- .github/workflows/build-deploy.yml | 2 +- .htaccess | 21 --------- Makefile | 6 ++- README.md | 31 ++++++------- config.json | 2 - layout/footer.php | 2 +- layout/header.php | 8 ++-- system/bin/dev-server-entrypoint.sh | 15 +++++++ .../{generate_html.sh => generate-html.sh} | 15 +++---- system/bootstrap.php | 38 +++++++++++++++- system/layoutUtils.php | 21 ++------- system/markdown.php | 2 +- system/workflow-image/nginx.conf | 44 ++++++++++++++++--- 13 files changed, 125 insertions(+), 82 deletions(-) delete mode 100644 .htaccess create mode 100755 system/bin/dev-server-entrypoint.sh rename system/bin/{generate_html.sh => generate-html.sh} (89%) diff --git a/.github/workflows/build-deploy.yml b/.github/workflows/build-deploy.yml index d760eeb..b21326a 100644 --- a/.github/workflows/build-deploy.yml +++ b/.github/workflows/build-deploy.yml @@ -46,7 +46,7 @@ jobs: - name: Generate HTML run: | - system/bin/generate_html.sh + system/bin/generate-html.sh - name: Upload artifact uses: actions/upload-artifact@v2 diff --git a/.htaccess b/.htaccess deleted file mode 100644 index e46befc..0000000 --- a/.htaccess +++ /dev/null @@ -1,21 +0,0 @@ -# Turn on the rewrite engine -RewriteEngine On - -RewriteCond %{HTTPS} off -RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] - -RewriteCond %{HTTP_HOST} !^www\. [NC] -RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] - -# For /page to /page.php?page=page -RewriteCond %{REQUEST_FILENAME} !-f -RewriteCond %{REQUEST_FILENAME} !-d -RewriteRule ^([a-zA-Z0-9-]+)$ /page.php?page=$1 [L] - -# Rewrite /p/something to /post.php?slug=something -RewriteRule ^p/(.*)$ /post.php?slug=$1 [L] - -# For extensionless PHP files -RewriteCond %{REQUEST_FILENAME} !-d -RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}.php -f -RewriteRule ^(.*?)/?$ $1.php [L] diff --git a/Makefile b/Makefile index 1acc73d..8d94e66 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,11 @@ build-local-image: docker build system/workflow-image -t atas-ssg-builder:latest run-local-image: - docker run --rm -it -v $(shell pwd):/github/workspace atas-ssg-builder:latest + docker run --rm -it -v $(shell pwd):/workspace atas-ssg-builder:latest + +dev-server: + docker run --rm -it --entrypoint /workspace/system/bin/dev-server-entrypoint.sh -p 8001:80 \ + -v $(shell pwd):/workspace atas-ssg-builder:latest # Updates the GHCR:latest image update-workflow-image: diff --git a/README.md b/README.md index cba478a..a22e51b 100644 --- a/README.md +++ b/README.md @@ -56,8 +56,8 @@ You can create any .php page at root directory or project or any subdirectory. ` `./my-custom.php` will be `yoursite.com/my-custom` `./my-custom-dir/my-custom.php` will be `yoursite.com/my-custom-dir/my-custom` -Nginx and Apache `.htaccess` configurations are included to remove `.php` extension from URLs in your local dev -environment. +Nginx configuration includes extensionless-php directives to remove `.php` extension from URLs in your local dev +environment. Don't put `.php` extensions in the URLs and links, just put in files. ## Enabling GitHub Pages @@ -95,24 +95,25 @@ AAAA 2606:50c0:8000::153 you can also add `your-github-username.github.io` as a CNAME record to your DNS records instead and still have a custom domain, instead of the IP addresses above. -## Local Development Environment in a PHP server (Nginx or Apache) -You can use either apache with php or nginx with php-fpm locally to run your site. When run locally, there is no -build process, it's just PHP working server side. I won't dive into setting those up here. +## Local Development Environment -Do `composer update` locally to install dependencies before running locally. Build process does this automatically -but you need to do manually for local development. +You can spin up the docker container and let it serve the PHP site locally, without a build process. You need to +have `docker` installed on your machine. -### For Local Nginx -use the config file in dir `./system/workflow-image/nginx.conf` and follow the comments. +`cd` into the project directory -### For Local Apache -For local Apache, the .htaccess should be enough but also need to configure your virtual host in apache -configuration for the `local_hostname` domain name set in `config.json`. +run: +``` +make dev-server +``` -Ensure local hostname matches the `local_hostname` in `config.json` file. Add it to hosts file at `/etc/hosts` if -necessary with IP `127.0.0.1` +Alternatively, you don't have `make` installed, you can run below, and adjust the port `8001` to your liking: +``` +docker run --rm -it --entrypoint /workspace/system/bin/dev-server-entrypoint.sh -p 8001:80 \ + -v $(shell pwd):/workspace ghcr.io/atas/ssg-builder::latest +``` -Locally, http works fine, https is used in build process with self-signed cert to generate URLs correctly. +Your local php site will be running at `http://localhost:8001` with instant updates on page refresh, as PHP does. ## Architectural Considerations diff --git a/config.json b/config.json index 622db67..48d6a96 100644 --- a/config.json +++ b/config.json @@ -2,8 +2,6 @@ "site_top_h1": "ata's ssg", "site_top_about_line1": "Simple PHP-based Static Site generator", "site_top_about_line2": "Supports Markdown and deployed to GitHub Pages by GitHub Actions", - "hostname": "ssg-test.atasasmaz.com", - "local_hostname": "ssg-local.atasasmaz.com", "email": "local-address@your-domain.com", "full_title": "Ata's SSG - a Simple PHP-based SSG for GitHub Pages", "appended_title": " - Ata's SSG", diff --git a/layout/footer.php b/layout/footer.php index 3fd8901..e15af51 100644 --- a/layout/footer.php +++ b/layout/footer.php @@ -2,7 +2,7 @@