You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
115 lines
3.0 KiB
115 lines
3.0 KiB
#!/bin/bash
|
|
|
|
|
|
#!-
|
|
. /etc/shlib
|
|
#!-
|
|
|
|
|
|
DOCKER_UPDATE_PATH=${DOCKER_UPDATE_PATH:-/srv/docker-builder}
|
|
KEEP_ONLY_PO="fr en de"
|
|
|
|
|
|
include common
|
|
include pretty
|
|
ansi_color no
|
|
usage="$exname COMPONENT MASTER_IMAGE_NAME BRANCH UPDATED_IMAGE_NAME"
|
|
|
|
COMPONENT_NAME="$1"
|
|
MASTER_IMAGE_NAME="$2"
|
|
BRANCH="$3"
|
|
UPDATED_IMAGE_NAME="$4"
|
|
|
|
## Note: we will need in the DOCKER_UPDATE_HOST:
|
|
## - git-sub
|
|
|
|
## should we check for aufs ?
|
|
|
|
mkdir -p "$DOCKER_UPDATE_PATH"
|
|
cd "$DOCKER_UPDATE_PATH"
|
|
if ! [ -d "$COMPONENT_NAME" ]; then
|
|
echo "ERROR: repository $DOCKER_UPDATE_PATH/$COMPONENT_NAME is not existent."
|
|
echo "You should build it on this host prior to run this hook."
|
|
echo "As a remainder: this host is supposed to keep the reference git that"
|
|
echo "was used to built the master image."
|
|
exit 1
|
|
fi
|
|
|
|
lock=$DOCKER_UPDATE_PATH/$COMPONENT_NAME.lock
|
|
if [ -e "$lock" ]; then
|
|
echo "Master is being updated."
|
|
echo "Or '$lock' file was left dangling over."
|
|
exit 1
|
|
fi
|
|
touch "$lock"
|
|
|
|
## This path is on the docker HOST !
|
|
AUFS_APPLY_PATH=${AUFS_APPLY_PATH:-/opt/apps/aufs_apply/bin/aufs_apply}
|
|
|
|
md5() {
|
|
find "$@" -type f -exec md5sum {} \; 2>/dev/null | md5sum | cut -f 1 -d " "
|
|
}
|
|
|
|
|
|
clean_all() {
|
|
cd /
|
|
mountpoint "$tmpdir_root" 2>/dev/null && umount "$tmpdir_root"
|
|
[ -d "$tmpdir_root" ] && rmdir "$tmpdir_root"
|
|
[ -d "$tmpdir_changes" ] && rm -rf "$tmpdir_changes"
|
|
rm "$lock"
|
|
}
|
|
|
|
tmpdir="$DOCKER_UPDATE_PATH"/tmp
|
|
mkdir -p "$tmpdir"
|
|
tmpdir_changes=$(mktemp -d $tmpdir/$COMPONENT_NAME.changes.XXXXXX)
|
|
tmpdir_root=$(mktemp -d $tmpdir/$COMPONENT_NAME.root.XXXXXX)
|
|
trap "clean_all" EXIT
|
|
mount -t aufs -o br=$tmpdir_changes:$DOCKER_UPDATE_PATH/$COMPONENT_NAME -o udba=none none "$tmpdir_root"
|
|
cd "$tmpdir_root"
|
|
## XXXvlab: We probably would need to:
|
|
## - fetch only the module concerned
|
|
## - fetch only the ref concerned
|
|
Wrap -d "Update source code" <<EOF
|
|
git fetch origin "$BRANCH"
|
|
git checkout "$BRANCH"
|
|
git reset --hard origin/$BRANCH
|
|
#git reset --hard "origin/$BRANCH"
|
|
git sub update
|
|
EOF
|
|
|
|
cd / &&
|
|
umount "$tmpdir_root" &&
|
|
rmdir "$tmpdir_root"
|
|
if [ "$?" != 0 ]; then
|
|
echo "Uh oh... could not umount aufs $tmpdir_root or delete it."
|
|
exit 1
|
|
fi
|
|
cd "$tmpdir_changes"
|
|
|
|
Wrap -d "Cleaning the change layer." <<EOF
|
|
find . -name .git -type d -exec rm -rf {} \; -prune
|
|
|
|
if [ "$KEEP_ONLY_PO" ]; then
|
|
find_args=""
|
|
for lang in $KEEP_ONLY_PO; do
|
|
find_args="\$find_args -not -name \$lang.po"
|
|
done
|
|
|
|
find /opt/apps -name \*.po -type f \$find_args -delete
|
|
fi
|
|
EOF
|
|
|
|
## XXXvlab: if we produced it we shouldn't have to pull it
|
|
#
|
|
#echo "Pulling $MASTER_IMAGE_NAME"
|
|
#docker pull "$MASTER_IMAGE_NAME" || exit 1
|
|
docker tag "$MASTER_IMAGE_NAME" "$UPDATED_IMAGE_NAME"
|
|
Elt "Updating $MASTER_IMAGE_NAME"
|
|
print_info $(cat <<EOF | docker-update "$UPDATED_IMAGE_NAME" -v "$tmpdir_changes:/mnt/changes" -v "$AUFS_APPLY_PATH:/usr/bin/aufs_apply"
|
|
## Applying changes: $(cd "$tmpdir_changes" ; md5 ".")
|
|
/usr/bin/aufs_apply /opt/apps/0k-oe /mnt/changes
|
|
EOF
|
|
)
|
|
Feedback || exit 1
|
|
|
|
Wrap -d "Push new $YELLOW$UPDATED_IMAGE_NAME$NORMAL to registry" docker push "$UPDATED_IMAGE_NAME"
|