diff --git a/app/data/container-build/cerc-laconic-console-host/Dockerfile b/app/data/container-build/cerc-laconic-console-host/Dockerfile index de477a8c..fe5e50ae 100644 --- a/app/data/container-build/cerc-laconic-console-host/Dockerfile +++ b/app/data/container-build/cerc-laconic-console-host/Dockerfile @@ -36,6 +36,12 @@ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ # ARG EXTRA_NODE_VERSION=10 # RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}" +# 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 + # [Optional] Uncomment if you want to install more global node modules # RUN su node -c "npm install -g " @@ -44,15 +50,17 @@ RUN npm config set @cerc-io:registry ${CERC_NPM_URL} \ && npm config set @lirewine:registry ${CERC_NPM_URL} \ && npm config set -- ${CERC_NPM_URL}:_authToken ${CERC_NPM_AUTH_TOKEN} +RUN mkdir -p /config +COPY ./config.yml /config + # Install simple web server for now (use nginx perhaps later) RUN yarn global add http-server # Globally install the payload web app package RUN yarn global add @cerc-io/console-app -# Temp hack to fix up config -RUN cd /usr/local/share/.config/yarn/global/node_modules/@cerc-io/console-app/dist/production && \ - find . -type f -exec sed -i 's#LACONIC_HOSTED_CONFIG_SERVICES_WNS_SERVER#http://laconicd:9473/api#g' {} + +# Run this script to substitute the config values into the unpackaged webapp files: +# ./scripts/apply-webapp-config.sh ./config/config.yml /usr/local/share/.config/yarn/global/node_modules/@cerc-io/console-app/dist/production # Expose port for http EXPOSE 80 diff --git a/app/data/container-build/cerc-laconic-console-host/apply-webapp-config.sh b/app/data/container-build/cerc-laconic-console-host/apply-webapp-config.sh new file mode 100755 index 00000000..a453cc87 --- /dev/null +++ b/app/data/container-build/cerc-laconic-console-host/apply-webapp-config.sh @@ -0,0 +1,34 @@ +#!/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 +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: +# LACONIC_HOSTED_CONFIG_= +readarray -t config_kv_pair_array < <( yq '.. | select(length > 2) | ([path | join("_"), .] | join("=") )' ${config_file_name} | sed 's/^/LACONIC_HOSTED_CONFIG_/' ) +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 diff --git a/app/data/container-build/cerc-laconic-console-host/config.yml b/app/data/container-build/cerc-laconic-console-host/config.yml new file mode 100644 index 00000000..dc385bf3 --- /dev/null +++ b/app/data/container-build/cerc-laconic-console-host/config.yml @@ -0,0 +1,6 @@ +# Config for laconic-console running in a fixturenet with laconicd + +services: + wns: + server: 'http:/laconicd:9473/api' + webui: 'http://laconicd:9473/console' diff --git a/app/data/container-build/cerc-laconic-console-host/start-serving-app.sh b/app/data/container-build/cerc-laconic-console-host/start-serving-app.sh new file mode 100644 index 00000000..ab466678 --- /dev/null +++ b/app/data/container-build/cerc-laconic-console-host/start-serving-app.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +if [ -n "$CERC_SCRIPT_DEBUG" ]; then + set -x +fi