-
Notifications
You must be signed in to change notification settings - Fork 8
/
out
executable file
·107 lines (80 loc) · 2.5 KB
/
out
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
#!/bin/bash
set -e -u
exec 3>&1
exec 1>&2
source $(dirname $0)/common.sh
source=$1
if [ -z "$source" ]; then
echo "usage: $0 <path/to/source>"
exit 1
fi
PATH=/usr/local/bin:$PATH
payload=$(mktemp /tmp/resource-in.XXXXXX)
cat > $payload <&0
cd $source
insecure_registries=$(jq -r '.source.insecure_registries // [] | join(" ")' < $payload)
registry_mirror=$(jq -r '.source.registry_mirror // ""' < $payload)
username=$(jq -r '.source.username // ""' < $payload)
password=$(jq -r '.source.password // ""' < $payload)
repository=$(jq -r '.source.repository // ""' < $payload)
tag_source=$(jq -r '.source.tag // "latest"' < $payload)
tag_params=$(jq -r '.params.tag_file // ""' < $payload)
# [docker-image-resource] for backwards compatibility, check `tag` if `tag_file` is empty
if [ -z "$tag_params" ]; then
tag_params=$(jq -r '.params.tag // ""' < $payload)
fi
tag_prefix=$(jq -r '.params.tag_prefix // ""' < $payload)
tag_name=""
if [ -n "$tag_params" ]; then
if [ ! -f "$tag_params" ]; then
echo "tag file '$tag_params' does not exist"
exit 1
fi
tag_name="${tag_prefix}$(cat $tag_params)"
else
tag_name="$tag_source"
fi
ca_certs=$(jq -r '.source.ca_certs // []' < $payload)
client_certs=$(jq -r '.source.client_certs // []' < $payload)
max_concurrent_downloads=$(jq -r '.source.max_concurrent_downloads // 3' < $payload)
max_concurrent_uploads=$(jq -r '.source.max_concurrent_uploads // 3' < $payload)
if private_registry "$repository" ; then
registry="$(extract_registry "$repository")"
else
registry=
fi
certs_to_file "$ca_certs"
set_client_certs "$client_certs"
sanitize_cgroups
start_docker \
"$insecure_registries" \
"$registry_mirror"
log_in "$username" "$password" "$registry"
build=$(jq -r '.params.build // "./"' < $payload)
stack=$(jq -r '.params.stack // ""' < $payload)
env_file=$(jq -r '.params.env_file // ""' < $payload)
builder=$(jq -r '.params.builder // ""' < $payload)
if [ ! -z $builder ]; then
pack set-default-builder $builder
fi
if [ ! -z $stack ]; then
pack set-default-stack $stack
fi
pack_args=""
if [ ! -z $env_file ]; then
pack_args="$pack_args --env-file $env_file"
fi
pack build $repository:$tag_name $pack_args --path $build
docker push $repository:$tag_name
inspect_output=$(docker inspect $repository:$tag_name)
jq -n "{
version: {
digest: \"$(echo $inspect_output | jq '.[].RepoDigests[0]' | jq -r 'split("@")[1]')\"
},
metadata: [
{
name: \"$repository:$tag_name\",
id: \"$(echo $inspect_output | jq -r '.[].Id')\",
}
]
}" >&3