From 6e67a59251be24f97224206025573421af5392c3 Mon Sep 17 00:00:00 2001 From: David Boreham Date: Fri, 6 Jan 2023 13:44:52 -0700 Subject: [PATCH] Initial implementation --- app/data/container-image-list.txt | 2 +- .../cerc-laconic-registry-cli/Dockerfile | 57 ++++++++++++++++--- .../cerc-laconic-registry-cli/build.sh | 6 +- 3 files changed, 54 insertions(+), 11 deletions(-) diff --git a/app/data/container-image-list.txt b/app/data/container-image-list.txt index c697fe21..48d5bc04 100644 --- a/app/data/container-image-list.txt +++ b/app/data/container-image-list.txt @@ -9,7 +9,7 @@ cerc/ipld-eth-beacon-db cerc/ipld-eth-beacon-indexer cerc/ipld-eth-server cerc/laconicd -cerc/laconic-cns-cli +cerc/laconic-registry-cli cerc/fixturenet-eth-geth cerc/fixturenet-eth-lighthouse cerc/watcher-mobymask diff --git a/container-build/cerc-laconic-registry-cli/Dockerfile b/container-build/cerc-laconic-registry-cli/Dockerfile index dab45c26..45ec0a8c 100644 --- a/container-build/cerc-laconic-registry-cli/Dockerfile +++ b/container-build/cerc-laconic-registry-cli/Dockerfile @@ -1,13 +1,54 @@ -# TODO: move this into the cerc-io/laconic-sdk (aka client) repo -FROM node:16.17.1-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 NPM_AUTH_TOKEN -WORKDIR /app +ARG USERNAME=node +ARG NPM_GLOBAL=/usr/local/share/npm-global -COPY . . +# This container pulls npm packages from a local registry configured via these env vars +ARG CERC_LOCAL_NPM_URL +ARG CERC_LOCAL_NPM_TOKEN -RUN echo //npm.pkg.github.com/:_authToken=$NPM_AUTH_TOKEN > ~/.npmrc +# Add NPM global to PATH. +ENV PATH=${NPM_GLOBAL}/bin:${PATH} -RUN apk --update --no-cache add git && yarn && yarn build +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 -ENTRYPOINT ["/app/bin/laconic"] +# [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}" + +# [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 @lirewine:registry ${CERC_LOCAL_NPM_URL} \ + && npm config set @cerc-io:registry ${CERC_LOCAL_NPM_URL} \ + && npm config set @lirewine:registry ${CERC_LOCAL_NPM_URL} \ + && npm config set -- ${CERC_LOCAL_NPM_URL}:_authToken ${CERC_LOCAL_NPM_TOKEN} + +# TODO: the image at this point could be made a base image for several different CLI images +# that install different Node-based CLI commands + +# Globally install the cli package +RUN yarn global add @cerc-io/laconic-registry-cli + +ENTRYPOINT ["laconic"] diff --git a/container-build/cerc-laconic-registry-cli/build.sh b/container-build/cerc-laconic-registry-cli/build.sh index a4a8de41..43ec55a7 100755 --- a/container-build/cerc-laconic-registry-cli/build.sh +++ b/container-build/cerc-laconic-registry-cli/build.sh @@ -1,7 +1,9 @@ #!/usr/bin/env bash -# Build cerc/laconic-cns-cli +# 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-cns-cli:local -f ${SCRIPT_DIR}/Dockerfile --build-arg NPM_AUTH_TOKEN=$(NPM_AUTH_TOKEN) ${CERC_REPO_BASE_DIR}/laconic-cns-cli +docker build -t cerc/laconic-registry-cli:local -f ${SCRIPT_DIR}/Dockerfile \ + --add-host host.docker.internal:host-gateway \ + --build-arg CERC_LOCAL_NPM_TOKEN --build-arg CERC_LOCAL_NPM_URL ${SCRIPT_DIR}