circleciで No application encryption key has been specified.が出てしまう
解決したいこと
circleciでテストを成功させたいです。
記事を投稿する機能の実装中にエラーが発生しました。
ローカルでのテストは成功しますがcircleciだと失敗します。
.envはsrcディレクトリにあります。
解決方法を教えて下さい。
発生している問題・エラー
• Tests\Feature\CookieAuthenticationControllerTest > login success
Illuminate\Encryption\MissingAppKeyException
No application encryption key has been specified.
at vendor/laravel/framework/src/Illuminate/Encryption/EncryptionServiceProvider.php:101
97▕ protected function key(array $config)
98▕ {
99▕ return tap($config['key'], function ($key) {
100▕ if (empty($key)) {
➜ 101▕ throw new MissingAppKeyException;
102▕ }
103▕ });
104▕ }
105▕ }
+18 vendor frames
19 tests/Feature/CookieAuthenticationControllerTest.php:21
Illuminate\Foundation\Testing\TestCase::postJson("login", ["test@example.com", "password"])
該当のコード
config.yml
version: 2.1
jobs:
build:
docker:
- image: circleci/php:8-node-browsers
- image: circleci/postgres:11.6-alpine
environment:
POSTGRES_DB: larasns
POSTGRES_USER: default
POSTGRES_PASSWORD: secret
environment:
APP_ENV: testing
DB_CONNECTION: pgsql
DB_HOST: localhost
DB_PORT: 5432
DB_DATABASE: larasns
DB_USERNAME: default
DB_PASSWORD: secret
steps:
- checkout
- run: sudo composer self-update --1
- run: pwd
- restore_cache:
key: composer-v1-{{ checksum "./src/composer.lock" }}
- run:
name: composer install
command: |
cd src/
composer install -n --prefer-dist
- save_cache:
key: composer-v1-{{ checksum "./src/composer.lock" }}
paths:
- vendor
- restore_cache:
key: npm-v1-{{ checksum "./src/package-lock.json" }}
- run:
name: npm ci
command: |
if [ ! -d node_modules ]; then
cd src/
npm ci
fi
- save_cache:
key: npm-v1-{{ checksum "./src/package-lock.json" }}
paths:
- node_modules
- run:
name: npm run dev
command: |
cd src/
npm run dev
- run:
name: get ready for postgres
command: |
sudo apt-get update
sudo apt-get install libpq-dev
sudo docker-php-ext-install pdo_pgsql
dockerize -wait tcp://localhost:5432 -timeout 1m
- run:
name: php test
command: |
cd src/
php artisan test
deploy:
docker:
- image: circleci/php:8-node-browsers
steps:
- add_ssh_keys
- run:
name: deploy
command: |
ssh -o StrictHostKeyChecking=no -t webapp@${HOST_NAME} "cd book_question && \
git pull origin main && \
composer install -n --no-dev --prefer-dist && \
npm ci && \
npm run prod && \
php artisan migrate --force && \
php artisan config:cache"
workflows:
version: 2
build_deploy:
jobs:
- build
- deploy:
requires:
- build
filters:
branches:
only:
- main
自分で試したこと
.envにphp artisan key:generateでAPP_KEYを作成。
補足情報(FW/ツールのバージョンなど)
laravel/8.0
0