Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wait-for-it functionality to facilitate network-based waits #102

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ ENV APP_SOURCE_DIR /opt/meteor/src
ENV APP_BUNDLE_DIR /opt/meteor/dist
ENV BUILD_SCRIPTS_DIR /opt/build_scripts

# wait-for-it
ENV WAIT_FOR_SECONDS=15

# Add entrypoint and build scripts
COPY scripts $BUILD_SCRIPTS_DIR
RUN chmod -R 750 $BUILD_SCRIPTS_DIR
Expand Down
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ docker run -d \
yourname/app
```

#### Delay startup
#### Delay Startup Based on Time

If you need to force a delay in the startup of the Node process (for example, to wait for a database to be ready), you can set the `STARTUP_DELAY` environment variable to any number of seconds. For example, to delay starting the app by 10 seconds, you would do this:

Expand All @@ -53,6 +53,24 @@ docker run -d \
yourname/app
```

#### Delay Startup Based on Network Connection
If you need to force a delay in startup of the node process while waiting for
the database (or some other TCP service) to be ready after
```WAIT_FOR_SECONDS``` seconds (the default if unspecified is 15 seconds), use
```WAIT_FOR```. To make the container refuse to start without being able to
contact the service, set the variable ```WAIT_FOR_REQUIRED``` to a value.

```sh
docker run -d \
-e ROOT_URL=http://example.com \
-e MONGO_URL=mongodb://url \
-e WAIT_FOR_SECONDS=13 \
-e WAIT_FOR_REQUIRED=1 \
-e WAIT_FOR=host:port \
-p 80:3000 \
yourname/app
```

### Build Options

Meteor Launchpad supports setting custom build options in one of two ways. You can either create a launchpad.conf config file in the root of your app or you can use [Docker build args](https://docs.docker.com/engine/reference/builder/#arg). The currently supported options are to install PhantomJS, GraphicsMagick, MongoDB, or any list of `apt-get` dependencies (Meteor Launchpad is built on `debian:jesse`).
Expand Down
10 changes: 10 additions & 0 deletions scripts/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ if [[ $STARTUP_DELAY ]]; then
sleep $STARTUP_DELAY
fi

# Wait for network service
if [[ ! -z $WAIT_FOR ]]; then
wait_for_args=" --timeout=$WAIT_FOR_SECONDS $WAIT_FOR -- echo \"done waiting for $WAIT_FOR\""
if [[ ! -z $WAIT_FOR_REQUIRED ]]; then
wait-for-it.sh --strict $wait_for_args
else
wait-for-it.sh $wait_for_args
fi
fi

if [ "${1:0:1}" = '-' ]; then
set -- node "$@"
fi
Expand Down
4 changes: 3 additions & 1 deletion scripts/install-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')"

wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch"
wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch.asc"
wget -O /usr/local/bin/wait-for-it.sh https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh

export GNUPGHOME="$(mktemp -d)"

Expand All @@ -38,8 +39,9 @@ gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu

rm -r "$GNUPGHOME" /usr/local/bin/gosu.asc

chmod +x /usr/local/bin/gosu
chmod +x /usr/local/bin/gosu /usr/local/bin/wait-for-it.sh

gosu nobody true

apt-get purge -y --auto-remove wget