diff --git a/app/data/compose/docker-compose-mobymask-app.yml b/app/data/compose/docker-compose-mobymask-app.yml index 961fc7fe..ad97056a 100644 --- a/app/data/compose/docker-compose-mobymask-app.yml +++ b/app/data/compose/docker-compose-mobymask-app.yml @@ -13,6 +13,7 @@ services: CERC_DEPLOYED_CONTRACT: ${CERC_DEPLOYED_CONTRACT} CERC_APP_WATCHER_URL: ${CERC_APP_WATCHER_URL} CERC_RELAY_NODES: ${CERC_RELAY_NODES} + working_dir: /scripts # Waits for watcher server to be up before app build # Required when running with watcher stack to get deployed contract address command: @@ -20,8 +21,8 @@ services: - -c - ./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-start.sh:/app/mobymask-app-start.sh + - ../config/wait-for-it.sh:/scripts/wait-for-it.sh + - ../config/watcher-mobymask-v2/mobymask-app-start.sh:/scripts/mobymask-app-start.sh - peers_ids:/peers - mobymask_deployment:/server ports: diff --git a/app/data/config/watcher-mobymask-v2/mobymask-app-config.json b/app/data/config/watcher-mobymask-v2/mobymask-app-config.json deleted file mode 100644 index ed913b51..00000000 --- a/app/data/config/watcher-mobymask-v2/mobymask-app-config.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "name": "MobyMask", - "relayNodes": [], - "peer": { - "enableDebugInfo": true - } -} diff --git a/app/data/container-build/cerc-mobymask-ui/Dockerfile b/app/data/container-build/cerc-mobymask-ui/Dockerfile index 791b623c..3f04ec45 100644 --- a/app/data/container-build/cerc-mobymask-ui/Dockerfile +++ b/app/data/container-build/cerc-mobymask-ui/Dockerfile @@ -1,8 +1,37 @@ -FROM node:18.15.0-alpine3.16 +# Originally from: https://github.com/devcontainers/images/blob/main/src/javascript-node/.devcontainer/Dockerfile +# [Choice] Node.js version (use -bullseye variants on local arm64/Apple Silicon): 18, 16, 14, 18-bullseye, 16-bullseye, 14-bullseye, 18-buster, 16-buster, 14-buster +ARG VARIANT=16-bullseye +FROM node:${VARIANT} -ARG REPO_DIR +ARG USERNAME=node +ARG NPM_GLOBAL=/usr/local/share/npm-global -RUN apk --update --no-cache add make git jq bash +# This container pulls npm package from a registry configured via env var +ARG CERC_NPM_REGISTRY_URL + +# Add NPM global to PATH. +ENV PATH=${NPM_GLOBAL}/bin:${PATH} +# Prevents npm from printing version warnings +ENV NPM_CONFIG_UPDATE_NOTIFIER=false + +RUN \ + # Configure global npm install location, use group to adapt to UID/GID changes + if ! cat /etc/group | grep -e "^npm:" > /dev/null 2>&1; then groupadd -r npm; fi \ + && usermod -a -G npm ${USERNAME} \ + && umask 0002 \ + && mkdir -p ${NPM_GLOBAL} \ + && touch /usr/local/etc/npmrc \ + && chown ${USERNAME}:npm ${NPM_GLOBAL} /usr/local/etc/npmrc \ + && chmod g+s ${NPM_GLOBAL} \ + && npm config -g set prefix ${NPM_GLOBAL} \ + && su ${USERNAME} -c "npm config -g set prefix ${NPM_GLOBAL}" \ + # Install eslint + && su ${USERNAME} -c "umask 0002 && npm install -g eslint" \ + && npm cache clean --force > /dev/null 2>&1 + +# Install additional OS packages. +RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ + && apt-get -y install --no-install-recommends 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 @@ -11,24 +40,16 @@ RUN mkdir -p /scripts COPY ./apply-webapp-config.sh /scripts COPY ./start-serving-app.sh /scripts +# Configure the local npm registry +RUN npm config set @cerc-io:registry ${CERC_NPM_REGISTRY_URL} + RUN mkdir -p /config # Install simple web server for now (use nginx perhaps later) RUN yarn global add http-server -WORKDIR /app - -# 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 /app/src/config.json - -RUN echo "Building mobymask-ui" -RUN npm install -RUN REACT_APP_WATCHER_URI="MOBYMASK_HOSTED_CONFIG_watcherUrl/graphql" npm run build - -WORKDIR /app +# Globally install the payload web app package +RUN yarn global add @cerc-io/mobymask-ui # Expose port for http EXPOSE 80 diff --git a/app/data/container-build/cerc-mobymask-ui/apply-webapp-config.sh b/app/data/container-build/cerc-mobymask-ui/apply-webapp-config.sh index a7f0a28e..9f32cd23 100755 --- a/app/data/container-build/cerc-mobymask-ui/apply-webapp-config.sh +++ b/app/data/container-build/cerc-mobymask-ui/apply-webapp-config.sh @@ -33,7 +33,7 @@ do 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 + if [[ "$template_string_to_replace" =~ ^${config_prefix}_(relayNodes|chainId)$ ]]; 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. diff --git a/app/data/container-build/cerc-mobymask-ui/build.sh b/app/data/container-build/cerc-mobymask-ui/build.sh index 81e0b3b5..995a3b51 100755 --- a/app/data/container-build/cerc-mobymask-ui/build.sh +++ b/app/data/container-build/cerc-mobymask-ui/build.sh @@ -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/mobymask-ui:local -f ${SCRIPT_DIR}/Dockerfile ${SCRIPT_DIR} +# 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/mobymask-ui:local ${build_command_args} -f ${SCRIPT_DIR}/Dockerfile \ + --build-arg CERC_NPM_REGISTRY_URL ${SCRIPT_DIR} diff --git a/app/data/container-build/cerc-mobymask-ui/mobymask-config.json b/app/data/container-build/cerc-mobymask-ui/mobymask-config.json deleted file mode 100644 index f1d53acc..00000000 --- a/app/data/container-build/cerc-mobymask-ui/mobymask-config.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "MobyMask", - "address": "MOBYMASK_HOSTED_CONFIG_address", - "chainId": "MOBYMASK_HOSTED_CONFIG_chainId", - "relayNodes": "MOBYMASK_HOSTED_CONFIG_relayNodes", - "peer": { - "enableDebugInfo": true - } -} diff --git a/app/data/container-build/cerc-mobymask-ui/start-serving-app.sh b/app/data/container-build/cerc-mobymask-ui/start-serving-app.sh index e1b460e9..4e0a976c 100755 --- a/app/data/container-build/cerc-mobymask-ui/start-serving-app.sh +++ b/app/data/container-build/cerc-mobymask-ui/start-serving-app.sh @@ -2,7 +2,8 @@ if [ -n "$CERC_SCRIPT_DEBUG" ]; then set -x fi + # TODO: Don't hard wire this: -webapp_files_dir=/app/build +webapp_files_dir=/usr/local/share/.config/yarn/global/node_modules/@cerc-io/mobymask-ui/build /scripts/apply-webapp-config.sh /config/config.yml ${webapp_files_dir} MOBYMASK_HOSTED_CONFIG http-server -p 80 ${webapp_files_dir} diff --git a/app/data/stacks/mobymask-v2/web-apps.md b/app/data/stacks/mobymask-v2/web-apps.md index 382b8af5..2a98370a 100644 --- a/app/data/stacks/mobymask-v2/web-apps.md +++ b/app/data/stacks/mobymask-v2/web-apps.md @@ -23,7 +23,7 @@ git checkout v0.2.31 # mobymask-ui cd ~/cerc/mobymask-ui -git checkout laconic +git checkout v0.1.1 ``` Build the container images: