diff --git a/app/data/compose/docker-compose-fixturenet-laconic-console.yml b/app/data/compose/docker-compose-fixturenet-laconic-console.yml new file mode 100644 index 00000000..f402fa70 --- /dev/null +++ b/app/data/compose/docker-compose-fixturenet-laconic-console.yml @@ -0,0 +1,6 @@ +services: + laconic-console: + restart: unless-stopped + image: cerc/laconic-console-host:local + ports: + - "80" diff --git a/app/data/compose/docker-compose-fixturenet-laconicd.yml b/app/data/compose/docker-compose-fixturenet-laconicd.yml index 9663e7f0..5d777b5d 100644 --- a/app/data/compose/docker-compose-fixturenet-laconicd.yml +++ b/app/data/compose/docker-compose-fixturenet-laconicd.yml @@ -13,7 +13,7 @@ services: - "6060" - "26657" - "26656" - - "9473" + - "9473:9473" - "8545" - "8546" - "9090" diff --git a/app/data/container-build/cerc-laconic-console-host/Dockerfile b/app/data/container-build/cerc-laconic-console-host/Dockerfile new file mode 100644 index 00000000..66eec1f5 --- /dev/null +++ b/app/data/container-build/cerc-laconic-console-host/Dockerfile @@ -0,0 +1,67 @@ +# 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 USERNAME=node +ARG NPM_GLOBAL=/usr/local/share/npm-global + +# This container pulls npm packages from a local registry configured via these env vars +ARG CERC_NPM_URL +ARG CERC_NPM_AUTH_TOKEN + +# Add NPM global to PATH. +ENV PATH=${NPM_GLOBAL}/bin:${PATH} + +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 + +# [Optional] Uncomment this section to install additional OS packages. +RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ + && apt-get -y install --no-install-recommends jq + +# [Optional] Uncomment if you want to install an additional version of node using nvm +# 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 +COPY ./start-serving-app.sh /scripts + +# [Optional] Uncomment if you want to install more global node modules +# RUN su node -c "npm install -g " + +# Configure the local npm registry +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 + +# Expose port for http +EXPOSE 80 + +# Default command sleeps forever so docker doesn't kill it +CMD ["/scripts/start-serving-app.sh"] 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/build.sh b/app/data/container-build/cerc-laconic-console-host/build.sh new file mode 100755 index 00000000..cc84d249 --- /dev/null +++ b/app/data/container-build/cerc-laconic-console-host/build.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +# Build cerc/laconic-registry-cli + +# See: https://stackoverflow.com/a/246128/1701505 +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +docker build -t cerc/laconic-console-host:local -f ${SCRIPT_DIR}/Dockerfile \ + --add-host gitea.local:host-gateway \ + --build-arg CERC_NPM_AUTH_TOKEN --build-arg CERC_NPM_URL ${SCRIPT_DIR} 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..da57724a --- /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://localhost:9473/api' + webui: 'http://localhost: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 100755 index 00000000..a322e5fb --- /dev/null +++ b/app/data/container-build/cerc-laconic-console-host/start-serving-app.sh @@ -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=/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} +http-server -p 80 ${webapp_files_dir} diff --git a/app/data/container-image-list.txt b/app/data/container-image-list.txt index 8be9f085..c7b76e8d 100644 --- a/app/data/container-image-list.txt +++ b/app/data/container-image-list.txt @@ -11,6 +11,7 @@ cerc/ipld-eth-beacon-indexer cerc/ipld-eth-server cerc/laconicd cerc/laconic-registry-cli +cerc/laconic-console-host cerc/fixturenet-eth-geth cerc/fixturenet-eth-lighthouse cerc/watcher-mobymask diff --git a/app/data/npm-package-list.txt b/app/data/npm-package-list.txt index 3b6656be..f194e627 100644 --- a/app/data/npm-package-list.txt +++ b/app/data/npm-package-list.txt @@ -1,5 +1,7 @@ laconic-sdk laconic-registry-cli -gem +laconic-console debug crypto +sdk +gem diff --git a/app/data/repository-list.txt b/app/data/repository-list.txt index cc78b080..5acc4523 100644 --- a/app/data/repository-list.txt +++ b/app/data/repository-list.txt @@ -9,6 +9,7 @@ cerc-io/ipld-eth-beacon-db cerc-io/laconicd cerc-io/laconic-sdk cerc-io/laconic-registry-cli +cerc-io/laconic-console cerc-io/mobymask-watcher cerc-io/watcher-ts cerc-io/react-peer @@ -23,4 +24,5 @@ dboreham/foundry lirewine/gem lirewine/debug lirewine/crypto +lirewine/sdk telackey/act_runner diff --git a/app/data/stacks/fixturenet-laconic-loaded/README.md b/app/data/stacks/fixturenet-laconic-loaded/README.md new file mode 100644 index 00000000..000596ee --- /dev/null +++ b/app/data/stacks/fixturenet-laconic-loaded/README.md @@ -0,0 +1,50 @@ +# Laconic Fixturenet (experimental) + +Testing a "Loaded" fixturenet with console. + +Instructions for deploying a local Laconic blockchain "fixturenet" for development and testing purposes using laconic-stack-orchestrator. + +## 1. Install Laconic Stack Orchestrator +Installation is covered in detail [here](https://github.com/cerc-io/stack-orchestrator#user-mode) but if you're on Linux and already have docker installed it should be as simple as: +``` +$ mkdir my-working-dir +$ cd my-working-dir +$ curl -L -o ./laconic-so https://github.com/cerc-io/stack-orchestrator/releases/latest/download/laconic-so +$ 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. +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 +$ laconic-so --stack package-registry setup-repositories +$ laconic-so --stack package-registry deploy-system up +``` +Then add the localhost alias `gitea.local` and set `CERC_NPM_AUTH_TOKEN` to the token printed when the package-registry stack was deployed above: +``` +$ sudo vi /etc/hosts +$ export CERC_NPM_AUTH_TOKEN= +``` + +## 3. Clone required repositories +``` +$ laconic-so --stack fixturenet-laconicd setup-repositories +``` +## 4. Build the stack's packages and containers +``` +$ laconic-so --stack fixturenet-laconicd build-npms +$ laconic-so --stack fixturenet-laconicd build-containers +``` +## 5. Deploy the stack +``` +$ laconic-so --stack fixturenet-laconicd deploy up +``` +Correct operation should be verified by checking the laconicd container's logs with: +``` +$ laconic-so --stack fixturenet-laconicd deploy logs +``` +## 6. Test with the Registry CLI +``` +$ laconic-so --stack fixturenet-laconicd deploy exec cli "laconic cns status" +``` diff --git a/app/data/stacks/fixturenet-laconic-loaded/stack.yml b/app/data/stacks/fixturenet-laconic-loaded/stack.yml new file mode 100644 index 00000000..03d0a4c9 --- /dev/null +++ b/app/data/stacks/fixturenet-laconic-loaded/stack.yml @@ -0,0 +1,30 @@ +version: "1.0" +name: fixturenet-laconic-loaded +description: "A full featured laconic fixturenet" +repos: + - cerc-io/laconicd + - lirewine/debug + - lirewine/crypto + - lirewine/gem + - lirewine/sdk + - cerc-io/laconic-sdk + - cerc-io/laconic-registry-cli + - cerc-io/laconic-console +npms: + - laconic-sdk + - laconic-registry-cli + - debug + - crypto + - sdk + - gem + - laconic-console +containers: + - cerc/laconicd + - cerc/laconic-registry-cli + - cerc/laconic-console-host +pods: + - fixturenet-laconicd + - fixturenet-laconic-console +config: + cli: + key: laconicd.mykey