-
Notifications
You must be signed in to change notification settings - Fork 33
/
build_push_images.sh
executable file
·63 lines (55 loc) · 1.5 KB
/
build_push_images.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
54
55
56
57
58
59
60
61
62
63
#!/bin/bash -e
export IMAGE_NAME=shippabledocker/micro-mono
detect_changed_languages() {
echo "detecting changes for this build"
languages=`git diff --name-only $SHIPPABLE_COMMIT_RANGE | sort -u | awk 'BEGIN {FS="/"} {print $1}' | uniq`
for language in $languages
do
unset changed_components
detect_changed_folders $language
tag_and_push_changed_components
done
}
detect_changed_folders() {
folders=`git diff --name-only $SHIPPABLE_COMMIT_RANGE | sort -u | grep $1 | awk 'BEGIN {FS="/"} {print $2}' | uniq`
push_all_images=false
for folder in $folders
do
if [ "$folder" == '_global' ]; then
echo "pushing all images"
push_all_images=true
break
fi
done
if [ "$push_all_images" == true ]; then
cd $1
export changed_components+=`ls -d */ | sed 's/.$//'`
cd ..
else
export changed_components+=$folders
fi
}
tag_and_push_changed_components() {
for component in $changed_components
do
if [ "$component" != '_global' ] && [ "$component" != 'node_modules' ]; then
tag_and_push_image $component
fi
done
}
tag_and_push_image() {
if [[ -z "$1" ]]; then
return 0
else
echo "building image $1"
sudo docker build -t $IMAGE_NAME:$1.$BRANCH.$SHIPPABLE_BUILD_NUMBER ./$language/$1
echo "pushing image $1"
sudo docker push $IMAGE_NAME:$1.$BRANCH.$SHIPPABLE_BUILD_NUMBER
fi
}
if [ "$IS_PULL_REQUEST" != true ]; then
detect_changed_languages
# tag_and_push_changed_components
else
echo "skipping because it's a PR"
fi