-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDocker.buildx.sh
More file actions
executable file
·147 lines (137 loc) · 4.96 KB
/
Copy pathDocker.buildx.sh
File metadata and controls
executable file
·147 lines (137 loc) · 4.96 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#! /bin/bash
# The MIT License (MIT)
#
# Copyright © 2026 The pyTooling Authors
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
# Software.
#
# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# shellcheck shell=bash
# Save working directory
WorkingDir=$(pwd)
ScriptDir="$(readlink -f "$(dirname "$0")")"
RootDir="$(readlink -f "$ScriptDir/..")"
ANSI_BLACK=$'\x1b[30m'
ANSI_RED=$'\x1b[31m'
ANSI_GREEN=$'\x1b[32m'
ANSI_YELLOW=$'\x1b[33m'
ANSI_BLUE=$'\x1b[34m'
ANSI_MAGENTA=$'\x1b[35m'
ANSI_CYAN=$'\x1b[36m'
ANSI_DARK_GRAY=$'\x1b[90m'
ANSI_LIGHT_GRAY=$'\x1b[37m'
ANSI_LIGHT_RED=$'\x1b[91m'
ANSI_LIGHT_GREEN=$'\x1b[92m'
ANSI_LIGHT_YELLOW=$'\x1b[93m'
ANSI_LIGHT_BLUE=$'\x1b[94m'
ANSI_LIGHT_MAGENTA=$'\x1b[95m'
ANSI_LIGHT_CYAN=$'\x1b[96m'
ANSI_WHITE=$'\x1b[97m'
ANSI_NOCOLOR=$'\x1b[0m'
# red texts
COLORED_ERROR="${ANSI_RED}[ERROR]"
# command line argument processing
COMMAND=2 # 0-help, 1-unknown option, 2-no arg needed
INDENT=""
VERBOSE=0; DEBUG=0
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-i|--indent)
shift
INDENT=$1
;;
# -v|--verbose)
# VERBOSE=1
# ;;
# -d|--debug)
# VERBOSE=1
# DEBUG=1
# ;;
-h|--help)
COMMAND=0
;;
*) # unknown option
echo 1>&2 -e "${COLORED_ERROR} Unknown command line option '$key'.${ANSI_NOCOLOR}"
COMMAND=1
;;
esac
shift # past argument or value
done
if [ $COMMAND -le 1 ]; then
printf "%s\n" ""
printf "%s\n" "Synopsis:"
printf "%s\n" " Script to filter Docker 'buildx' outputs."
printf "%s\n" ""
printf "%s\n" "Usage:"
printf "%s\n" " Docker.buildx.sh [-v][-d] [--help] [--indent <pattern>]"
printf "%s\n" ""
printf "%s\n" "Common commands:"
printf "%s\n" " -h --help Print this help page."
printf "%s\n" ""
printf "%s\n" "Common options:"
# printf "%s\n" " -v --verbose Print verbose messages."
# printf "%s\n" " -d --debug Print debug messages."
printf "%s\n" " -i --indent <pattern> Indent all lines by this pattern."
printf "%s\n" ""
exit $COMMAND
fi
# Counters
Counter_Error=0
Pattern_CACHED='#[0-9]+ CACHED'
Pattern_FROM='#[0-9]+ \[([-a-zA-Z0-9]+ )?[0-9]+/[0-9]+\] FROM'
Pattern_RUN='#[0-9]+ \[([-a-zA-Z0-9]+ )?[0-9]+/[0-9]+\] RUN'
Pattern_COPY='#[0-9]+ \[([-a-zA-Z0-9]+ )?[0-9]+/[0-9]+\] COPY'
Pattern_LABEL_ENV='#[0-9]+ \[([-a-zA-Z0-9]+ )?[0-9]+/[0-9]+\] (LABEL|ENV)'
Pattern_DONE='#[0-9]+ DONE [0-9]+\.[0-9]+s'
Pattern_ERROR='(#[0-9]+ )?ERROR:'
Pattern_CANCELED='#[0-9]+ CANCELED'
Pattern_Tagging='#[0-9]+ naming to (.*?) done'
Pattern_MIKTEX='#[0-9]+ [0-9]+\.[0-9]+ Installing package'
group=0
while IFS=$'\n' read -r line; do
if [[ "${line}" =~ $Pattern_FROM ]]; then
printf "::group::%s\n" "${INDENT}${ANSI_MAGENTA}${line}${ANSI_NOCOLOR}"
group=1
elif [[ "${line}" =~ $Pattern_RUN ]]; then
printf "::group::%s\n" "${INDENT}${ANSI_CYAN}${line}${ANSI_NOCOLOR}"
group=1
elif [[ "${line}" =~ $Pattern_COPY ]]; then
printf "%s\n" "${INDENT}${ANSI_LIGHT_CYAN}${line}${ANSI_NOCOLOR}"
elif [[ "${line}" =~ $Pattern_LABEL_ENV ]]; then
printf "%s\n" "${INDENT}${ANSI_BLUE}${line}${ANSI_NOCOLOR}"
elif [[ "${line}" =~ $Pattern_DONE ]]; then
if [[ $group -eq 1 ]]; then
printf "::endgroup::\n"
fi
printf "%s\n" "${INDENT}${ANSI_GREEN}${line}${ANSI_NOCOLOR}"
group=0
elif [[ "${line}" =~ $Pattern_ERROR ]]; then
printf "%s\n" "${INDENT}${ANSI_LIGHT_RED}${line}${ANSI_NOCOLOR}"
elif [[ "${line}" =~ $Pattern_CANCELED ]]; then
printf "%s\n" "${INDENT}${ANSI_LIGHT_RED}${line}${ANSI_NOCOLOR}"
elif [[ "${line}" =~ $Pattern_CACHED ]]; then
printf "%s\n" "${INDENT}${ANSI_YELLOW}${line}${ANSI_NOCOLOR}"
elif [[ "${line}" =~ $Pattern_Tagging ]]; then
ImageName=${BASH_REMATCH[1]}
printf "%s\n" "${INDENT}${ANSI_LIGHT_GREEN}${line}${ANSI_NOCOLOR}"
elif [[ "${line}" =~ $Pattern_MIKTEX ]]; then
printf "%s\n" "${INDENT}${ANSI_LIGHT_BLUE}${line}${ANSI_NOCOLOR}"
else
printf "%s\n" "${INDENT}${ANSI_LIGHT_GRAY}${line}${ANSI_NOCOLOR}"
fi
done < "/dev/stdin"
if [[ -n "${ImageName}" ]]; then
printf "%s\n" ""
printf "%s\n" "Image size of '${ImageName}' is $(docker image inspect ${ImageName} --format='{{.Size}}' | numfmt --to=iec)"
fi
exit $Counter_Error