Skip to content

Commit

Permalink
Dockerfile: ensure json-server terminates on SIGTERM
Browse files Browse the repository at this point in the history
Ensure that the json-server process terminates upon reception of the
SIGTERM signal, so that the pod doesn't remain in terminating status
for 30 seconds (the default grace period) when deleted. This fix
involves two changes:

* Run exec at the end of the run.sh script, instead of shelling out,
  so that the callee gets PID 1;
* Wrap the json-server executable with the "tini" lightweight init
  system, as apparently node doesn't terminate upon SIGTERM when
  running as PID 1.

Signed-off-by: Marco Iorio <[email protected]>
  • Loading branch information
giorio94 authored and dylandreimerink committed Jan 9, 2024
1 parent 983d231 commit 93b6602
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ FROM docker.io/library/node:21.3.0-slim@sha256:8d66ff8ac7f7053d707de87bc86ebfe8b
RUN npm install -g json-server \
&& apt-get update \
&& apt-get upgrade -y \
&& apt-get install -y curl iproute2 \
&& apt-get install -y tini curl iproute2 \
&& apt-get autoremove -y \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
Expand Down
4 changes: 2 additions & 2 deletions run.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

SERVER_ARGS="--host '' $@"
SERVER_ARGS="$@"

if [ ! -z "$PORT" ]; then
SERVER_ARGS="$SERVER_ARGS --port $PORT"
Expand All @@ -20,4 +20,4 @@ else
SERVER_ARGS="$SERVER_ARGS --middlewares /middleware.js"
fi

sh -c "json-server $SERVER_ARGS"
exec /usr/bin/tini -- /usr/local/bin/json-server --host "" $SERVER_ARGS

0 comments on commit 93b6602

Please sign in to comment.