-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdocker-manifest.sh
executable file
·673 lines (600 loc) · 22.7 KB
/
docker-manifest.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
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
#!/bin/bash
set -e
RED='\033[0;31m'
CYAN='\033[0;36m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NC='\033[0m'
REPO_REGISTRY="https://registry-1.docker.io/v2"
REPO_AUTH="https://auth.docker.io"
LIST_TEMPLATE="{
\"schemaVersion\": 2,
\"mediaType\": \"application/vnd.docker.distribution.manifest.list.v2+json\",
\"manifests\": [
IMAGES
]
}"
IMAGE_TEMPLATE=" {
\"mediaType\": \"application/vnd.docker.distribution.manifest.v2+json\",
\"size\": IMAGE_SIZE,
\"digest\": \"IMAGE_DIGEST\",
\"platform\": {
\"architecture\": \"ARCHITECTURE\",
\"os\": \"OS\"
}
}"
# arrays to store temporary values
declare -A TOKENS
declare -A CROSS_TOKENS
declare -A OPTIONS
declare -A MANIFESTS
CURL_OPT="-s -L"
V2SCHEMA2_MANIFEST_LIST="application/vnd.docker.distribution.manifest.list.v2+json"
V2SCHEMA2_MANIFEST="application/vnd.docker.distribution.manifest.v2+json"
V2SCHEMA2_CONTAINER_CFG="application/vnd.docker.container.image.v1+json"
OUTPUT_DIR="output"
make_request()
{
curl -s -L -w "HTTPSTATUS:%{http_code}" $@
}
get_request_status()
{
# response code of make_request
echo $1 | tail -1 | sed -e 's/.*HTTPSTATUS://'
}
get_request_body()
{
# response body of make_request
echo $1 | sed -e 's/HTTPSTATUS\:.*//g'
}
get_token()
{
local repo="$1"
# request for it now
curl ${CURL_OPT} \
"${REPO_AUTH}/token?service=registry.docker.io&scope=repository:${repo}:pull" \
| jq -r '.token'
}
get_manifests_list()
{
local repo=$(echo "$1" | cut -d ':' -f 1)
local tag=$(echo "$1" | cut -d ':' -f 2)
local token=$2
# load manifest.list
curl ${CURL_OPT} \
--header "Authorization: Bearer ${token}" \
--header "Accept: ${V2SCHEMA2_MANIFEST_LIST}" \
"${REPO_REGISTRY}/${repo}/manifests/$tag"
}
get_manifest()
{
local repo=$(echo "$1" | cut -d ':' -f 1)
local tag=$(echo "$1" | cut -d ':' -f 2)
local token=$2
local flag=$3
# load manifest
curl $flag ${CURL_OPT} \
--header "Authorization: Bearer ${token}" \
--header "Accept: ${V2SCHEMA2_MANIFEST}" \
"${REPO_REGISTRY}/${repo}/manifests/${tag}"
}
get_image()
{
local repo=$(echo "$1" | cut -d ':' -f 1)
local token=$2
local digest=$3
# load image info
curl ${CURL_OPT} \
--header "Authorization: Bearer $token" \
--header "Accept: ${V2SCHEMA2_CONTAINER_CFG}" \
"${REPO_REGISTRY}/${repo}/blobs/$digest"
}
process_option()
{
opt=$(echo $1 | sed -e 's/^-*//')
echo "opt: $opt"
case "$opt" in
# save value
os|arch|os-features|variant)
OPTIONS["$opt"]="$2"
;;
# default is to mark the option selected-"Y"
*)
OPTIONS["$opt"]="Y"
;;
esac
}
show_create_help()
{
echo -e "Usage: $0 create [OPTIONS] MANFEST_LIST MANIFEST [MANIFEST...]\n"
echo -e "Create a local manifest list for annotating and pushing to a registry\n"
echo "Options:"
echo " -a, --amend Amend an existing manifest list"
echo " --insecure allow communication with an insecure registry"
echo " --help Print usage"
}
show_annotate_help()
{
echo -e "Usage: $0 annotate MANIFEST_LIST MANIFEST [OPTIONS]\n"
echo -e "Add additional information to a local image manifest\n"
echo "Options:"
echo " --arch string Set architecture"
echo " --os string Set operating system"
echo " --os-features stringSlice Set operating system feature"
echo " --variant string Set architecture variant"
echo " --help Print usage"
}
show_inspect_help()
{
echo -e "Usage: $0 inspect [OPTIONS] [MANIFEST_LIST] MANIFEST\n"
echo -e "Display an image manifest, or manifest list\n"
echo "Options:"
echo " -v, --verbose Output additional info including layers and platform"
echo " --insecure allow communication with an insecure registry"
echo " --help Print usage"
}
show_push_help()
{
echo -e "Usage: $0 push [OPTIONS] MANIFEST_LIST\n"
echo -e "Push a manifest list to a repository"
echo "Options:"
echo " --insecure allow push to an insecure registry"
echo " -p, --purge Remove the local manifest list after push"
echo " --help Print usage"
}
showhelp()
{
echo "A script to manage docker manifests"
echo ""
echo "Usage: $0 COMMAND"
echo "Commands:"
echo -e " create\tCreate a local manifest list for annotating and pushing to a registry"
echo -e " annotate\tAdd additional information to a local image manifest"
echo -e " inspect\tDisplay an image manifest, or manifest list"
echo -e " push \tPush a manifest list to a repository"
echo ""
echo "Run '$0 COMMAND --help' for more information on a command."
}
process_create()
{
# input validate
if [ "--help" == "$1" ] || [ $# -lt 2 ]; then
show_create_help
exit 1
fi
# process arguments
local i=0
while (( "$#" )); do
case "$1" in
-*|--*)
opt=$(echo $1 | sed -e 's/^-*//')
OPTIONS["$opt"]="Y"
;;
*)
MANIFESTS[$i]=$1
let i=i+1
;;
esac
shift
done
if [ "Y" == "${OPTIONS[insecure]}" ]; then
# add -k option to curl
CURL_OPT="${CURL_OPT} -k"
fi
# "amend" option is omitted as we'll write manifests file anyway
should_fail="NO"
# extract manifests list fields
list_repo=$(echo ${MANIFESTS[0]} | cut -d ':' -f 1)
list_tag=$(echo ${MANIFESTS[0]} | cut -d ':' -f 2)
list_name="$(echo $list_repo | sed -e 's|/|\#|')#$list_tag"
# process specified images one by one
images_list=""
# MANIFESTS[0] is always the "manifests list"
for ((i=1; i <${#MANIFESTS[@]}; i++)); do
this_image=${MANIFESTS[$i]}
repo=$(echo "$this_image" | cut -d ':' -f 1)
tag=$(echo "$this_image" | cut -d ':' -f 2)
# check read token for $repo
token=${TOKENS[${repo}]}
if [ -z "$token" ]; then
# request and cache read token
token=$(get_token $repo)
TOKENS[${repo}]=$token
fi
# check if specified item is a manifests list.
# manifests-list cannot be added
api_resp=$(get_manifests_list $this_image $token)
list_count=$(echo "$api_resp" | jq '.manifests | length')
if [ $list_count -eq 0 ]; then
# this is a image manifest, now read its info
printf "Reading [${CYAN}${MANIFESTS[$i]}${NC}] ...."
# read header to find length and digest
get_manifest $this_image $token "-I -D /tmp/$$.txt" > /dev/null
header=$(cat /tmp/$$.txt)
content_length=$(echo "$header" | grep 'Content-Length' | tr -d ' \n\r' | cut -d ':' -f 2)
digest=$(echo "$header" | grep 'Docker-Content-Digest' | tr -d '\n\r' | cut -d ' ' -f 2)
rm /tmp/$$.txt
#echo "digest: $digest"
if [ ! -z $digest ]; then
printf " ${GREEN}Success${NC}\n"
# specified image is found, now load its manifest info to read blob digest
# so we can detect arch/os/features
api_resp=$(get_manifest $this_image $token)
blob_digest=$(echo $api_resp | jq -r '.config.digest')
#echo "blob digest: $blob_digest"
# check if $this_image repo is same as $list_repo
# if not, we need to
# 1. mount blob layers to make it visible to $list_repo
# 2. push reference manifest to $list_repo
# check: https://docs.docker.com/registry/spec/api/ Cross Repository Blob Mount
if [ "$repo" != "$list_repo" ]; then
# do mount
# 1. get authorization to pull/push, $list_repo:pull and push, $target_repo: pull
cross_token=${CROSS_TOKENS[${repo}]}
if [ -z "$cross_token" ]; then
# prompt for authorization
read -p "Please input [email protected]: " username
read -sp "Please input password: " password
# request for access_token
printf "\nAuthorizing ......."
response=$(make_request -u $username:$password "https://auth.docker.io/token?service=registry.docker.io&scope=repository:${list_repo}:pull,push&scope=repository:${repo}:pull")
code=$(get_request_status "$response")
body=$(get_request_body "$response")
if [ 200 -eq $code ]; then
cross_token=$(echo $body | jq -r .token)
CROSS_TOKENS[${repo}]=$cross_token
printf " ${GREEN}Success${NC}\n"
else
printf " ${RED}Failed${NC}\n"
printf "Reason: ${CYAN}$body${NC}\n"
exit 1
fi
fi
# 2. read this_image manifest to create layers list
# these layers shall be mounted to $list_repo
layers_cnt=$(echo "$api_resp" | jq '.layers | length')
let layers_cnt=layers_cnt-1
for layer_i in $(seq 0 $layers_cnt); do
layer_digest=$(echo "$api_resp" | jq -r ".layers[$layer_i].digest")
printf "Mounting layer [$layer_digest] ..."
response=$(curl -s -L -w "HTTPSTATUS:%{http_code}" -X POST -H "Authorization: Bearer ${cross_token}" -H "Content-Length: 0" "$REPO_REGISTRY/$list_repo/blobs/uploads/?mount=$layer_digest&from=$repo")
code=$(get_request_status "$response")
body=$(get_request_body "$response")
if [ 201 -ne $code ]; then
printf " ${RED}Failed${NC}\n"
printf "Reason: ${CYAN}$body${NC}\n"
exit 1
else
printf " ${GREEN}SUCCESS${NC}\n"
fi
done
# 3. upload config content
printf "Mounting blob [${repo}:${tag}] ......"
# load blob info by digest
response=$(curl -s -L -w "HTTPSTATUS:%{http_code}" -X POST -H "Authorization: Bearer ${cross_token}" -H "Content-Length: 0" "$REPO_REGISTRY/$list_repo/blobs/uploads/?mount=$blob_digest&from=$repo")
code=$(get_request_status "$response")
body=$(get_request_body "$response")
if [ 201 -ne $code ]; then
printf " ${RED}Failed${NC}\n"
printf "Reason: ${CYAN}$body${NC}\n"
exit 1
else
printf " ${GREEN}SUCCESS${NC}\n"
fi
# 4. upload reference manifest
printf "Pushing reference manifest: [${repo}:${tag}] ......"
response=$(curl -s -L -w "HTTPSTATUS:%{http_code}" -X PUT "$REPO_REGISTRY/${list_repo}/manifests/${digest}" -H "Authorization: Bearer ${cross_token}" -H "Content-Type: application/vnd.docker.distribution.manifest.list.v2+json" --data-binary "$api_resp")
code=$(get_request_status "$response")
body=$(get_request_body "$response")
if [ 201 -ne $code ]; then
printf " ${RED}Failed${NC}\n"
printf "Reason: ${CYAN}$body${NC}\n"
exit 1
else
printf " ${GREEN}SUCCESS${NC}\n"
fi
fi
# load blob info by digest
api_resp=$(get_image $this_image $token $blob_digest)
# get os/architecture/features... info specified in
# https://docs.docker.com/registry/spec/manifest-v2-2/
os=$(echo $api_resp | jq -r '.os')
architecture=$(echo $api_resp | jq -r '.architecture')
# now add it to list
images_list="$images_list ${content_length},$digest,$os,$architecture"
else
printf " ${RED}FAILED${NC}\n"
printf "[${RED}ERROR${NC}] ${CYAN}$repo:$tag${NC} is not found!\n"
should_fail="YES"
fi
else
# it is a manifest list
printf "[${RED}ERROR${YELLOW}] ${CYAN}$repo:$tag${NC} is not an image.\n"
should_fail="YES"
fi
done
if [ "YES" == $should_fail ]; then
exit 1
fi
[ ! -d ${OUTPUT_DIR} ] && mkdir -p ${OUTPUT_DIR}
# now build manifest list file
manifests_list=$LIST_TEMPLATE
> ${OUTPUT_DIR}/$$-images.json
for image in $images_list; do
image_length=$(echo $image | cut -d ',' -f 1)
image_digest=$(echo $image | cut -d ',' -f 2)
image_os=$(echo $image | cut -d ',' -f 3)
image_architecture=$(echo $image | cut -d ',' -f 4)
# these fields are must options
entry=$(echo -n "$IMAGE_TEMPLATE" | sed -e "s/IMAGE_SIZE/$image_length/" | sed -e "s/IMAGE_DIGEST/$image_digest/")
entry=$(echo -n "$entry" | sed -e "s/ARCHITECTURE/$image_architecture/" | sed -e "s/OS/$image_os/")
entry="$entry,"
echo -e "$entry" >> ${OUTPUT_DIR}/$$-images.json
done
sed -i '$s/,$//' ${OUTPUT_DIR}/$$-images.json
manifests_list=$(echo -n "$manifests_list" | sed -e "/IMAGES/r ${OUTPUT_DIR}/$$-images.json" | sed -e '/IMAGE/d')
echo -n "$manifests_list" > ${OUTPUT_DIR}/${list_name}#manifest.json
mv ${OUTPUT_DIR}/$$-images.json ${OUTPUT_DIR}/${list_name}#images.json
}
process_annotate()
{
if [ "--help" == "$1" ] || [ $# -lt 4 ]; then
show_annotate_help
exit 1
fi
# so far support these fields: os, arch, variant, os-features
# process arguments
local i=0
while (( "$#" )); do
case "$1" in
-*|--*)
opt=$(echo $1 | sed -e 's/^-*//')
case "$opt" in
# save value
os|variant)
OPTIONS["$opt"]="$2"
shift
;;
arch)
OPTIONS["architecture"]="$2"
shift
;;
os-features)
# string slice
value=$(echo "$2" | sed -e 's/\,/\"\,\"/g')
OPTIONS["os.features"]="[\"$value\"]"
shift
;;
# default is to mark the option selected-"Y"
*)
OPTIONS["$opt"]="Y"
;;
esac
;;
*)
MANIFESTS[$i]=$1
let i=i+1
;;
esac
shift
done
should_fail="NO"
# get manifests list content
# 1. from local cache
# 2. from remote registry
list_repo=$(echo ${MANIFESTS[0]} | cut -d ':' -f 1)
list_tag=$(echo ${MANIFESTS[0]} | cut -d ':' -f 2)
list_name="$(echo $list_repo | sed -e 's|/|\#|')#$list_tag"
if [ -f ${OUTPUT_DIR}/${list_name}#manifest.json ]; then
list_content=$(cat ${OUTPUT_DIR}/${list_name}#manifest.json)
else
printf "Cannot find ${CYAN}[${MANIFESTS[0]}]${NC} in cache.\n"
read -p "Download to proceed? (Y/N) : " choice
[ "N" == "$choice" ] && exit 1
# load manifests-list access token
target=${MANIFESTS[0]}
printf "Reading: [${CYAN}$target${NC}]\n"
repo=$(echo "$target" | cut -d ':' -f 1)
token=${TOKENS[${repo}]}
if [ -z "$token" ]; then
printf "\tRequesting access token ..."
token=$(get_token $repo)
TOKENS[${repo}]=$token
printf " ${GREEN}Done${NC}\n"
fi
# read from registry
printf "\tLoading manifests list ..."
list_content=$(get_manifests_list $target $token)
printf " ${GREEN}Done${NC}\n"
fi
list_count=$(echo "$list_content" | jq '.manifests | length')
if [ $list_count -gt 0 ]; then
# get listed images manifest
for ((i=1; i <${#MANIFESTS[@]}; i++)); do
target=${MANIFESTS[$i]}
# read digest associates with given target
# search target manifest-digest in list
# append/modify fields if target exists
# get token for this repo
repo=$(echo "$target" | cut -d ':' -f 1)
token=${TOKENS[${repo}]}
if [ -z "$token" ]; then
token=$(get_token $repo)
TOKENS[${repo}]=$token
fi
# check if specified item is a manifest list.
api_resp=$(get_manifests_list $target $token)
list_count=$(echo "$api_resp" | jq '.manifests | length')
if [ $list_count -gt 0 ]; then
printf "[${RED}ERROR${NC}] [${CYAN}$target${NC}] is not an image\n"
exit 1
fi
# get digest of target manifest
get_manifest $target $token "-I -D /tmp/$$.txt" > /dev/null
header=$(cat /tmp/$$.txt)
content_length=$(echo "$header" | grep 'Content-Length' | tr -d ' \n\r' | cut -d ':' -f 2)
digest=$(echo "$header" | grep 'Docker-Content-Digest' | tr -d '\n\r' | cut -d ' ' -f 2)
rm /tmp/$$.txt
# search this digest in $list_content
found=$(echo $list_content | grep "$digest" | wc -l)
if [ 0 -eq $found ]; then
echo "[ERROR] Specified [$target] is not in ${MANIFESTS[0]}"
exit 1
else
# add fields
export MS_DIGEST=$digest
for this_field in architecture variant os "os.features"; do
if [ ! -z ${OPTIONS[${this_field}]} ]; then
export FIELD=${this_field}
export VALUE="${OPTIONS[${this_field}]}"
if [ "$FIELD" == "os.features" ]; then
list_content=$(echo -E "$list_content" | jq '(.manifests[] | select(.digest == "'$MS_DIGEST'").platform."'$FIELD'") = '$VALUE'')
else
list_content=$(echo -E "$list_content" | jq '(.manifests[] | select(.digest == "'$MS_DIGEST'").platform."'$FIELD'") = "'$VALUE'"')
fi
unset FIELD
unset VALUE
fi
done
unset MS_DIGEST
fi
done
# save to cache
echo "$list_content" | jq . -M > ${OUTPUT_DIR}/${list_name}#manifest.json
else
printf "[${RED}ERROR${NC}] [${CYAN}$target${NC}] is not a manifest list\n"
should_fail="YES"
fi
}
process_inspect()
{
if [ "--help" == "$1" ] || [ $# -lt 1 ]; then
show_inspect_help
exit 1
fi
# process arguments
local i=0
while (( "$#" )); do
case "$1" in
-*|--*)
opt=$(echo $1 | sed -e 's/^-*//')
OPTIONS["$opt"]="Y"
;;
*)
MANIFESTS[$i]=$1
let i=i+1
;;
esac
shift
done
if [ "Y" == "${OPTIONS[insecure]}" ]; then
# add -k option to curl
CURL_OPT="${CURL_OPT} -k"
fi
# check token
target=${MANIFESTS[0]}
repo=$(echo "$target" | cut -d ':' -f 1)
token=${TOKENS[${repo}]}
if [ -z "$token" ]; then
token=$(get_token $repo)
TOKENS[${repo}]=$token
fi
# get manifests list
api_resp=$(get_manifests_list $target $token)
list_count=$(echo -E "$api_resp" | jq '.manifests | length')
if [ $list_count -eq 0 ]; then
# get image manifest
api_resp=$(get_manifest $target $token)
fi
echo $api_resp | jq
}
process_push()
{
echo $#
if [ "--help" == "$1" ] || [ $# -lt 1 ]; then
show_push_help
exit 1
fi
# check options
local i=0
while (( "$#" )); do
case "$1" in
-*|--*)
opt=$(echo $1 | sed -e 's/^-*//')
OPTIONS["$opt"]="Y"
;;
*)
MANIFESTS[$i]=$1
let i=i+1
;;
esac
shift
done
if [ "Y" == "${OPTIONS[insecure]}" ]; then
# add -k option to curl
CURL_OPT="${CURL_OPT} -k"
fi
# check if manifests-list has been created or not
repo=$(echo "${MANIFESTS[0]}" | cut -d ':' -f 1)
tag=$(echo "${MANIFESTS[0]}" | cut -d ':' -f 2)
manifests_file="${OUTPUT_DIR}/$(echo $repo | sed -e 's|/|\#|')#$tag#manifest.json"
if [ ! -f ${manifests_file} ]; then
printf "${RED}[ERROR]${NC} Couldn't find specified manifest ${CYAN}[$repo:$tag]${NC}\n"
exit 1
fi
# prompt for authorization
read -p "Please input [email protected]: " username
read -sp "Please input password: " password
# request for access_token
printf "\nAuthorizing ......."
response=$(make_request -u $username:$password "https://auth.docker.io/token?service=registry.docker.io&scope=repository:${repo}:pull,push")
code=$(get_request_status "$response")
body=$(get_request_body "$response")
#ret=$(curl -s -u $username:$password "https://auth.docker.io/token?service=registry.docker.io&scope=repository:${repo}:pull,push")
if [ 200 -eq $code ]; then
access_token=$(echo $body | jq -r .token)
printf " ${GREEN}Success${NC}\n"
else
printf " ${RED}Failed${NC}\n"
printf "Reason: ${CYAN}$body${NC}\n"
exit 1
fi
# put manifests file
printf "Uploading ......."
response=$(curl -s -L -w "HTTPSTATUS:%{http_code}" -X PUT "$REPO_REGISTRY/${repo}/manifests/${tag}" -H "Authorization: Bearer ${access_token}" -H "Content-Type: application/vnd.docker.distribution.manifest.list.v2+json" --data-binary @${manifests_file})
code=$(get_request_status "$response")
body=$(get_request_body "$response")
if [ 201 -eq $code ]; then
printf " ${GREEN}Success${NC}\n"
else
printf " ${RED}Failed${NC}\n"
printf "Reason: ${CYAN}$body${NC}\n"
fi
# should manifests-list be purged?
if [ "Y" == "${OPTIONS[purge]}" ]; then
printf "Delete manifest json file\n"
fi
}
if [ $# -lt 1 ]; then
showhelp
exit 1
fi
cmd=$1
shift
case $cmd in
create)
process_create $@
;;
annotate)
process_annotate $@
;;
inspect)
process_inspect $@
;;
push)
process_push $@
;;
*)
showhelp
;;
esac