-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathentrypoint.sh
executable file
·58 lines (47 loc) · 1.27 KB
/
entrypoint.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
#!/usr/bin/env sh
set -o pipefail
set -e
BASE_IMAGE=${1:-}
IMAGE=${2:-}
BASE_REG_USERNAME=${3:-}
BASE_REG_PASSWORD=${4:-}
IMAGE_REG_USERNAME=${5:-}
IMAGE_REG_PASSWORD=${6:-}
if [[ -z "${BASE_IMAGE}" || -z "${IMAGE}" ]]; then
echo "::error title=argument::Missing Argument base-image or image"
exit 1
fi
get_layers(){
image=$1
username=$2
password=$3
cmd="manifest-tool"
if [ -n "${username}" ] && [ -n "${password}" ]; then
cmd="${cmd} --username=${username} --password=${password}"
fi
cmd="${cmd} inspect ${image} --raw"
op=$($cmd)
retval=$?
if [ $retval -ne 0 ]; then
echo "::error title=get_layers::Failed to get layers for ${image}"
return $retval
fi
layers=$(echo ${op} | jq -r ".[]|.Layers[]?")
echo "$layers"
}
get_base_layers(){
get_layers "${BASE_IMAGE}" "${BASE_REG_USERNAME}" "${BASE_REG_PASSWORD}"
}
get_image_base_layer(){
# returns only the first layer(base layer)
get_layers "${IMAGE}" "${IMAGE_REG_USERNAME}" "${IMAGE_REG_PASSWORD}" | head -n 1
}
base_layers=$(get_base_layers)
image_base_layer=$(get_image_base_layer)
found=$(echo "${base_layers}" | grep -c "${image_base_layer}")
retval=$?
if [ "$found" -gt 0 ]; then
echo "needs-update=false" >> $GITHUB_OUTPUT
else
echo "needs-update=true" >> $GITHUB_OUTPUT
fi