-
Notifications
You must be signed in to change notification settings - Fork 2
/
push-stages.sh
executable file
·51 lines (46 loc) · 1.06 KB
/
push-stages.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
#!/usr/bin/env bash
RED='\033[0;31m'
GREEN='\033[0;32m'
CYAN='\033[0;36m'
NC='\033[0m'
repository="docker.io/pusher"
for arg in "$@"; do
case ${arg%%=*} in
"--build-root")
build_root="${arg##*=}"
;;
"--repository")
repository="${arg##*=}"
;;
"--help")
printf "${GREEN}$0${NC}\n"
printf " available options:\n"
printf " --build-root=${BLUE}<docker build root>${NC}\n"
exit 0
;;
*)
echo "Unknown option: $arg"
exit 2
;;
esac
done
###########################################
#
# Check if the image is a multi stage build
#
###########################################
lines=$(grep 'FROM .* AS' ${build_root}/Dockerfile)
declare -a stages
while read -r from; do
stage=$(echo $from | sed -E 's|FROM .* AS (.*)$|\1|')
stages+=($stage)
done <<< "$lines"
#####################
#
# Push any pre-stages
#
#####################
for stage in "${stages[@]}"; do
echo -e "${CYAN}Pushing Docker pre-stage: ${build_root}:${stage}${NC}"
docker push ${repository}/${build_root}:stage-${stage}
done