diff --git a/README.md b/README.md index 0c41ae9..7570974 100644 --- a/README.md +++ b/README.md @@ -32,8 +32,11 @@ sync: volumes: - geoserver_datadir:/var/local/data:rw ``` +If `WATCH_FILE` environment is not set, volume will only be bootstraped from +remote git repository. Note that entrypoint will stop just after volume +bootstrap so you should configure container restart policy. -Required environment: +Required environment for watching: * `WATCH_FILE`: file to watch (path relative to volume root) * `GIT_COMMIT_MESSAGE`: string or expression evaluated in the volume to provide a commit message * `GIT_USERNAME`: git username for commit @@ -46,6 +49,20 @@ To push to a repository, these additional variables are required: Optional environment: * `REMOTE_BRANCH`: Remote branch to use. Defaults to master. * `FORCE_CLONE`: Delete volume content before cloning remote repository + * `INITIALIZED_FILE_FLAG`: If set, a file will be created after initialisation + called INITIALIZED_FILE_FLAG. During initialisation, this file will be + deleted. This should be a relative path to volume root. This file can be used + to avoid other containers from starting during initialisation of the volume. + +Example of script that wait for a `initialised` file to be created: +```bash +until ls /mnt/volume/initialised; do + echo waiting for volume initialisation; + sleep 1; +done; +``` +This kind of script can be launched before main entrypoint of other +containers. To use SSH authentication to access remote repository, one of following variables must be set: diff --git a/scripts/entrypoint.sh b/scripts/entrypoint.sh index d2c49b2..6b2064a 100644 --- a/scripts/entrypoint.sh +++ b/scripts/entrypoint.sh @@ -1,5 +1,11 @@ #!/bin/bash +# Remove flag file during initialisation +if [ -n $INITIALIZED_FILE_FLAG ] && [ -f $INITIALIZED_FILE_FLAG ]; then + echo "rm -f $INITIALIZED_FILE_FLAG..." + rm -f $INITIALIZED_FILE_FLAG +fi + # set name and email to use for commits made by this container git config --global user.email "$GIT_EMAIL" git config --global user.name "$GIT_USERNAME" @@ -64,5 +70,14 @@ if [ -n "$REMOTE_NAME" ] && [ -n "$REMOTE_URL" ]; then git clean -xdf fi -# execute CMD -exec "$@" +# Add a file to mark volume as initialized +if [ -n $INITIALIZED_FILE_FLAG ]; then + pwd + echo "touch $INITIALIZED_FILE_FLAG" + touch $INITIALIZED_FILE_FLAG +fi + +# Launch inotify to watch $WATCH_FILE if configured +if [ -n "$WATCH_FILE" ]; then + exec "$@" +fi diff --git a/scripts/run.sh b/scripts/run.sh index a664ac6..1d71b04 100644 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -21,6 +21,11 @@ do # set up watches: inotifywait -e modify $WATCH_FILE + # Temporary remove flag file to avoid commit of this file + if [ -n $INITIALIZED_FILE_FLAG ] && [ -f $INITIALIZED_FILE_FLAG ]; then + rm -f $INITIALIZED_FILE_FLAG + fi + # commit all files from current dir: git add --all . @@ -28,6 +33,11 @@ do msg=`eval $GIT_COMMIT_MESSAGE` git commit -m "${msg:-"no commit message"}" + # Restore flag file + if [ -n $INITIALIZED_FILE_FLAG ]; then + touch $INITIALIZED_FILE_FLAG + fi + if [ $REMOTE_NAME ] && [ $REMOTE_URL ]; then # push to repository in the background git push $REMOTE_NAME $REMOTE_BRANCH &