-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
executable file
·53 lines (40 loc) · 1.15 KB
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env bash
# AUTHOR= Jessie Frazelle
# It's an copy of the jessfraz dockerfiles test.
set -e
# Exit on error in any of pipe commands
set -o pipefail
UPSTREAM_REPO="https://github.com/dungeonmaster18/awesome-dockerfiles.git"
UPSTREAM_BRANCH="master"
VALIDATE_HEAD="$(git rev-parse --verify HEAD)"
git fetch -q "$UPSTREAM_REPO" "refs/heads/$UPSTREAM_BRANCH"
VALIDATE_UPSTREAM="$(git rev-parse --verify FETCH_HEAD)"
VALIDATE_COMMIT_DIFF="$VALIDATE_UPSTREAM...$VALIDATE_HEAD"
validate_diff() {
if [ "$VALIDATE_UPSTREAM" != "$VALIDATE_HEAD" ]; then
git diff "$VALIDATE_COMMIT_DIFF" "$@"
else
git diff HEAD~ "$@"
fi
}
# Get changed dockerfiles after previous commit
IFS=$'\n'
changed_files=( $(validate_diff --name-only -- '*Dockerfile') )
unset IFS
# build the changed dockerfiles
for f in "${changed_files[@]}"; do
if ! [[ -e "$f" ]]; then
continue
fi
build_dir=$(dirname "$f")
base="${build_dir%%\/*}"
tag="${build_dir##*}"
if [[ -z "$tag" ]]; then
tag=latest
fi
(
set -x
docker build -t "$DOCKER_USERNAME/$base:$tag" "$build_dir"
)
echo "Successfully built "{$base}:{$tag}" with context "$build_dir""
done