mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-16 03:49:52 +00:00
b990f48 Merge pull request #42 from kinvolk/lorenzo/fix-git-diff 224a145 Check if SHA1 exists before calling `git diff` 1c3000d Add auto_apply config for wcloud 0ebf5c0 Fix wcloud -serivice4fe078aMerge pull request #39 from weaveworks/fix-wrong-subtree-use3f4934dRemove generate_latest_map48beb60Sync changes done directly in scope/tools45dcdd5Merge pull request #37 from weaveworks/fix-mflag-missingb895344Use mflag package from weaveworks fork until we find a better solutione030008Merge pull request #36 from weaveworks/wcloud-service-flags9cbab40Add wcloud Makefileef55901Review feedback, and build wcloud in circle.3fe92f5Add wcloud deploy --service flag3527b56Merge pull request #34 from weaveworks/repo-branch92cd0b8[wcloud] Add support for repo_branch option9f760abAllow wcloud users to override username38037f8Merge pull request #33 from weaveworks/wcloud-templates7acfbd7Propagate the local usernamee6876d1Add template fields to wcloud config.f1bb537Merge pull request #30 from weaveworks/mike/shell-lint/dont-error-if-emptye60f5dfMerge pull request #31 from weaveworks/mike/fix-shell-lint-errorse8e2b69integrations: Fix a shellcheck linter errora781575shell-lint: Don't fail if no shell scripts founddb5efc0Merge pull request #28 from weaveworks/mike/add-image-tag5312c40Import image-tag script into build tools so it can be shared7e850f8Fix logs pathdda9785Update deploy apif2f4e5bFix the wcloud client3925eb6Merge pull request #27 from weaveworks/wcloud-events77355b9Lintd9a1c6cAdd wcloud events, update flags and error nicely when there is no config git-subtree-dir: tools git-subtree-split: b990f488bdc7909b62d9245bc4b4caf58f5ae7ea
80 lines
1.9 KiB
Bash
Executable File
80 lines
1.9 KiB
Bash
Executable File
#!/bin/bash
|
|
# Rebuild a cached docker image if the input files have changed.
|
|
# Usage: ./rebuild-image <image name> <image dir> <image files...>
|
|
|
|
set -eux
|
|
|
|
IMAGENAME=$1
|
|
# shellcheck disable=SC2001
|
|
SAVEDNAME=$(echo "$IMAGENAME" | sed "s/[\/\-]/\./g")
|
|
IMAGEDIR=$2
|
|
shift 2
|
|
|
|
INPUTFILES=( "$@" )
|
|
CACHEDIR=$HOME/docker/
|
|
|
|
# Rebuild the image
|
|
rebuild() {
|
|
mkdir -p "$CACHEDIR"
|
|
rm "$CACHEDIR/$SAVEDNAME"* || true
|
|
docker build -t "$IMAGENAME" "$IMAGEDIR"
|
|
docker save "$IMAGENAME:latest" | gzip - > "$CACHEDIR/$SAVEDNAME-$CIRCLE_SHA1.gz"
|
|
}
|
|
|
|
# Get the revision the cached image was build at
|
|
cached_image_rev() {
|
|
find "$CACHEDIR" -name "$SAVEDNAME-*" -type f | sed -n 's/^[^\-]*\-\([a-z0-9]*\).gz$/\1/p'
|
|
}
|
|
|
|
# Have there been any revision between $1 and $2
|
|
has_changes() {
|
|
local rev1=$1
|
|
local rev2=$2
|
|
local changes
|
|
changes=$(git diff --oneline "$rev1..$rev2" -- "${INPUTFILES[@]}" | wc -l)
|
|
[ "$changes" -gt 0 ]
|
|
}
|
|
|
|
commit_timestamp() {
|
|
local rev=$1
|
|
git show -s --format=%ct "$rev"
|
|
}
|
|
|
|
# Is the SHA1 actually present in the repo?
|
|
# It could be it isn't, e.g. after a force push
|
|
is_valid_commit() {
|
|
local rev=$1
|
|
git rev-parse --quiet --verify "$rev^{commit}" > /dev/null
|
|
}
|
|
|
|
cached_revision=$(cached_image_rev)
|
|
if [ -z "$cached_revision" ]; then
|
|
echo ">>> No cached image found; rebuilding"
|
|
rebuild
|
|
exit 0
|
|
fi
|
|
|
|
if ! is_valid_commit "$cached_revision"; then
|
|
echo ">>> Git commit of cached image not found in repo; rebuilding"
|
|
rebuild
|
|
exit 0
|
|
fi
|
|
|
|
echo ">>> Found cached image rev $cached_revision"
|
|
if has_changes "$cached_revision" "$CIRCLE_SHA1" ; then
|
|
echo ">>> Found changes, rebuilding"
|
|
rebuild
|
|
exit 0
|
|
fi
|
|
|
|
IMAGE_TIMEOUT="$(( 3 * 24 * 60 * 60 ))"
|
|
if [ "$(commit_timestamp "$cached_revision")" -lt "${IMAGE_TIMEOUT}" ]; then
|
|
echo ">>> Image is more the 24hrs old; rebuilding"
|
|
rebuild
|
|
exit 0
|
|
fi
|
|
|
|
# we didn't rebuild; import cached version
|
|
echo ">>> No changes found, importing cached image"
|
|
zcat "$CACHEDIR/$SAVEDNAME-$cached_revision.gz" | docker load
|