Use published react-peer/test-app from gitea

This commit is contained in:
nabarun 2023-04-18 18:01:36 +05:30
parent bfe4e9982d
commit 46574341bb
11 changed files with 95 additions and 30 deletions

View File

@ -28,7 +28,7 @@ services:
ports:
- "0.0.0.0:3002:80"
healthcheck:
test: ["CMD", "nc", "-v", "localhost", "3000"]
test: ["CMD", "nc", "-v", "localhost", "80"]
interval: 20s
timeout: 5s
retries: 15

View File

@ -4,7 +4,7 @@ services:
peer-test-app:
# Builds and serves the peer-test react-app
image: cerc/react-peer:local
working_dir: /app/packages/test-app
working_dir: /scripts
env_file:
- ../config/watcher-mobymask-v2/mobymask-params.env
environment:
@ -12,13 +12,12 @@ services:
CERC_RELAY_NODES: ${CERC_RELAY_NODES}
command: ["sh", "./test-app-start.sh"]
volumes:
- ../config/watcher-mobymask-v2/test-app-config.json:/app/packages/test-app/src/test-app-config.json
- ../config/watcher-mobymask-v2/test-app-start.sh:/app/packages/test-app/test-app-start.sh
- ../config/watcher-mobymask-v2/test-app-start.sh:/scripts/test-app-start.sh
- peers_ids:/peers
ports:
- "0.0.0.0:3003:3000"
- "0.0.0.0:3003:80"
healthcheck:
test: ["CMD", "nc", "-v", "localhost", "3000"]
test: ["CMD", "nc", "-v", "localhost", "80"]
interval: 20s
timeout: 5s
retries: 15

View File

@ -14,11 +14,7 @@ fi
echo "Using CERC_RELAY_NODES $CERC_RELAY_NODES"
# Set relay nodes in config using CERC_RELAY_NODES
jq --argjson relayNodes "$CERC_RELAY_NODES" \
'.relayNodes = $relayNodes' \
./src/test-app-config.json > ./src/config.json
# Use yq to create config.yml with environment variables
yq -n ".relayNodes = strenv(CERC_RELAY_NODES)" > /config/config.yml
yarn build
serve -s build
/scripts/start-serving-app.sh

View File

@ -2,13 +2,12 @@
if [ -n "$CERC_SCRIPT_DEBUG" ]; then
set -x
fi
if [[ $# -ne 3 ]]; then
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
@ -18,8 +17,8 @@ if ! [[ -d ${webapp_files_dir} ]]; then
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}_/" )
# LACONIC_HOSTED_CONFIG_<path-through-objects>=<value>
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[@]}"

View File

@ -4,5 +4,5 @@ if [ -n "$CERC_SCRIPT_DEBUG" ]; then
fi
# TODO: Don't hard wire this:
webapp_files_dir=/usr/local/share/.config/yarn/global/node_modules/@cerc-io/console-app/dist/production
/scripts/apply-webapp-config.sh /config/config.yml ${webapp_files_dir} LACONIC_HOSTED_CONFIG
/scripts/apply-webapp-config.sh /config/config.yml ${webapp_files_dir}
http-server -p 80 ${webapp_files_dir}

View File

@ -1,14 +1,30 @@
FROM node:18.15.0-alpine3.16
RUN apk --update --no-cache add make git python3 jq
# This container pulls npm package from a registry configured via env var
ARG CERC_NPM_REGISTRY_URL
WORKDIR /app
RUN apk --update --no-cache add make git python3 jq bash
COPY . .
# 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 yarn global add serve
RUN mkdir -p /scripts
COPY ./apply-webapp-config.sh /scripts
COPY ./start-serving-app.sh /scripts
RUN echo "Building react-peer" && \
yarn install --ignore-scripts && yarn build --ignore @cerc-io/test-app
# Configure the local npm registry
RUN npm config set @cerc-io:registry ${CERC_NPM_REGISTRY_URL}
WORKDIR /app
RUN mkdir -p /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/test-app
# Expose port for http
EXPOSE 80
CMD ["/scripts/start-serving-app.sh"]

View File

@ -0,0 +1,42 @@
#!/usr/bin/env bash
if [ -n "$CERC_SCRIPT_DEBUG" ]; then
set -x
fi
if [[ $# -ne 3 ]]; 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 sed to translate our yaml config file into an array of key value pairs like:
# ${config_prefix}<path-through-objects>=<value>
# 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
# 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}"
# 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

View File

@ -6,4 +6,8 @@ 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/react-peer:local -f ${SCRIPT_DIR}/Dockerfile ${build_command_args} ${CERC_REPO_BASE_DIR}/react-peer
# TODO: Publish package to local SO gitea similar to laconic-console
CERC_NPM_REGISTRY_URL="https://git.vdb.to/api/packages/cerc-io/npm/"
docker build -t cerc/react-peer:local ${build_command_args} -f ${SCRIPT_DIR}/Dockerfile \
--build-arg CERC_NPM_REGISTRY_URL ${SCRIPT_DIR}

View File

@ -0,0 +1,9 @@
#!/usr/bin/env bash
if [ -n "$CERC_SCRIPT_DEBUG" ]; then
set -x
fi
# TODO: Don't hard wire this:
webapp_files_dir=/usr/local/share/.config/yarn/global/node_modules/@cerc-io/test-app/build
/scripts/apply-webapp-config.sh /config/config.yml ${webapp_files_dir} MOBYMASK_HOSTED_CONFIG
http-server -p 80 ${webapp_files_dir}

View File

@ -27,11 +27,11 @@ git checkout v0.2.35
# react-peer
cd ~/cerc/react-peer
git checkout v0.2.31
git checkout v0.2.32
# mobymask-ui
cd ~/cerc/mobymask-ui
git checkout laconic
git checkout v0.1.2
# MobyMask
cd ~/cerc/MobyMask

View File

@ -19,11 +19,11 @@ Checkout to the required versions and branches in repos:
```bash
# react-peer
cd ~/cerc/react-peer
git checkout v0.2.31
git checkout v0.2.32
# mobymask-ui
cd ~/cerc/mobymask-ui
git checkout v0.1.1
git checkout v0.1.2
```
Build the container images: