Browse Source

new: [docker-builder] using new aufs_apply and cleaned output.

postgres
root 10 years ago
parent
commit
8338153e0e
  1. 35
      precise/docker-builder/src/usr/local/bin/hook-docker-update

35
precise/docker-builder/src/usr/local/bin/hook-docker-update

@ -12,7 +12,7 @@ KEEP_ONLY_PO="fr en de"
include common include common
include pretty include pretty
ansi_color no
usage="$exname COMPONENT MASTER_IMAGE_NAME BRANCH UPDATED_IMAGE_NAME" usage="$exname COMPONENT MASTER_IMAGE_NAME BRANCH UPDATED_IMAGE_NAME"
COMPONENT_NAME="$1" COMPONENT_NAME="$1"
@ -43,12 +43,20 @@ if [ -e "$lock" ]; then
fi fi
touch "$lock" 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() { clean_all() {
cd / cd /
mountpoint "$tmpdir_root" 2>/dev/null && umount "$tmpdir_root" mountpoint "$tmpdir_root" 2>/dev/null && umount "$tmpdir_root"
[ -d "$tmpdir_root" ] && rmdir "$tmpdir_root" [ -d "$tmpdir_root" ] && rmdir "$tmpdir_root"
[ -d "$tmpdir_changes" ] && rm -rf "$tmpdir_changes" [ -d "$tmpdir_changes" ] && rm -rf "$tmpdir_changes"
rm "$lock"
} }
tmpdir="$DOCKER_UPDATE_PATH"/tmp tmpdir="$DOCKER_UPDATE_PATH"/tmp
@ -58,15 +66,16 @@ tmpdir_root=$(mktemp -d $tmpdir/$COMPONENT_NAME.root.XXXXXX)
trap "clean_all" EXIT trap "clean_all" EXIT
mount -t aufs -o br=$tmpdir_changes:$DOCKER_UPDATE_PATH/$COMPONENT_NAME -o udba=none none "$tmpdir_root" mount -t aufs -o br=$tmpdir_changes:$DOCKER_UPDATE_PATH/$COMPONENT_NAME -o udba=none none "$tmpdir_root"
cd "$tmpdir_root" cd "$tmpdir_root"
set -eux
## XXXvlab: We probably would need to: ## XXXvlab: We probably would need to:
## - fetch only the module concerned ## - fetch only the module concerned
## - fetch only the ref concerned ## - fetch only the ref concerned
Wrap -d "Update source code" <<EOF
git fetch origin "$BRANCH" git fetch origin "$BRANCH"
git checkout "$BRANCH" git checkout "$BRANCH"
git reset --hard origin/$BRANCH git reset --hard origin/$BRANCH
#git reset --hard "origin/$BRANCH" #git reset --hard "origin/$BRANCH"
git sub update git sub update
EOF
cd / && cd / &&
umount "$tmpdir_root" && umount "$tmpdir_root" &&
@ -77,28 +86,30 @@ if [ "$?" != 0 ]; then
fi fi
cd "$tmpdir_changes" cd "$tmpdir_changes"
echo "Cleaning the change layer."
Wrap -d "Cleaning the change layer." <<EOF
find . -name .git -type d -exec rm -rf {} \; -prune find . -name .git -type d -exec rm -rf {} \; -prune
if [ "$KEEP_ONLY_PO" ]; then if [ "$KEEP_ONLY_PO" ]; then
find_args="" find_args=""
for lang in $KEEP_ONLY_PO; do for lang in $KEEP_ONLY_PO; do
find_args="$find_args -not -name $lang.po"
find_args="\$find_args -not -name \$lang.po"
done done
find /opt/apps -name \*.po -type f $find_args -delete
find /opt/apps -name \*.po -type f \$find_args -delete
fi fi
EOF
## XXXvlab: if we produced it we shouldn't have to pull it ## XXXvlab: if we produced it we shouldn't have to pull it
# #
#echo "Pulling $MASTER_IMAGE_NAME" #echo "Pulling $MASTER_IMAGE_NAME"
#docker pull "$MASTER_IMAGE_NAME" || exit 1 #docker pull "$MASTER_IMAGE_NAME" || exit 1
cat <<EOF | docker-update "$MASTER_IMAGE_NAME" -v "$tmpdir_changes:/mnt/changes"
mkdir -p /srv/app/{root,changes}
cp -a /mnt/changes /srv/app/changes/0000
ls /srv/app/changes/0000
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 EOF
)
Feedback || exit 1
docker push "$UPDATED_IMAGE_NAME"
Wrap -d "Push new $YELLOW$UPDATED_IMAGE_NAME$NORMAL to registry" docker push "$UPDATED_IMAGE_NAME"
Loading…
Cancel
Save