Skip to content

Commit 29e5823

Browse files
authored
support build environment variable (#2257)
* support build environment variable * filter environment variables by prefix "USER_ENV_" * refine user env prefix
1 parent 2c7a5f0 commit 29e5823

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

builders/container-apps-internal-registry-demo/Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ RUN chmod u+x /startup-script.sh
4949
RUN touch /usr/local/share/ca-certificates/internalregistry.crt \
5050
&& chmod 666 /usr/local/share/ca-certificates/internalregistry.crt
5151
RUN chown ${CNB_USER_ID}:${CNB_GROUP_ID} /etc/ssl/certs/ \
52-
&& chown ${CNB_USER_ID}:${CNB_GROUP_ID} /usr/local/share/ca-certificates/
52+
&& chown ${CNB_USER_ID}:${CNB_GROUP_ID} /usr/local/share/ca-certificates/ \
53+
&& chown ${CNB_USER_ID}:${CNB_GROUP_ID} /platform/env
54+
5355

5456
# Give cnb user permission to /cnb/extensions directory
5557
RUN mkdir -p ${CNB_EXTENSIONS_DIR} && \

builders/container-apps-internal-registry-demo/startup-script.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,21 @@ temp_app_source_dir="/tmp/appsource"
1313
temp_app_source_path="$temp_app_source_dir/$FILE_UPLOAD_BLOB_NAME"
1414
mkdir $temp_app_source_dir
1515

16+
# List all the environment variables and filter the environment variable with prefix "ACA_CLOUD_BUILD_USER_ENV_", then write them to folder "/platform/env",
17+
# file name is the environment variable name without prefix, file content is the environment variable value.
18+
build_env_dir="/platform/env"
19+
env | grep -E '^ACA_CLOUD_BUILD_USER_ENV_' | while read -r line; do
20+
key=$(echo "$line" | cut -d= -f1)
21+
value=$(echo "$line" | cut -d= -f2-)
22+
filename="${key#ACA_CLOUD_BUILD_USER_ENV_}"
23+
echo "$value" > "$build_env_dir/$filename"
24+
done
25+
26+
# write environment variable CORRELATION_ID to folder "/platform/env",
27+
if [ -n "$CORRELATION_ID" ]; then
28+
echo "$CORRELATION_ID" > "$build_env_dir/CORRELATION_ID"
29+
fi
30+
1631
while [[ ! -f "$temp_app_source_path" || ! "$(file $temp_app_source_path)" =~ "compressed data" ]]
1732
do
1833
echo "Waiting for app source to be uploaded. Please upload the app source to the endpoint specified in the Build resource's 'uploadEndpoint' property."

0 commit comments

Comments
 (0)