-
Notifications
You must be signed in to change notification settings - Fork 259
/
in
executable file
·90 lines (65 loc) · 2.25 KB
/
in
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
#!/bin/sh
# vim: set ft=sh
set -e
exec 3>&1 # make stdout available as fd 3 for the result
exec 1>&2 # redirect all output to stderr for logging
source $(dirname $0)/common.sh
destination=$1
if [ -z "$destination" ]; then
echo "usage: $0 <path/to/destination>" >&2
exit 1
fi
# for jq
PATH=/usr/local/bin:$PATH
payload=$(mktemp /tmp/resource-in.XXXXXX)
cat > $payload <&0
insecure_registries=$(jq -r '.source.insecure_registries // [] | join(" ")' < $payload)
start_docker "$insecure_registries"
username=$(jq -r '.source.username // ""' < $payload)
password=$(jq -r '.source.password // ""' < $payload)
email=$(jq -r '.source.email // ""' < $payload)
repository="$(jq -r '.source.repository // ""' < $payload)"
tag="$(jq -r '.source.tag // "latest"' < $payload)"
if private_registry "${repository}" ; then
registry="$(extract_registry "${repository}")"
else
registry=
fi
digest="$(jq -r '.version.digest' < $payload)"
rootfs="$(jq -r '.params.rootfs // false' < $payload)"
skip_download="$(jq -r '.params.skip_download // false' < $payload)"
save="$(jq -r '.params.save // false' < $payload)"
mkdir -p $destination
image_name="${repository}@${digest}"
if [ "$skip_download" = "false" ]; then
if [ -n "${username}" ] && [ -n "${password}" ] && [ -n "${email}" ]; then
docker login -u "${username}" -p "${password}" -e "${email}" ${registry}
fi
docker_pull "$image_name"
if [ "$save" = "true" ]; then
docker save -o ${destination}/image "$image_name"
fi
docker run \
--cidfile=/tmp/container.cid \
-v /opt/resource/print-metadata:/tmp/print-metadata \
--entrypoint /tmp/print-metadata \
"$image_name" > ${destination}/metadata.json
mkdir -p ${destination}/rootfs/
docker export $(cat /tmp/container.cid) | tar -xf - -C ${destination}/rootfs/
if [ "$rootfs" = "true" ]; then
docker export $(cat /tmp/container.cid) > ${destination}/rootfs.tar
fi
fi
image_id="$(image_from_digest "$repository" "$digest")"
echo "$repository" > ${destination}/repository
echo "$tag" > ${destination}/tag
echo "$image_id" > ${destination}/image-id
echo "$digest" > ${destination}/digest
jq -n "{
version: {
digest: $(echo $digest | jq -R .)
},
metadata: [
{ name: \"image\", value: $(echo $image_id | head -c 12 | jq -R .) }
]
}" >&3