Page MenuHomeDevCentral

Ensure APP_KEY is defined
ClosedPublic

Authored by dereckson on Jan 22 2016, 05:09.
Tags
None
Referenced Files
F3748984: D258.diff
Sat, Nov 16, 11:49
F3747246: D258.id603.diff
Sat, Nov 16, 01:07
Unknown Object (File)
Fri, Nov 15, 22:20
Unknown Object (File)
Fri, Nov 15, 21:22
Unknown Object (File)
Fri, Nov 15, 14:48
Unknown Object (File)
Fri, Nov 15, 13:35
Unknown Object (File)
Fri, Nov 15, 04:20
Unknown Object (File)
Fri, Nov 15, 04:19
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
No Lint Coverage
Unit
No Test Coverage
Branch
security/env
Build Status
Buildable 326
Build 371: arc lint + arc unit

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.