Replace variables in built web-app files
This commit is contained in:
parent
85eeb2e99f
commit
068d7ffc32
@ -1,4 +1,4 @@
|
|||||||
#!/bin/sh
|
#!/usr/bin/env bash
|
||||||
set -e
|
set -e
|
||||||
if [ -n "$CERC_SCRIPT_DEBUG" ]; then
|
if [ -n "$CERC_SCRIPT_DEBUG" ]; then
|
||||||
set -x
|
set -x
|
||||||
@ -32,6 +32,6 @@ fi
|
|||||||
yq -n ".address = env(CERC_DEPLOYED_CONTRACT)" > /config/config.yml
|
yq -n ".address = env(CERC_DEPLOYED_CONTRACT)" > /config/config.yml
|
||||||
yq ".watcherUrl = env(CERC_APP_WATCHER_URL)" -i /config/config.yml
|
yq ".watcherUrl = env(CERC_APP_WATCHER_URL)" -i /config/config.yml
|
||||||
yq ".chainId = env(CERC_CHAIN_ID)" -i /config/config.yml
|
yq ".chainId = env(CERC_CHAIN_ID)" -i /config/config.yml
|
||||||
yq ".relayNodes = env(CERC_RELAY_NODES)" -i /config/config.yml
|
yq ".relayNodes = strenv(CERC_RELAY_NODES)" -i /config/config.yml
|
||||||
|
|
||||||
sh /scripts/start-serving-app.sh
|
/scripts/start-serving-app.sh
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
if [ -n "$CERC_SCRIPT_DEBUG" ]; then
|
if [ -n "$CERC_SCRIPT_DEBUG" ]; then
|
||||||
set -x
|
set -x
|
||||||
fi
|
fi
|
||||||
if [[ $# -ne 2 ]]; then
|
if [[ $# -ne 3 ]]; then
|
||||||
echo "Illegal number of parameters" >&2
|
echo "Illegal number of parameters" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
@ -22,7 +22,7 @@ WORKDIR /app
|
|||||||
# Would not be required if publishing package for web-app build
|
# Would not be required if publishing package for web-app build
|
||||||
RUN git clone --branch laconic https://github.com/cerc-io/mobymask-ui.git .
|
RUN git clone --branch laconic https://github.com/cerc-io/mobymask-ui.git .
|
||||||
|
|
||||||
COPY ./mobymask-config.json /src/config.json
|
COPY ./mobymask-config.json /app/src/config.json
|
||||||
|
|
||||||
RUN echo "Building mobymask-ui"
|
RUN echo "Building mobymask-ui"
|
||||||
RUN npm install
|
RUN npm install
|
||||||
|
@ -2,24 +2,25 @@
|
|||||||
if [ -n "$CERC_SCRIPT_DEBUG" ]; then
|
if [ -n "$CERC_SCRIPT_DEBUG" ]; then
|
||||||
set -x
|
set -x
|
||||||
fi
|
fi
|
||||||
if [[ $# -ne 2 ]]; then
|
if [[ $# -ne 3 ]]; then
|
||||||
echo "Illegal number of parameters" >&2
|
echo "Illegal number of parameters" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
config_file_name=$1
|
config_file_name=$1
|
||||||
webapp_files_dir=$2
|
webapp_files_dir=$2
|
||||||
config_prefix=$3
|
config_prefix=$3
|
||||||
if ![[ -f ${config_file_name} ]]; then
|
if ! [[ -f ${config_file_name} ]]; then
|
||||||
echo "Config file ${config_file_name} does not exist" >&2
|
echo "Config file ${config_file_name} does not exist" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
if ![[ -d ${webapp_files_dir} ]]; then
|
if ! [[ -d ${webapp_files_dir} ]]; then
|
||||||
echo "Webapp directory ${webapp_files_dir} does not exist" >&2
|
echo "Webapp directory ${webapp_files_dir} does not exist" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
# First some magic using yq to translate our yaml config file into an array of key value pairs like:
|
# First some magic using sed to translate our yaml config file into an array of key value pairs like:
|
||||||
# ${config_prefix}<path-through-objects>=<value>
|
# ${config_prefix}<path-through-objects>=<value>
|
||||||
readarray -t config_kv_pair_array < <( yq '.. | select(length > 2) | ([path | join("_"), .] | join("=") )' ${config_file_name} | sed "s/^/${config_prefix}_/" )
|
# sed "s/'//g" is used to remove single quote for relayNodes value
|
||||||
|
readarray -t config_kv_pair_array < <( sed -E 's/([^:]+):\s*(.*)/\1=\2/g' ${config_file_name} | sed "s/'//g" | sed "s/^/${config_prefix}_/" )
|
||||||
declare -p config_kv_pair_array
|
declare -p config_kv_pair_array
|
||||||
# Then iterate over that kv array making the template substitution in our web app files
|
# Then iterate over that kv array making the template substitution in our web app files
|
||||||
for kv_pair_string in "${config_kv_pair_array[@]}"
|
for kv_pair_string in "${config_kv_pair_array[@]}"
|
||||||
@ -30,6 +31,12 @@ do
|
|||||||
# Run find and sed to do the substitution of one variable over all files
|
# Run find and sed to do the substitution of one variable over all files
|
||||||
# See: https://stackoverflow.com/a/21479607/1701505
|
# See: https://stackoverflow.com/a/21479607/1701505
|
||||||
echo "Substituting: ${template_string_to_replace} = ${template_value_to_substitute}"
|
echo "Substituting: ${template_string_to_replace} = ${template_value_to_substitute}"
|
||||||
# Note: we do not escape our strings, on the expectation they do not container the '#' char.
|
|
||||||
find ${webapp_files_dir} -type f -exec sed -i 's#'${template_string_to_replace}'#'${template_value_to_substitute}'#g' {} +
|
# TODO: Pass keys to be replaced without double quotes
|
||||||
|
if [[ "$template_string_to_replace" == "${config_prefix}_relayNodes" ]]; then
|
||||||
|
find ${webapp_files_dir} -type f -exec sed -i 's#"'"${template_string_to_replace}"'"#'"${template_value_to_substitute}"'#g' {} +
|
||||||
|
else
|
||||||
|
# Note: we do not escape our strings, on the expectation they do not container the '#' char.
|
||||||
|
find ${webapp_files_dir} -type f -exec sed -i 's#'${template_string_to_replace}'#'${template_value_to_substitute}'#g' {} +
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
Loading…
Reference in New Issue
Block a user