Package mobymask-v2 stack web-apps similar to laconic-console app #310
@ -3,6 +3,7 @@ version: '3.2'
|
||||
services:
|
||||
# Builds and serves the MobyMask react-app
|
||||
mobymask-app:
|
||||
restart: unless-stopped
|
||||
image: cerc/mobymask-ui:local
|
||||
env_file:
|
||||
- ../config/watcher-mobymask-v2/mobymask-params.env
|
||||
@ -20,12 +21,12 @@ 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/mobymask-app-config.json:/app/src/mobymask-app-config.json
|
||||
- ../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
|
||||
ports:
|
||||
- "0.0.0.0:3002:3000"
|
||||
- "0.0.0.0:3002:80"
|
||||
healthcheck:
|
||||
test: ["CMD", "nc", "-v", "localhost", "3000"]
|
||||
interval: 20s
|
||||
|
9
app/data/config/watcher-mobymask-v2/config-template.yml
Normal file
9
app/data/config/watcher-mobymask-v2/config-template.yml
Normal file
@ -0,0 +1,9 @@
|
||||
# Config for mobymask-app running with mobymask-v2-watcher
|
||||
|
||||
address:
|
||||
|
||||
chainId:
|
||||
|
||||
relayNodes:
|
||||
|
||||
watcherUrl:
|
@ -28,13 +28,14 @@ else
|
||||
echo "Taking deployed contract details from env"
|
||||
fi
|
||||
|
||||
# Export config values in a json file
|
||||
jq --arg address "$CERC_DEPLOYED_CONTRACT" \
|
||||
--argjson chainId "$CERC_CHAIN_ID" \
|
||||
--argjson relayNodes "$CERC_RELAY_NODES" \
|
||||
'.address = $address | .chainId = $chainId | .relayNodes = $relayNodes' \
|
||||
/app/src/mobymask-app-config.json > /app/src/config.json
|
||||
# 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
|
||||
|
||||
REACT_APP_WATCHER_URI="$CERC_APP_WATCHER_URL/graphql" npm run build
|
||||
|
||||
serve -s build
|
||||
sh /scripts/mobymask-app-start.sh
|
||||
|
@ -8,6 +8,7 @@ if [[ $# -ne 2 ]]; then
|
||||
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
|
||||
@ -17,8 +18,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:
|
||||
# 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_/' )
|
||||
# ${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[@]}"
|
@ -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,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}
|
||||
/scripts/apply-webapp-config.sh /config/config.yml ${webapp_files_dir} LACONIC_HOSTED_CONFIG
|
||||
http-server -p 80 ${webapp_files_dir}
|
||||
|
@ -1,14 +1,29 @@
|
||||
FROM node:18.15.0-alpine3.16
|
||||
|
||||
ARG REPO_DIR
|
||||
|
||||
RUN apk --update --no-cache add make git jq bash
|
||||
|
||||
RUN mkdir -p /scripts
|
||||
COPY ../apply-webapp-config.sh /scripts
|
||||
COPY ./start-serving-app.sh /scripts
|
||||
|
||||
# Install simple web server for now (use nginx perhaps later)
|
||||
RUN yarn global add http-server
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY . .
|
||||
COPY ${REPO_DIR} .
|
||||
|
||||
RUN npm install -g serve
|
||||
COPY ./mobymask-config.json /src/config.json
|
||||
|
||||
RUN echo "Building mobymask-ui" && \
|
||||
npm install
|
||||
npm install && \
|
||||
REACT_APP_WATCHER_URI="MOBYMASK_HOSTED_CONFIG_watcherUrl/graphql" npm run build
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Expose port for http
|
||||
EXPOSE 80
|
||||
|
||||
CMD ["/scripts/start-serving-app.sh"]
|
||||
|
@ -6,4 +6,5 @@ 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_command_args} ${CERC_REPO_BASE_DIR}/mobymask-ui
|
||||
docker build -t cerc/mobymask-ui:local -f ${SCRIPT_DIR}/Dockerfile \
|
||||
--build-arg REPO_DIR=${CERC_REPO_BASE_DIR}/mobymask-ui ${SCRIPT_DIR}
|
||||
|
@ -0,0 +1,9 @@
|
||||
{
|
||||
"name": "MobyMask",
|
||||
"address": "MOBYMASK_HOSTED_CONFIG_address",
|
||||
"chainId": "MOBYMASK_HOSTED_CONFIG_chainId",
|
||||
"relayNodes": "MOBYMASK_HOSTED_CONFIG_relayNodes",
|
||||
"peer": {
|
||||
"enableDebugInfo": true
|
||||
}
|
||||
}
|
8
app/data/container-build/cerc-mobymask-ui/start-serving-app.sh
Executable file
8
app/data/container-build/cerc-mobymask-ui/start-serving-app.sh
Executable file
@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
if [ -n "$CERC_SCRIPT_DEBUG" ]; then
|
||||
set -x
|
||||
fi
|
||||
# TODO: Don't hard wire this:
|
||||
webapp_files_dir=/app/build
|
||||
/scripts/apply-webapp-config.sh /config/config.yml ${webapp_files_dir} MOBYMASK_HOSTED_CONFIG
|
||||
http-server -p 80 ${webapp_files_dir}
|
@ -14,7 +14,7 @@ $ chmod +x ./laconic-so
|
||||
$ export PATH=$PATH:$(pwd) # Or move laconic-so to ~/bin or your favorite on-path directory
|
||||
```
|
||||
## 2. Prepare the local build environment
|
||||
Note that this step needs only to be done once on a new machine.
|
||||
Note that this step needs only to be done once on a new machine.
|
||||
Detailed instructions can be found [here](../build-support/README.md). For the impatient run these commands:
|
||||
```
|
||||
$ laconic-so --stack build-support build-containers --exclude cerc/builder-gerbil
|
||||
|
@ -29,7 +29,7 @@ git checkout laconic
|
||||
Build the container images:
|
||||
|
||||
```bash
|
||||
laconic-so --stack mobymask-v2 build-containers --include cerc/react-peer-v2,cerc/mobymask-ui
|
||||
laconic-so --stack mobymask-v2 build-containers --include cerc/react-peer,cerc/mobymask-ui
|
||||
```
|
||||
|
||||
This should create the required docker images in the local image registry
|
||||
|
Loading…
Reference in New Issue
Block a user