Page MenuHomeDevCentral

Ensure APP_KEY is defined
ClosedPublic

Authored by dereckson on Jan 22 2016, 05:09.
Tags
None
Referenced Files
F3913467: D258.diff
Thu, Dec 19, 10:14
Unknown Object (File)
Thu, Dec 12, 12:51
Unknown Object (File)
Tue, Dec 10, 04:31
Unknown Object (File)
Tue, Dec 10, 04:15
Unknown Object (File)
Mon, Dec 9, 08:15
Unknown Object (File)
Fri, Dec 6, 02:34
Unknown Object (File)
Sun, Dec 1, 16:43
Unknown Object (File)
Sun, Dec 1, 00:05
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 325
Build 370: 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.