Skip to content

Commit e56be33

Browse files
committed
Fix healthcheck
1 parent 83e5fea commit e56be33

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

.devcontainer/init-container.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ setup_rootless_docker
5252

5353
philomena init
5454

55-
step npm ci install --ignore-scripts
55+
step npm ci --ignore-scripts
5656

5757
# Create an empty file which indicates to the healthcheck that the container
5858
# finished initializing. This precents race conditions with `docker exec` commands

docker/app/Dockerfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,11 @@ ENTRYPOINT ["./.devcontainer/init-container.sh"]
130130
# Check for the presence of a special marker file that indicates that the
131131
# container has been initialized. Use a big `--interval` to "disable"
132132
# healthchecks after initialization completes.
133-
HEALTHCHECK --start-period=10s --start-interval=0.5s --interval=9999h \
134-
CMD [ "test", "-f", "$HOME/.initialized" ]
133+
#
134+
# Also, don't be fooled - docker dosn't interpolate env vars in the CMD exec
135+
# form, so we explicitly use `bash -c` to expand the `$HOME` variable.
136+
HEALTHCHECK --start-period=10s --start-interval=0.5s --retries=1 --interval=9999h \
137+
CMD [ "bash", "-c", "test -f $HOME/.initialized" ]
135138

136139
# Make sure the process doesn't exit to keep the container alive
137140
CMD ["sleep", "infinity"]

scripts/lib.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,19 +118,23 @@ function devcontainer_up {
118118
local status=$?
119119
set -e
120120

121+
# Ideally compose should stream the logs from the container while it's
122+
# starting, unfortunately, this issue has been open for years:
123+
# https://github.com/docker/compose/issues/9122
121124
if [[ "$status" = "0" ]]; then
122-
return 0
125+
info "Dumping the devcontainer logs..."
126+
else
127+
error "Failed to create the devcontainer. Dumping its logs below..."
123128
fi
124129

125-
error "Failed to create the devcontainer. Dumping its logs below..."
126130
step docker compose --file "$file" logs --no-log-prefix
127131

128132
return "$status"
129133
}
130134

131135
function devcontainer_forward {
132136
# Make sure the devcontainer is up and running.
133-
if ! docker ps --all --format '{{.Names}}' | grep -wq philomena-devcontainer; then
137+
if ! docker ps --filter "health=healthy" --format '{{.Names}}' | grep -wq philomena-devcontainer; then
134138
devcontainer_up
135139
fi
136140

0 commit comments

Comments
 (0)