-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New ENV command for environment variables
ENV can be either used to pass environment variables to be used within the image or be substituted beforehand. This allows another kind of variables within a Pifile.
- Loading branch information
Showing
7 changed files
with
115 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# ENV_VARS is an associative array of environment variables, set via ENV. | ||
declare -A ENV_VARS=() | ||
|
||
# env_vars_set saves an environment variable mapping. | ||
# Usage: env_vars_set KEY VALUE | ||
env_vars_set() { | ||
ENV_VARS["${1}"]="${2}" | ||
} | ||
|
||
# env_vars_del removes an environment variable mapping. | ||
# Usage: env_vars_del KEY | ||
env_vars_del() { | ||
unset ENV_VARS["${1}"] | ||
} | ||
|
||
# env_vars_export_cmd creates a single "export K1=V1 K2=V2 ...;" output. If no | ||
# values are present, an empty output is generated. | ||
# Usage: env_vars_export_cmd | ||
env_vars_export_cmd() { | ||
if [[ "${#ENV_VARS[@]}" -eq "0" ]]; then | ||
echo "" | ||
return | ||
fi | ||
|
||
declare -a pairs | ||
|
||
for key in "${!ENV_VARS[@]}"; do | ||
pairs+=("${key}=${ENV_VARS["$key"]}") | ||
done | ||
|
||
echo "export ${pairs[*]};" | ||
} | ||
|
||
# env_vars_subst replaces all previously defined environment variables in the | ||
# form of "@@ENV@@" by its value. | ||
# Usage: env_vars_subst echo hello @@USER_NAME@@ | ||
env_vars_subst() { | ||
for part in "${@}"; do | ||
for key in "${!ENV_VARS[@]}"; do | ||
part="${part/"@@${key}@@"/${ENV_VARS["$key"]}}" | ||
done | ||
printf '%s ' "$part" | ||
done | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,10 @@ WORKDIR() { | |
: | ||
} | ||
|
||
ENV() { | ||
: | ||
} | ||
|
||
RUN() { | ||
: | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters