Page MenuHomeDevCentral

Ensure APP_KEY is defined
ClosedPublic

Authored by dereckson on Jan 22 2016, 05:09.
Tags
None
Referenced Files
F3629379: D258.id601.diff
Sun, Oct 6, 00:22
F3629128: D258.id.diff
Sat, Oct 5, 22:28
F3629110: D258.id.diff
Sat, Oct 5, 22:19
Unknown Object (File)
Thu, Oct 3, 01:24
Unknown Object (File)
Wed, Oct 2, 15:42
Unknown Object (File)
Wed, Oct 2, 15:19
Unknown Object (File)
Wed, Oct 2, 04:31
Unknown Object (File)
Wed, Oct 2, 04:31
Subscribers
None

Details

Summary

At container launch, a custom application key can be defined with
docker run ... -e APP_KEY=... ... nasqueron/notifications.

If no key is submitted, we run php artisan key:generate after
an an empty .env is created if missing.

If NO_INSTALL is defined, we don't check anything and the application
will fail loudly if no configuration is provided.

Fixes T690.

Test Plan

Build the image, run it, ensure web application is live.

Create an .env when APP_KEY isn't in the environment.

$ docker run -it nasqueron/notifications
/var/wwwroot/default /var/wwwroot/default
Configuration cache cleared!
Configuration cached successfully!
/var/wwwroot/default  
$ docker exec -it prickly_brattain cat .env

APP_KEY=atk8fwTbU4VWYYn9elwkC2DVMVfH712I

OK.


Don't create an .env when APP_KEY is in the environment.

$ docker run -it -e APP_KEY=wazza nasqueron/notifications
$ docker exec -it evil_tesla ls .env
ls: cannot access .env: No such file or directory

OK.

Diff Detail

Repository
rDNOTIF Notifications center Docker image
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

dereckson retitled this revision from to Ensure APP_KEY is defined.
dereckson updated this object.
dereckson edited the test plan for this revision. (Show Details)
dereckson added a reviewer: Sandlayth.

When .env doesn't exist, it executes what it should (echo "APP_KEY=SomeRandomString" > .env then php artisan key:generate but the command doesn't update .env.

I'm trying something like:

function generate_key {
	KEY=`php artisan key:generate --show`
	echo "APP_KEY=$KEY" >> .env
}

# [...]

	if [ -z "$APP_KEY"] && [! -f .env ]; then
		generate_key
	fi

But I would like to perform a grep APP_KEY .env too.

Sandlayth edited edge metadata.
This revision is now accepted and ready to land.Jan 22 2016, 20:16
dereckson edited edge metadata.
This revision was automatically updated to reflect the committed changes.