From 4aa7e8f2484e17e72238a862418b30613f0cbb82 Mon Sep 17 00:00:00 2001 From: Julien Acroute Date: Wed, 4 Apr 2018 17:50:27 +0200 Subject: [PATCH 1/3] Make watch part optional (only update volume) --- README.md | 5 ++++- scripts/entrypoint.sh | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0c41ae9..6434d23 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 diff --git a/scripts/entrypoint.sh b/scripts/entrypoint.sh index d2c49b2..6ae7453 100644 --- a/scripts/entrypoint.sh +++ b/scripts/entrypoint.sh @@ -64,5 +64,7 @@ if [ -n "$REMOTE_NAME" ] && [ -n "$REMOTE_URL" ]; then git clean -xdf fi -# execute CMD -exec "$@" +# Launch inotify to watch $WATCH_FILE if configured +if [ -n "$WATCH_FILE" ]; then + exec "$@" +fi From d6e8a232031fb905f6b37f6344080a12ebe2e1e1 Mon Sep 17 00:00:00 2001 From: Julien Acroute Date: Thu, 19 Apr 2018 09:56:10 +0200 Subject: [PATCH 2/3] Add a file in volume when volume is initialized --- README.md | 3 +++ scripts/entrypoint.sh | 13 +++++++++++++ scripts/run.sh | 10 ++++++++++ 3 files changed, 26 insertions(+) diff --git a/README.md b/README.md index 6434d23..56b1c0b 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,9 @@ 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. 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 6ae7453..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,6 +70,13 @@ if [ -n "$REMOTE_NAME" ] && [ -n "$REMOTE_URL" ]; then git clean -xdf fi +# 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 "$@" 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 & From 614d0f93f76a3e4bf64bcf88e692d6f957a582be Mon Sep 17 00:00:00 2001 From: Julien Acroute Date: Mon, 30 Apr 2018 12:15:40 +0200 Subject: [PATCH 3/3] Document INITIALIZED_FILE_FLAG option --- README.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 56b1c0b..7570974 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,18 @@ Optional environment: * `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. + 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: