From a204a843b40670d118c09b30628ed5c767ef84e6 Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Tue, 14 Feb 2023 11:18:08 -0500 Subject: [PATCH 1/4] chore: Updated copyright date --- .docker-config/php/composer_install.sh | 9 ++------- .docker-config/php/run_queue.sh | 9 ++------- 2 files changed, 4 insertions(+), 14 deletions(-) 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 From 6c279246aef4cc39534042567554f150104aaf1b Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Tue, 14 Feb 2023 11:18:55 -0500 Subject: [PATCH 2/4] refactor: Refactor the banner to a separate `banner_message.sh` --- .docker-config/php/Dockerfile | 2 ++ .docker-config/php/banner_message.sh | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100755 .docker-config/php/banner_message.sh 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}" From 7a6fda79110230d9975f04567ad769a72c15c0dd Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Tue, 14 Feb 2023 11:19:20 -0500 Subject: [PATCH 3/4] feat: Detect when we're running in Codespaces, and swap in the dynamic URL for the `PRIMARY_SITE_URL` env var automatically --- config/general.php | 10 ++++++++++ 1 file changed, 10 insertions(+) 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.) From f03f7c7ba0b1685bb5e12cc2f5554df250b5c339 Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Tue, 14 Feb 2023 11:19:27 -0500 Subject: [PATCH 4/4] chore: Version 1.0.5 --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) 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