File tree 5 files changed +48
-8
lines changed
5 files changed +48
-8
lines changed Original file line number Diff line number Diff line change @@ -44,7 +44,9 @@ module "ecr_repo_image" {
44
44
45
45
## NOTES
46
46
47
- * This module needs ` curl ` and ` jq ` on ` PATH ` .
47
+ * This module only works under Linux.
48
+ * This module needs ` curl ` and ` jq ` on ` PATH ` . If ` jq ` are missing, it will fetch
49
+ and install ` jq 1.7.1 ` locally for the appropriate architecture.
48
50
49
51
## EXAMPLES
50
52
Original file line number Diff line number Diff line change 1
1
#! /usr/bin/env bash
2
+ set -eu
2
3
3
4
curl_with_auth_header () {
4
5
auth_params=()
@@ -43,3 +44,13 @@ check_vars() {
43
44
fi
44
45
return 0
45
46
}
47
+
48
+ install_jq () {
49
+ cd " ${1:? Install directory not passed as $1 to install_jq} "
50
+ arch=$( uname -m)
51
+ case $arch in
52
+ x86_64) arch=" amd64" ;;
53
+ esac
54
+ curl -fsSLo jq " https://github.com/jqlang/jq/releases/download/jq-1.7.1/jq-linux-$arch "
55
+ chmod 0755 jq
56
+ }
Original file line number Diff line number Diff line change @@ -37,14 +37,14 @@ _fetch_manifest() {
37
37
if [ " $image_hash " = " null" ]; then
38
38
available=$( jq -r ' . | map(.platform.architecture) | join(", ")' <<< " $manifests" )
39
39
printf " Architecture %s not found. Available options are: %s\n" " $IMAGE_ARCH " " $available " >&2
40
- exit 2
40
+ exit 3
41
41
else
42
42
IMAGE_TAG=" $image_hash " _fetch_manifest
43
43
fi
44
44
else
45
45
echo " Unknown manifest format: " >&2
46
46
echo " $curl_output " >&2
47
- exit 1
47
+ exit 3
48
48
fi
49
49
echo ' _fetch_manifest: complete' >&2
50
50
}
@@ -72,7 +72,7 @@ download_image() {
72
72
if [[ -z " $config_digest " || " $config_digest " == ' null' ]]; then
73
73
echo ' download_image: failed to parse config_digest from manifest' >&2
74
74
cat " $manifest_file_path " >&2
75
- return 1
75
+ return 3
76
76
fi
77
77
78
78
config_file_path=" $dir_path /config.json"
Original file line number Diff line number Diff line change @@ -17,6 +17,14 @@ set -eu
17
17
# PUSH_REPO_NAME='my-repo' \
18
18
# PUSH_IMAGE_TAG='latest' \
19
19
# ./pull_then_push.sh
20
+ #
21
+ # Exit codes:
22
+ # * 1 - Undefined input variable
23
+ # * 2 - Missing tools
24
+ # * 3 - Pull failures
25
+ # * 4, 5 - Push failures
26
+ # * Other codes - curl failures or unexpected error
27
+ #
20
28
# #
21
29
22
30
_dir_path () {
@@ -40,6 +48,25 @@ if [ -z ${PUSH_CURL_AUTH_HEADER+x} ]; then
40
48
exit 1
41
49
fi
42
50
51
+ # Check tools
52
+ if ! command -v curl & > /dev/null; then
53
+ echo " curl not found" >&2
54
+ exit 2
55
+ fi
56
+ if ! command -v jq & > /dev/null; then
57
+ echo " jq not found, trying to install..." >&2
58
+ bin_dir=" $PULL_DOWNLOAD_DIR_PATH /bin"
59
+ mkdir -p " $bin_dir "
60
+ bin_dir=$( readlink -f " $bin_dir " )
61
+ if install_jq " $bin_dir " ; then
62
+ export PATH=" $bin_dir :$PATH "
63
+ echo " Installed $( jq --version) ." >&2
64
+ else
65
+ echo " jq not found and could not be installed" >&2
66
+ exit 2
67
+ fi
68
+ fi
69
+
43
70
# Pull image
44
71
export CURL_AUTH_HEADER=" $PULL_CURL_AUTH_HEADER "
45
72
manifest_path=$(
Original file line number Diff line number Diff line change @@ -24,13 +24,13 @@ check_vars REPO_URL IMAGE_TAG LAYER_PATHS CONFIG_PATH MANIFEST_PATH
24
24
echo " $LAYER_PATHS " | while read -r layer_path ; do
25
25
if [[ ! -f " $layer_path " ]]; then
26
26
echo " No file exists at layer_path of '$layer_path '" >&2
27
- exit 1
27
+ exit 4
28
28
fi
29
29
done
30
30
31
31
if [[ ! -f " $CONFIG_PATH " ]]; then
32
32
echo " No file exists at CONFIG_PATH='$CONFIG_PATH '" >&2
33
- exit 1
33
+ exit 4
34
34
fi
35
35
36
36
@@ -65,7 +65,7 @@ _initiate_upload() {
65
65
)
66
66
if [[ -z " $location " ]]; then
67
67
echo ' _initiate_upload: Failed to parse Location from curl_output' >&2
68
- return 1
68
+ return 5
69
69
fi
70
70
71
71
echo ' _initiate_upload: complete' >&2
@@ -95,7 +95,7 @@ _patch_layer() {
95
95
)
96
96
if [[ -z " $location " ]]; then
97
97
echo ' _patch_layer: Failed to parse location from curl_output' >&2
98
- return 1
98
+ return 5
99
99
fi
100
100
101
101
echo ' _patch_layer: complete' >&2
You can’t perform that action at this time.
0 commit comments