Skip to content
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
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
19 changes: 17 additions & 2 deletions scripts/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
10 changes: 10 additions & 0 deletions scripts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,23 @@ 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 .

# commit with custom message:
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 &
Expand Down