diff --git a/.docker-config/php/Dockerfile b/.docker-config/php/Dockerfile index 3896cfd..b897029 100755 --- a/.docker-config/php/Dockerfile +++ b/.docker-config/php/Dockerfile @@ -12,6 +12,8 @@ RUN chmod a+x run_queue.sh \ chown -R www-data:www-data /var/www/project COPY ./composer_install.sh . RUN chmod a+x composer_install.sh +COPY ./banner_message.sh . +RUN chmod a+x banner_message.sh WORKDIR /var/www/project diff --git a/.docker-config/php/banner_message.sh b/.docker-config/php/banner_message.sh new file mode 100755 index 0000000..f6dbc33 --- /dev/null +++ b/.docker-config/php/banner_message.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +# Banner Message shell script +# +# Display a banner message to let the user know the environment is ready for use +# +# @author nystudio107 +# @copyright Copyright (c) 2023 nystudio107 +# @link https://nystudio107.com/ +# @license MIT + +# Rewrite the PRIMARY_SITE_URL env var if we're running in Codespaces +if [[ ! ${CODESPACES:-"unset"} == "unset" ]]; then + export PRIMARY_SITE_URL="https://${CODESPACE_NAME}-${DEV_SERVER_PORT}.preview.app.github.dev/" +fi +# Banner message +sleep 1 +echo "### Your Craft site is ready!" +echo "Frontend URL: ${PRIMARY_SITE_URL}" +echo "CP URL: ${PRIMARY_SITE_URL}admin" +echo "CP User: ${CRAFT_CP_USER}" +echo "CP Password: ${CRAFT_CP_PASSWORD}" diff --git a/.docker-config/php/composer_install.sh b/.docker-config/php/composer_install.sh index c045073..d646d2f 100755 --- a/.docker-config/php/composer_install.sh +++ b/.docker-config/php/composer_install.sh @@ -6,7 +6,7 @@ # the `vendor/` directory is not present` # # @author nystudio107 -# @copyright Copyright (c) 2022 nystudio107 +# @copyright Copyright (c) 2023 nystudio107 # @link https://nystudio107.com/ # @license MIT @@ -28,9 +28,4 @@ if [ ! -f "composer.lock" ] || [ ! -d "vendor" ] || [ ! -f "vendor/autoload.php" su-exec www-data php craft up fi # Banner message -sleep 1 -echo "### Your Craft site is ready!" -echo "Frontend URL: ${PRIMARY_SITE_URL}" -echo "CP URL: ${PRIMARY_SITE_URL}admin" -echo "CP User: ${CRAFT_CP_USER}" -echo "CP Password: ${CRAFT_CP_PASSWORD}" +source '/var/www/banner_message.sh' diff --git a/.docker-config/php/run_queue.sh b/.docker-config/php/run_queue.sh index 66a2c86..755a78a 100755 --- a/.docker-config/php/run_queue.sh +++ b/.docker-config/php/run_queue.sh @@ -8,7 +8,7 @@ # then runs the queue listener that listens for and runs pending queue jobs # # @author nystudio107 -# @copyright Copyright (c) 2022 nystudio107 +# @copyright Copyright (c) 2023 nystudio107 # @link https://nystudio107.com/ # @license MIT @@ -31,11 +31,6 @@ chown -R www-data:www-data /var/www/project/web/cpresources # Run any pending migrations/project config changes su-exec www-data php craft up # Banner message -sleep 1 -echo "### Your Craft site is ready!" -echo "Frontend URL: ${PRIMARY_SITE_URL}" -echo "CP URL: ${PRIMARY_SITE_URL}admin" -echo "CP User: ${CRAFT_CP_USER}" -echo "CP Password: ${CRAFT_CP_PASSWORD}" +source '/var/www/banner_message.sh' # Run a queue listener su-exec www-data php craft queue/listen 10 diff --git a/CHANGELOG.md b/CHANGELOG.md index b139def..9449e4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # nystudio107/spin-up-craft Change Log +## 1.0.5 - 2023.02.14 +### Added +* Detect when we're running in Codespaces, and swap in the dynamic URL for the `PRIMARY_SITE_URL` env var automatically + +### Changed +* Refactor the banner to a separate `banner_message.sh` + ## 1.0.4 - 2023.02.08 ### Added * Add PHP 8.1 as the default image diff --git a/config/general.php b/config/general.php index 965ca65..ab655db 100644 --- a/config/general.php +++ b/config/general.php @@ -11,6 +11,16 @@ use craft\config\GeneralConfig; use craft\helpers\App; +// Rewrite the PRIMARY_SITE_URL env var if we're running in Codespaces +if (App::env('CODESPACES')) { + // putenv() only affects the OS's environment, so set it directly + $_ENV['PRIMARY_SITE_URL'] = $_SERVER['PRIMARY_SITE_URL'] = sprintf( + "https://%s-%s.preview.app.github.dev/", + App::env('CODESPACE_NAME'), + App::env('DEV_SERVER_PORT') + ); +} + return GeneralConfig::create() ->runQueueAutomatically(false) // Set the default week start day for date pickers (0 = Sunday, 1 = Monday, etc.)