mardi 23 juillet 2019

Problem with generating and using application key within a CI Job

Im trying to get a laravel pipeline with unit tests to work. In my CI job im copying my testing environment file with the database credentials and generating a new application key with php artisan key:generate. The new key is setted without any problem but the phpunit test throws this exception: RuntimeException: No application encryption key has been specified..

With a preconfigured key its working fine. Even when im generating a new one in the job.

Any ideas on this behavior? Have to say im relativly new to CI.

Im docker as executor for my gitlab runner.

I first thought its some file permission stuff but that shouldn be the case when its working with a preconfigured key. So im pretty much clueless. Hope somebody can help me. Details below.

Here is the output of the pipeline:

Downloading artifacts for composer (262)...
Downloading artifacts from coordinator... ok        id=262 responseStatus=200 OK token=-A2VMuUf
$ cp .env.testing .env
$ php artisan key:generate
Application key set successfully.
./vendor/bin/phpunit --version
PHPUnit 7.5.13 by Sebastian Bergmann and contributors.

$ ./vendor/bin/phpunit -v -c ./phpunit.xml
PHPUnit 7.5.13 by Sebastian Bergmann and contributors.

Runtime:       PHP 7.2.19 with Xdebug 2.7.2
Configuration: /builds/MIRACUM/DIP/phpunit.xml

.E                                                                  2 / 2 (100%)

Time: 234 ms, Memory: 20.00 MB

There was 1 error:

1) Tests\Feature\ExampleTest::testBasicTest
RuntimeException: No application encryption key has been specified.

/builds/MIRACUM/DIP/vendor/laravel/framework/src/Illuminate/Encryption/EncryptionServiceProvider.php:44
/builds/MIRACUM/DIP/vendor/laravel/framework/src/Illuminate/Support/helpers.php:1124
/builds/MIRACUM/DIP/vendor/laravel/framework/src/Illuminate/Encryption/EncryptionServiceProvider.php:48
/builds/MIRACUM/DIP/vendor/laravel/framework/src/Illuminate/Encryption/EncryptionServiceProvider.php:24
/builds/MIRACUM/DIP/vendor/laravel/framework/src/Illuminate/Container/Container.php:787
/builds/MIRACUM/DIP/vendor/laravel/framework/src/Illuminate/Container/Container.php:667
/builds/MIRACUM/DIP/vendor/laravel/framework/src/Illuminate/Container/Container.php:615
/builds/MIRACUM/DIP/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:767
/builds/MIRACUM/DIP/vendor/laravel/framework/src/Illuminate/Container/Container.php:925
/builds/MIRACUM/DIP/vendor/laravel/framework/src/Illuminate/Container/Container.php:853
/builds/MIRACUM/DIP/vendor/laravel/framework/src/Illuminate/Container/Container.php:818
/builds/MIRACUM/DIP/vendor/laravel/framework/src/Illuminate/Container/Container.php:667
/builds/MIRACUM/DIP/vendor/laravel/framework/src/Illuminate/Container/Container.php:615
/builds/MIRACUM/DIP/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:767
/builds/MIRACUM/DIP/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:215
/builds/MIRACUM/DIP/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:189
/builds/MIRACUM/DIP/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php:354
/builds/MIRACUM/DIP/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php:170
/builds/MIRACUM/DIP/tests/Feature/ExampleTest.php:16

A list of the files in the working directory:

drwxrwxrwx 14 root root   4096 Jul 23 11:47 .
drwxrwxrwx  4 root root   4096 Jun  6 09:20 ..
-rw-rw-rw-  1 root root    213 Jul 23 07:41 .editorconfig
-rw-r--r--  1 php  php     792 Jul 23 11:47 .env
-rw-rw-rw-  1 root root    739 Jul 23 07:41 .env.example
-rw-rw-rw-  1 root root    741 Jul 23 11:43 .env.testing
drwxrwxrwx  6 root root   4096 Jul 23 11:47 .git
-rw-rw-rw-  1 root root    111 Jun  6 09:20 .gitattributes
-rw-rw-rw-  1 root root    165 Jul 23 07:41 .gitignore
-rw-rw-rw-  1 root root   2121 Jul 23 11:46 .gitlab-ci.yml
-rw-rw-rw-  1 root root   1255 Jul 23 07:41 .php_cs
-rw-rw-rw-  1 root root     15 Jul 23 07:41 .prettierignore
-rw-rw-rw-  1 root root    120 Jul 23 07:41 .prettierrc
-rw-rw-rw-  1 root root    174 Jul 23 07:41 .styleci.yml
-rw-rw-rw-  1 root root    971 Jun 18 07:56 CONTRIBUTING.md
drwxrwxrwx  6 root root   4096 Jul 23 07:41 app
-rw-rw-rw-  1 root root   1686 Jun  6 09:20 artisan
drwxrwxrwx  3 root root   4096 Jul 23 07:41 bootstrap
-rw-rw-rw-  1 root root   1736 Jul 23 07:41 composer.json
-rw-rw-rw-  1 root root 186367 Jul 23 07:41 composer.lock
drwxrwxrwx  2 root root   4096 Jul 23 07:41 config
drwxrwxrwx  5 root root   4096 Jul 23 07:41 database
-rw-rw-rw-  1 root root 426220 Jul 23 07:41 package-lock.json
-rw-rw-rw-  1 root root   1304 Jul 23 07:41 package.json
-rw-rw-rw-  1 root root   1156 Jul 23 07:41 phpunit.xml
drwxrwxrwx  4 root root   4096 Jul 23 11:01 public
drwxrwxrwx  6 root root   4096 Jul 23 07:41 resources
drwxrwxrwx  2 root root   4096 Jul 23 07:41 routes
-rw-rw-rw-  1 root root    572 Jul 23 07:41 server.php
drwxrwxrwx  5 root root   4096 Jun  6 09:20 storage
drwxrwxrwx  4 root root   4096 Jul 23 07:41 tests
drwxr-xr-x 42 php  php    4096 Jul 23 11:46 vendor
-rw-rw-rw-  1 root root    538 Jul 23 07:41 webpack.mix.js
-rw-rw-rw-  1 root root 202971 Jul 23 07:41 yarn.lock

The content of the existing .env-File:

APP_NAME=####
APP_ENV=testing
APP_KEY=base64:W99w+5JYz8SVGf5sx17gmPR6uoNCtWiEVc+9qu8iGEg=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=pgsql
DB_HOST=postgres
DB_PORT=5432
DB_DATABASE=####
DB_USERNAME=####
DB_PASSWORD=####

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
SESSION_LIFETIME=120
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire