From fdf2e5822ab9a4b9d5edbaa0bb29e8395d684a74 Mon Sep 17 00:00:00 2001 From: nanaya Date: Fri, 10 Jan 2025 17:47:32 +0900 Subject: [PATCH 1/2] Fix env file setup for dusk.local Also fixed bug of github token being echoed to console if set. Note that the APP_ENV in .env.dusk.local isn't actually used when using docker compose as it overrides the value with the one in .env. --- docker/development/prepare.sh | 41 +++++++++++++---------------------- 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/docker/development/prepare.sh b/docker/development/prepare.sh index 7f69ea08701..710db995174 100755 --- a/docker/development/prepare.sh +++ b/docker/development/prepare.sh @@ -15,18 +15,24 @@ _run() { docker compose run --rm php "$@" } -_run_dusk() { - docker compose run --rm -e APP_ENV=dusk.local php "$@" -} - -if [ ! -f .env ]; then - echo "Copying default env file" - cp .env.example .env -fi +for envfile in .env .env.testing .env.dusk.local; do + if [ ! -f "${envfile}" ]; then + echo "Copying env file '${envfile}'" + cp "${envfile}.example" "${envfile}" + fi + if [ "${envfile}" != .env.testing ] && ! grep -q '^APP_KEY=.' "${envfile}"; then + echo "Generating app key for env file '${envfile}'" + sed -i -e '/^APP_KEY=.*/d' "${envfile}" + : "${APP_KEY="base64:$(head -c 32 /dev/urandom | base64)"}" + echo "APP_KEY=${APP_KEY}" >> "${envfile}" + fi +done if [ -n "${GITHUB_TOKEN:-}" ]; then _run composer config -g github-oauth.github.com "${GITHUB_TOKEN}" - grep ^GITHUB_TOKEN= .env || echo "GITHUB_TOKEN=${GITHUB_TOKEN}" >> .env + for envfile in .env .env.dusk.local; do + grep -q '^GITHUB_TOKEN=' "${envfile}" || echo "GITHUB_TOKEN=${GITHUB_TOKEN}" >> "${envfile}" + done fi docker compose build @@ -37,23 +43,6 @@ _run composer install _run artisan dusk:chrome-driver -if ! grep -q '^APP_KEY=.' .env; then - echo "Generating app key" - _run artisan key:generate -fi - -if [ ! -f .env.testing ]; then - echo "Copying default test env file" - cp .env.testing.example .env.testing -fi - -if [ ! -f .env.dusk.local ]; then - echo "Copying default dusk env file" - cp .env.dusk.local.example .env.dusk.local - echo "Generating app key for dusk" - _run_dusk artisan key:generate -fi - if [ -d storage/oauth-public.key ]; then echo "oauth-public.key is a directory. Removing it" rmdir storage/oauth-public.key From 298f2acea9e9d80c0e9faf62ab702e09a3c68185 Mon Sep 17 00:00:00 2001 From: nanaya Date: Fri, 10 Jan 2025 19:04:52 +0900 Subject: [PATCH 2/2] Quotes optional --- docker/development/prepare.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/development/prepare.sh b/docker/development/prepare.sh index 710db995174..94ba4806019 100755 --- a/docker/development/prepare.sh +++ b/docker/development/prepare.sh @@ -23,7 +23,7 @@ for envfile in .env .env.testing .env.dusk.local; do if [ "${envfile}" != .env.testing ] && ! grep -q '^APP_KEY=.' "${envfile}"; then echo "Generating app key for env file '${envfile}'" sed -i -e '/^APP_KEY=.*/d' "${envfile}" - : "${APP_KEY="base64:$(head -c 32 /dev/urandom | base64)"}" + : ${APP_KEY="base64:$(head -c 32 /dev/urandom | base64)"} echo "APP_KEY=${APP_KEY}" >> "${envfile}" fi done