Working version of cloner, basic setup of git and so on
This commit is contained in:
parent
0712ca5d16
commit
aa601dc1fa
|
@ -5,7 +5,9 @@ VOLUME /data
|
||||||
|
|
||||||
RUN apk add --no-cache git bash
|
RUN apk add --no-cache git bash
|
||||||
|
|
||||||
|
ADD checker/* src/* /usr/local/bin/
|
||||||
CMD [ "/bin/bash" ]
|
|
||||||
|
|
||||||
|
CMD [ "/usr/local/bin/run-checker" ]
|
||||||
|
|
||||||
|
|
||||||
|
|
13
README.md
Normal file
13
README.md
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
# Docker Repo Checker
|
||||||
|
|
||||||
|
Container, that runs mirror process of git repository periodically
|
||||||
|
|
||||||
|
# Run command:
|
||||||
|
|
||||||
|
Tiniest case is:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run -v cloner-test:/data -it --rm docker-cloner
|
||||||
|
```
|
||||||
|
|
||||||
|
when you HAVE to specify volume with configuration etc
|
18
checker/cloner-lib-auth
Normal file
18
checker/cloner-lib-auth
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# library made for sourcing - just to prepare git auth environment
|
||||||
|
|
||||||
|
function prepareGitAuth(){
|
||||||
|
# usage
|
||||||
|
# $1 - config directory
|
||||||
|
confdir=$1/auth
|
||||||
|
[ -d $confdir ] || mkdir $confdir
|
||||||
|
[ -d $confdir/ssh ] || mkdir $confdir/ssh
|
||||||
|
|
||||||
|
chmod 0600 $confdir
|
||||||
|
|
||||||
|
# git configure http authenticator
|
||||||
|
git config --global credential.helper "store --file=$confdir/git-credentials"
|
||||||
|
# git configure ssh auth
|
||||||
|
git config --global core.sshcommand "ssh -i $confdir/ssh/id_rsa -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o BatchMode=yes"
|
||||||
|
}
|
||||||
|
|
12
checker/cloner-lib-cfg
Normal file
12
checker/cloner-lib-cfg
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# library for work with config file
|
||||||
|
|
||||||
|
# check directories if they exist
|
||||||
|
[ -d $CONFIG_DIR ] || die "Config directory does not exist on volune - $CONFIG_DIR"
|
||||||
|
[ -f $CONFIG_DIR/cloner.cfg ] || die "Config file does not exist - create please cloner.cfg"
|
||||||
|
# load config files
|
||||||
|
source $CONFIG_DIR/cloner.cfg
|
||||||
|
|
||||||
|
# check if the url is specified
|
||||||
|
repo=${cloner_repo_url:-}
|
||||||
|
[ -z "$repo" ] && die "No repository url is specified" || true
|
12
checker/cloner-lib-general
Normal file
12
checker/cloner-lib-general
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# configure
|
||||||
|
export BASE=/data
|
||||||
|
export CCLONE_PATH=$BASE/repos
|
||||||
|
export CCLONE_CACHE=$BASE/cache
|
||||||
|
export CONFIG_DIR=$BASE/config
|
||||||
|
|
||||||
|
function die(){
|
||||||
|
echo "$@" 1>&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
49
checker/run-checker
Executable file
49
checker/run-checker
Executable file
|
@ -0,0 +1,49 @@
|
||||||
|
#!/bin/bash
|
||||||
|
set -euo pipefail
|
||||||
|
IFS=$'\n\t'
|
||||||
|
|
||||||
|
# source libs
|
||||||
|
mydir=$(dirname $(realpath $0))
|
||||||
|
source $mydir/cloner-lib-general
|
||||||
|
source $mydir/cloner-lib-auth
|
||||||
|
source $mydir/cloner-lib-cfg
|
||||||
|
|
||||||
|
|
||||||
|
# interval - in minutes
|
||||||
|
interval=${cloner_interval:-0}
|
||||||
|
stampfile=$CCLONE_CACHE/last-check-time
|
||||||
|
|
||||||
|
# does it exist - if not, sync
|
||||||
|
[ -d $CCLONE_CACHE ] || mkdir $CCLONE_CACHE
|
||||||
|
[ -f $stampfile ] || echo 0 > $stampfile
|
||||||
|
|
||||||
|
|
||||||
|
now=$(date +"%s")
|
||||||
|
last=$(cat $stampfile)
|
||||||
|
diff=$(($now - $last))
|
||||||
|
mindiff=$(($interval * 60))
|
||||||
|
unset now last
|
||||||
|
|
||||||
|
if [ $diff -lt $mindiff ]
|
||||||
|
then
|
||||||
|
echo "Limit not reached - not syncing now"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# check and clone repo
|
||||||
|
submodules=${cloner_submodules:-0}
|
||||||
|
depth=${cloner_submodule_depth:-}
|
||||||
|
|
||||||
|
prepareGitAuth $CONFIG_DIR
|
||||||
|
|
||||||
|
# without submodule support
|
||||||
|
if [ ! "x$submodules" = "x1" ]
|
||||||
|
then
|
||||||
|
mirror-main-repo $repo
|
||||||
|
else
|
||||||
|
mirror-recursive $repo $depth
|
||||||
|
fi
|
||||||
|
|
||||||
|
date +"%s" > $stampfile
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user