Skip to content

Commit 9ecbd8c

Browse files
committed
feat(config): add typed values
1 parent 85b1bcc commit 9ecbd8c

1 file changed

Lines changed: 32 additions & 12 deletions

File tree

rootfs/imagebuilder/build

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,26 @@ function waiting_process {
3636
done
3737
}
3838

39+
function write_build_env {
40+
local envfile dryccfile command config items i
41+
envfile=$1
42+
dryccfile=$2
43+
if [[ -z "$3" ]]; then
44+
command=".build.config"
45+
else
46+
command=".build.config.${3}"
47+
fi
48+
if [[ -f "$dryccfile" ]]; then
49+
config=$(cat < "$dryccfile" | yq "$command" -o json)
50+
if [[ $config != null ]]; then
51+
mapfile -t items < <(echo "$config" | jq -c -r 'to_entries[] | (.key, .value)')
52+
for ((i=0; i<"${#items[@]}"; i=i+2)); do
53+
echo "${items[i]}=${items[i+1]}" >> "${envfile}"
54+
done
55+
fi
56+
fi
57+
}
58+
3959
CONTAINERS_CONFIG_DIR="${HOME}"/.config/containers
4060
mkdir -p "${CONTAINERS_CONFIG_DIR}"
4161
from_registries_file="/etc/imagebuilder/registries.conf"
@@ -96,19 +116,10 @@ fi
96116
envfile="${HOME}"/.config/build-env
97117
dryccfile="drycc.yaml"
98118
# create build-env
99-
touch "${envfile}"
119+
echo "" > "${envfile}"
100120
if [[ -f .build-env ]] ; then
101121
cat .build-env >> "${envfile}"
102122
fi
103-
if [[ -f "$dryccfile" ]]; then
104-
config=$(cat < "$dryccfile" | yq .build.config -o json)
105-
if [[ $config != null ]]; then
106-
mapfile -t items < <(echo "$config" | jq -c -r 'to_entries[] | (.key, .value)')
107-
for ((i=0; i<"${#items[@]}"; i=i+2)); do
108-
echo "${items[i]}=${items[i+1]}" >> "${envfile}"
109-
done
110-
fi
111-
fi
112123

113124
# Building
114125
if [[ "${DRYCC_STACK}" == "container" ]] ; then
@@ -118,6 +129,8 @@ if [[ "${DRYCC_STACK}" == "container" ]] ; then
118129
docker=$(cat < "$dryccfile" | yq .build.docker -o json)
119130
if [[ $docker != null ]]; then
120131
mapfile -t builds < <(echo "$docker" | jq -c -r 'to_entries[] | (.key, .value)')
132+
else
133+
write_build_env "$envfile" "$dryccfile"
121134
fi
122135
fi
123136
for ((i=0; i<"${#builds[@]}"; i=i+2)); do
@@ -134,6 +147,13 @@ if [[ "${DRYCC_STACK}" == "container" ]] ; then
134147
do
135148
podman_build="$podman_build --build-arg $build_arg"
136149
done
150+
typed_envfile="${HOME}/.config/build-env-${procfile_type}"
151+
echo "" > "$typed_envfile"
152+
write_build_env "$typed_envfile" "$dryccfile" "$procfile_type"
153+
for build_arg in $( < "${typed_envfile}" )
154+
do
155+
podman_build="$podman_build --build-arg $build_arg"
156+
done
137157
$podman_build
138158
$podman_push
139159
done
@@ -150,7 +170,7 @@ else
150170
image_base_name=$(echo "${IMAGE_NAME}" | sed -s "s#:${image_tag}##g")
151171
image_cache_name="${image_base_name}":cache
152172
image_latest_name="${image_base_name}":latest
153-
173+
write_build_env "$envfile" "$dryccfile"
154174
pack_build="pack build ${IMAGE_NAME} \
155175
--builder ${pack_builder} \
156176
--lifecycle-image ${pack_builder} \
@@ -170,4 +190,4 @@ else
170190
pack_build="$pack_build --clear-cache"
171191
fi
172192
$pack_build
173-
fi
193+
fi

0 commit comments

Comments
 (0)