docker-compose healthcheck
無限に失敗してる
local では通ってたのが突然 ci と同じ形で通らないようになった
> docker inspect --format "{{json .State.Health }}" ateaparty-reminder_graphql-engine_1 | jq
{
"Status": "starting",
"FailingStreak": 0,
"Log": [
{
"Start": "2022-02-23T08:16:59.4647861Z",
"End": "2022-02-23T08:16:59.5786331Z",
"ExitCode": 7,
"Output": "curl: (7) Failed to connect to localhost port 8080: Connection refused\n"
}
]
}
失敗してるときはこんなログ.
まだコンテナが起動してないっぽい
> docker-compose run --rm app /bin/bash -c "sudo npm i && npm run all"
WARNING: The DISCORD_WEBHOOK_URL variable is not set. Defaulting to a blank string.
WARNING: The HEROKU_API_KEY variable is not set. Defaulting to a blank string.
WARNING: The HEROKU_EMAIL variable is not set. Defaulting to a blank string.
WARNING: The TF_VAR_heroku_app_name variable is not set. Defaulting to a blank string.
Creating network "ateaparty-reminder_default" with the default driver
Creating volume "ateaparty-reminder_node_modules" with default driver
Creating volume "ateaparty-reminder_web_nodemodules" with default driver
Creating volume "ateaparty-reminder_db_data" with default driver
Creating ateaparty-reminder_postgres_1 ... done
Creating ateaparty-reminder_graphql-engine_1 ... done
ERROR: for app Container "c2ab786258c4" is unhealthy.
ERROR: Encountered errors while bringing up the project.
unhealthy で落ちてる
healthcheck:
test: curl -Ssf http://localhost:8080/healthz
interval: 20s
timeout: 80s
retries: 10
start_period: 120s
少なくとも 120s は落ちずに残ってるはずだとは思っているkedo
start_period を待たずにすぐに落ちることがあって、そのときに unhealthy になる
start_period 待ってくれる場合は、正常に動作する。
start period provides initialization time for containers that need time to bootstrap. Probe failure during that period will not be counted towards the maximum number of retries. However, if a health check succeeds during the start period, the container is considered started and all consecutive failures will be counted towards the maximum number of retries.
理解は間違ってないはず
しっぱいしてるとき
Failing streak は増えてないから、start_period は動作してる?
start_period を 0 にして試してみる
失敗して欲しい時に成功する定期
streak がちゃんと溜まった。
retry は 10 に設定してるが、2回でunhealthy になった
It takes retries consecutive failures of the health check for the container to be considered unhealthy.
これ?連続で失敗した場合は unhealthy になるとは書いてる
start_period がない場合にこの制約でこけるのはわかるが、あってもこけるのは謎
condition: service_healthy
の方が悪さしてるんかな
depends_on: condition
の 記述が ver 3 の doc からは消えてるっぽい
shellscript で実現するの推奨なんかな
これを entrypoint に書いてってみるかな
ここの方法を試してみる
local では通った
glob error [Error: EACCES: permission denied, scandir '/root/.npm/_logs'] {
errno: -13,
code: 'EACCES',
syscall: 'scandir',
path: '/root/.npm/_logs'
}
npm WARN logfile Error: EACCES: permission denied, scandir '/root/.npm/_logs'
npm WARN logfile error cleaning log files [Error: EACCES: permission denied, scandir '/root/.npm/_logs'] {
npm WARN logfile errno: -13,
npm WARN logfile code: 'EACCES',
npm WARN logfile syscall: 'scandir',
npm WARN logfile path: '/root/.npm/_logs'
npm WARN logfile }
> ateaparty-reminder@0.0.1 test
> jest --passWithNoTests
PASS src/repository/evemtRepository.spec.ts
PASS src/infrastructure/eventDataSource.spec.ts
PASS src/message.spec.ts
Test Suites: 3 passed, 3 total
Tests: 5 passed, 5 total
Snapshots: 0 total
Time: 3.343 s
Ran all test suites.
glob error [Error: EACCES: permission denied, scandir '/root/.npm/_logs'] {
errno: -13,
code: 'EACCES',
syscall: 'scandir',
path: '/root/.npm/_logs'
}
npm WARN logfile Error: EACCES: permission denied, scandir '/root/.npm/_logs'
npm WARN logfile error cleaning log files [Error: EACCES: permission denied, scandir '/root/.npm/_logs'] {
npm WARN logfile errno: -13,
npm WARN logfile code: 'EACCES',
npm WARN logfile syscall: 'scandir',
npm WARN logfile path: '/root/.npm/_logs'
npm WARN logfile }
> ateaparty-reminder@0.0.1 build
> tsc
glob error [Error: EACCES: permission denied, scandir '/root/.npm/_logs'] {
errno: -13,
code: 'EACCES',
syscall: 'scandir',
path: '/root/.npm/_logs'
}
npm WARN logfile Error: EACCES: permission denied, scandir '/root/.npm/_logs'
npm WARN logfile error cleaning log files [Error: EACCES: permission denied, scandir '/root/.npm/_logs'] {
npm WARN logfile errno: -13,
npm WARN logfile code: 'EACCES',
npm WARN logfile syscall: 'scandir',
npm WARN logfile path: '/root/.npm/_logs'
npm WARN logfile }
> ateaparty-reminder@0.0.1 pack
> ncc build -m
ncc: Version 0.33.1
ncc: Compiling file index.js into CJS
546kB dist/index.js
546kB [3488ms] - ncc 0.33.1
権限周りでエラーは起きてるけど、とりあえず通ったからよし!