From 21c3af0221b5cd485763409845df37ffb09a73c1 Mon Sep 17 00:00:00 2001 From: dtfiedler Date: Wed, 8 May 2024 12:12:26 -0400 Subject: [PATCH] feat(docker): add env var to docker file to wait This will tell the container to not start the server until after a certain # of seconds. This is useful in ECS where litestream needs some time to load the database before the service starts sending it --- Dockerfile | 1 + docker-compose.yaml | 1 + entrypoint.sh | 6 ++++++ 3 files changed, 8 insertions(+) diff --git a/Dockerfile b/Dockerfile index b1f7bab..c2a24c9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,6 +19,7 @@ WORKDIR /usr/src/app COPY --from=busybox:1.35.0-uclibc /bin/sh /bin/sh COPY --from=busybox:1.35.0-uclibc /bin/chown /bin/chown COPY --from=busybox:1.35.0-uclibc /bin/chmod /bin/chmod +COPY --from=busybox:1.35.0-uclibc /bin/sleep /bin/sleep # Copy build files COPY --from=builder /usr/src/app . diff --git a/docker-compose.yaml b/docker-compose.yaml index 0b24c46..be9fd57 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -19,6 +19,7 @@ services: GATEWAY_PROTOCOL: ${GATEWAY_PROTOCOL:-http} PREFETCH_CONTRACTS: ${PREFETCH_CONTRACTS:-false} BLOCKLISTED_CONTRACT_IDS: ${BLOCKLISTED_CONTRACT_IDS:-fbU8Y4NMKKzP4rmAYeYj6tDrVDo9XNbdyq5IZPA31WQ} + WAIT_TIME_SECONDS: ${WAIT_TIME_SECONDS:-} ports: - '3000:3000' diff --git a/entrypoint.sh b/entrypoint.sh index c036c08..f5ed50a 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -5,5 +5,11 @@ if [ -d "/usr/src/app/cache" ]; then chmod -R 755 /usr/src/app/cache fi +if [[ -n "$WAIT_TIME_SECONDS" ]]; then + # Sleep for the number of seconds specified in WAIT_TIME_SECONDS + echo "Waiting for $WAIT_TIME_SECONDS seconds before starting the service..." + sleep $WAIT_TIME_SECONDS +fi + # run the app exec /nodejs/bin/node /usr/src/app/dist/app.js