Launcher image
This commit is contained in:
parent
51f19c805b
commit
94ba9b86c7
8
Makefile
8
Makefile
|
@ -12,13 +12,19 @@ mirror:
|
|||
run-mirror: mirror
|
||||
docker run -v $(VOLUME):/data -it --rm $(TAGBASE)-mirror
|
||||
|
||||
# Creator - ./creator dir
|
||||
# Creator - ./creator-image dir
|
||||
creator:
|
||||
docker build -t $(TAGBASE)-creator ./creator-image
|
||||
|
||||
run-creator: creator
|
||||
docker run -v /var/run/docker.sock:/var/run/docker.sock -it --rm $(TAGBASE)-creator
|
||||
|
||||
# Launcher - ./launcher-image
|
||||
launcher:
|
||||
docker build -t $(TAGBASE)-launcher ./launcher-image
|
||||
|
||||
run-launcher: launcher
|
||||
docker run -v /var/run/docker.sock:/var/run/docker.sock -it --rm $(TAGBASE)-launcher
|
||||
|
||||
# wizzard
|
||||
wizzard: mirror run-creator
|
||||
|
|
11
launcher-image/Dockerfile
Normal file
11
launcher-image/Dockerfile
Normal file
|
@ -0,0 +1,11 @@
|
|||
# Alpine base image
|
||||
FROM alpine:edge
|
||||
|
||||
RUN apk add --no-cache bash docker parallel ; \
|
||||
echo "* * * * * /bin/cron-command" >> /etc/crontabs/root
|
||||
|
||||
ADD src/* /bin/
|
||||
|
||||
CMD [ "/bin/entrypoint" ]
|
||||
|
||||
|
39
launcher-image/src/cron-command
Executable file
39
launcher-image/src/cron-command
Executable file
|
@ -0,0 +1,39 @@
|
|||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
IFS=$'\n\t'
|
||||
|
||||
# trap
|
||||
lock=/var/run/cloner.pid
|
||||
|
||||
volume_prefix=cloner
|
||||
clone_prefix=cloner-runner
|
||||
|
||||
|
||||
function die(){
|
||||
echo $@ 1>&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
# first, check process
|
||||
if [ -f $lock ]
|
||||
then
|
||||
pid=$(cat $lock)
|
||||
# if it still runs, die not so quietly
|
||||
[ -d /proc/$pid ] && die "Another process running!"
|
||||
fi
|
||||
# else make some mess and setup trap
|
||||
echo $BASHPID > $lock
|
||||
function finish {
|
||||
rm -rf $lock
|
||||
}
|
||||
trap finish EXIT
|
||||
|
||||
|
||||
# declare functions
|
||||
function listVolumes(){
|
||||
docker volume ls --filter=name=$volume_prefix- --quiet
|
||||
}
|
||||
|
||||
# run for every volume in parallel
|
||||
listVolumes | parallel --lb -j 3 -n 1 --progress run-mirror-update
|
||||
|
11
launcher-image/src/entrypoint
Executable file
11
launcher-image/src/entrypoint
Executable file
|
@ -0,0 +1,11 @@
|
|||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
IFS=$'\n\t'
|
||||
|
||||
# make parallel citation shut up
|
||||
mkdir $HOME/.parallel
|
||||
touch $HOME/.parallel/will-cite
|
||||
|
||||
# run cron
|
||||
crond -f
|
||||
|
67
launcher-image/src/run-mirror-update
Executable file
67
launcher-image/src/run-mirror-update
Executable file
|
@ -0,0 +1,67 @@
|
|||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
IFS=$'\n\t'
|
||||
|
||||
mirror_image="valicek1/repo-cloner-mirror"
|
||||
|
||||
|
||||
function log(){
|
||||
local title=${raw:-$name}
|
||||
[ -z "$title" ] || title=" [$title]"
|
||||
echo "[$(date +"%X")]$title $@"
|
||||
}
|
||||
|
||||
function die(){
|
||||
log "$@" 1>&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
||||
scratch=$(mktemp -d -t tmp.XXXXXXXXXX)
|
||||
function finish {
|
||||
rm -rf "$scratch"
|
||||
}
|
||||
trap finish EXIT
|
||||
|
||||
volume_prefix=cloner
|
||||
clone_prefix=cloner-runner
|
||||
|
||||
name=${1:-}
|
||||
[ -n "$name" ] || die "No volume specified"
|
||||
|
||||
# contains prefix
|
||||
[[ "$name" == $volume_prefix-* ]] || die "Volume name does not contain prefix!"
|
||||
|
||||
raw=$(echo $name | sed "s/^$volume_prefix-//g")
|
||||
|
||||
container_name=$clone_prefix-$raw
|
||||
|
||||
# does it run?
|
||||
docker ps --quiet --no-trunc --filter name=^/$container_name$ > $scratch/running
|
||||
lines=$(wc -l $scratch/running | cut -f1 -d' ')
|
||||
|
||||
if ! [ $lines -eq 0 ]
|
||||
then
|
||||
log "Another copy of container is running.. Exiting silently"
|
||||
exit 0
|
||||
fi
|
||||
unset lines
|
||||
|
||||
# does it exist?
|
||||
docker ps --quiet -a --no-trunc --filter name=^/$container_name$ > $scratch/existing
|
||||
lines=$(wc -l $scratch/existing | cut -d' ' -f1)
|
||||
|
||||
if ! [ $lines -eq 0 ]
|
||||
then
|
||||
log "Conflicting container exists, removing.."
|
||||
docker rm $(cat $scratch/existing)
|
||||
fi
|
||||
|
||||
unset lines
|
||||
|
||||
# does volume exist?
|
||||
docker volume inspect $name > /dev/null 2>&1 || die "Volume '$name' does not exist - exiting!"
|
||||
|
||||
log "Running container of update process..."
|
||||
docker run -v $name:/data --name $container_name --rm $mirror_image | while read line; do log "$line"; done
|
||||
log "Finished."
|
Loading…
Reference in New Issue
Block a user