Package mobymask-v2 stack web-apps similar to laconic-console app #310
@ -21,7 +21,6 @@ services:
|
||||
- ./wait-for-it.sh -h ${CERC_WATCHER_HOST:-$${DEFAULT_CERC_WATCHER_HOST}} -p ${CERC_WATCHER_PORT:-$${DEFAULT_CERC_WATCHER_PORT}} -s -t 0 -- ./mobymask-app-start.sh
|
||||
volumes:
|
||||
- ../config/wait-for-it.sh:/app/wait-for-it.sh
|
||||
- ../config/watcher-mobymask-v2/config.yml:/config/config.yml
|
||||
- ../config/watcher-mobymask-v2/mobymask-app-start.sh:/app/mobymask-app-start.sh
|
||||
- peers_ids:/peers
|
||||
- mobymask_deployment:/server
|
||||
|
@ -1,9 +0,0 @@
|
||||
# Config for mobymask-app running with mobymask-v2-watcher
|
||||
|
||||
address:
|
||||
|
||||
chainId:
|
||||
|
||||
relayNodes:
|
||||
|
||||
watcherUrl:
|
@ -28,14 +28,10 @@ else
|
||||
echo "Taking deployed contract details from env"
|
||||
fi
|
||||
|
||||
# Use yq to replace the values in the YAML file with environment variables
|
||||
yq e \
|
||||
--arg deployed_contract "$CERC_DEPLOYED_CONTRACT" \
|
||||
--arg watcher_url "$CERC_APP_WATCHER_URL" \
|
||||
--arg chain_id "$CERC_CHAIN_ID" \
|
||||
--argjson relay_nodes "$CERC_RELAY_NODES" \
|
||||
'.address = $deployed_contract | .chainId = $chain_id | .relayNodes = $relay_nodes | .watcherUrl = $watcher_url' \
|
||||
/config/config-template.yml \
|
||||
| envsubst > /config/config.yml
|
||||
# Use yq to create config.yml with environment variables
|
||||
yq -n ".address = env(CERC_DEPLOYED_CONTRACT)" > /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 ".relayNodes = env(CERC_RELAY_NODES)" -i /config/config.yml
|
||||
|
||||
sh /scripts/mobymask-app-start.sh
|
||||
sh /scripts/start-serving-app.sh
|
||||
|
@ -42,7 +42,7 @@ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
|
||||
COPY --from=docker.io/mikefarah/yq:latest /usr/bin/yq /usr/local/bin/yq
|
||||
|
||||
RUN mkdir -p /scripts
|
||||
COPY ../apply-webapp-config.sh /scripts
|
||||
COPY ./apply-webapp-config.sh /scripts
|
||||
COPY ./start-serving-app.sh /scripts
|
||||
|
||||
# [Optional] Uncomment if you want to install more global node modules
|
||||
|
@ -4,22 +4,29 @@ ARG REPO_DIR
|
||||
|
||||
RUN apk --update --no-cache add make git jq bash
|
||||
|
||||
# We do this to get a yq binary from the published container, for the correct architecture we're building here
|
||||
COPY --from=docker.io/mikefarah/yq:latest /usr/bin/yq /usr/local/bin/yq
|
||||
|
||||
RUN mkdir -p /scripts
|
||||
COPY ../apply-webapp-config.sh /scripts
|
||||
COPY ./apply-webapp-config.sh /scripts
|
||||
COPY ./start-serving-app.sh /scripts
|
||||
|
||||
RUN mkdir -p /config
|
||||
|
||||
# Install simple web server for now (use nginx perhaps later)
|
||||
RUN yarn global add http-server
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY ${REPO_DIR} .
|
||||
# TODO: Workaround copying local repo outside docker build context
|
||||
# Would not be required if publishing package for web-app build
|
||||
RUN git clone --branch laconic https://github.com/cerc-io/mobymask-ui.git .
|
||||
|
||||
COPY ./mobymask-config.json /src/config.json
|
||||
|
||||
RUN echo "Building mobymask-ui" && \
|
||||
npm install && \
|
||||
REACT_APP_WATCHER_URI="MOBYMASK_HOSTED_CONFIG_watcherUrl/graphql" npm run build
|
||||
RUN echo "Building mobymask-ui"
|
||||
RUN npm install
|
||||
RUN REACT_APP_WATCHER_URI="MOBYMASK_HOSTED_CONFIG_watcherUrl/graphql" npm run build
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
|
35
app/data/container-build/cerc-mobymask-ui/apply-webapp-config.sh
Executable file
35
app/data/container-build/cerc-mobymask-ui/apply-webapp-config.sh
Executable file
@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env bash
|
||||
if [ -n "$CERC_SCRIPT_DEBUG" ]; then
|
||||
set -x
|
||||
fi
|
||||
if [[ $# -ne 2 ]]; then
|
||||
echo "Illegal number of parameters" >&2
|
||||
exit 1
|
||||
fi
|
||||
config_file_name=$1
|
||||
webapp_files_dir=$2
|
||||
config_prefix=$3
|
||||
if ![[ -f ${config_file_name} ]]; then
|
||||
echo "Config file ${config_file_name} does not exist" >&2
|
||||
exit 1
|
||||
fi
|
||||
if ![[ -d ${webapp_files_dir} ]]; then
|
||||
echo "Webapp directory ${webapp_files_dir} does not exist" >&2
|
||||
exit 1
|
||||
fi
|
||||
# First some magic using yq to translate our yaml config file into an array of key value pairs like:
|
||||
# ${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}_/" )
|
||||
declare -p config_kv_pair_array
|
||||
# Then iterate over that kv array making the template substitution in our web app files
|
||||
for kv_pair_string in "${config_kv_pair_array[@]}"
|
||||
do
|
||||
kv_pair=(${kv_pair_string//=/ })
|
||||
template_string_to_replace=${kv_pair[0]}
|
||||
template_value_to_substitute=${kv_pair[1]}
|
||||
# Run find and sed to do the substitution of one variable over all files
|
||||
# See: https://stackoverflow.com/a/21479607/1701505
|
||||
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' {} +
|
||||
done
|
@ -6,5 +6,4 @@ source ${CERC_CONTAINER_BASE_DIR}/build-base.sh
|
||||
# See: https://stackoverflow.com/a/246128/1701505
|
||||
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
||||
|
||||
docker build -t cerc/mobymask-ui:local -f ${SCRIPT_DIR}/Dockerfile \
|
||||
--build-arg REPO_DIR=${CERC_REPO_BASE_DIR}/mobymask-ui ${SCRIPT_DIR}
|
||||
docker build -t cerc/mobymask-ui:local -f ${SCRIPT_DIR}/Dockerfile ${SCRIPT_DIR}
|
||||
|
Loading…
Reference in New Issue
Block a user