From 4c1534d3bc91d716a1d5df541d7225d67590cb8a Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Thu, 12 Jul 2018 20:35:03 -0500 Subject: [PATCH 01/76] run.sh script / run_embark_docker function --- run.sh | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100755 run.sh diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..2b6ed0a --- /dev/null +++ b/run.sh @@ -0,0 +1,102 @@ +#!/usr/bin/env bash + +unset run_embark_docker + +run_embark_docker () { + local oldopts="" + case $- in + *e*) oldopts="set -e";; + *) oldopts="set +e";; + esac + if [[ $(shopt -po history) = "set -o history" ]]; then + oldopts="$oldopts; set -o history" + fi + set +e + set +o history + + local txtbld=$(tput bold) + local txtrst=$(tput sgr0) + + local bldcyn=${txtbld}$(tput setaf 6) + local bldred=${txtbld}$(tput setaf 1) + local bldylw=${txtbld}$(tput setaf 3) + + local ERROR=${bldred}ERROR${txtrst} + local INFO=${bldcyn}INFO${txtrst} + local WARNING=${bldylw}WARNING${txtrst} + + check_bash_version () { + if [[ $BASH_VERSINFO -lt 4 ]]; then + echo "$ERROR: this script requires Bash version >= 4.0" + return 1 + fi + } + + check_bash_version + + if [[ $? = 1 ]]; then + unset check_bash_version + eval "$oldopts" + if [[ "$0" != "$BASH_SOURCE" ]]; then + return 1 + else + exit 1 + fi + fi + + check_docker () { + if ! type docker &> /dev/null; then + echo "$ERROR: the command \`docker\` must be in a path on \$PATH or aliased" + return 127 + fi + } + + check_docker + + if [[ $? = 127 ]]; then + unset check_bash_version + unset check_docker + eval "$oldopts" + if [[ "$0" != "$BASH_SOURCE" ]]; then + return 127 + else + exit 127 + fi + fi + + local EMBARK_DOCKER_TAG="${EMBARK_DOCKER_TAG:-latest}" + local EMBARK_DOCKER_MOUNT_DIR="${EMBARK_DOCKER_MOUNT_DIR:-$(pwd)}" + + docker run \ + -it \ + -p 5001:5001 \ + -p 8000:8000 \ + -p 8080:8080 \ + -p 8500:8500 \ + -p 8545:8545 \ + -p 8546:8546 \ + -p 8555:8555 \ + -p 30301:30301/udp \ + -p 30303:30303 \ + -v "$EMBARK_DOCKER_MOUNT_DIR":/dapp \ + statusim/embark:"$EMBARK_DOCKER_TAG" \ + "$@" + + local docker_exit_status=$? + + unset check_bash_version + unset check_docker + eval "$oldopts" + + if [[ $docker_exit_status != 0 ]]; then + if [[ "$0" != "$BASH_SOURCE" ]]; then + return $docker_exit_status + else + exit $docker_exit_status + fi + fi +} + +if [[ "$0" = "$BASH_SOURCE" ]]; then + run_embark_docker "$@" +fi From 5986bb4e4c663126e42b6ffe0b0b9abe33f245e4 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Sun, 15 Jul 2018 20:15:41 -0500 Subject: [PATCH 02/76] ws proxy port --- run.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/run.sh b/run.sh index 2b6ed0a..a5df50a 100755 --- a/run.sh +++ b/run.sh @@ -76,6 +76,7 @@ run_embark_docker () { -p 8545:8545 \ -p 8546:8546 \ -p 8555:8555 \ + -p 8556:8556 \ -p 30301:30301/udp \ -p 30303:30303 \ -v "$EMBARK_DOCKER_MOUNT_DIR":/dapp \ From 85e482fe3925b2e4447d0c4c0115313344a08d3f Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Sun, 22 Jul 2018 22:51:42 -0500 Subject: [PATCH 03/76] expand env var overrides --- run.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/run.sh b/run.sh index a5df50a..e80aef9 100755 --- a/run.sh +++ b/run.sh @@ -64,8 +64,10 @@ run_embark_docker () { fi fi - local EMBARK_DOCKER_TAG="${EMBARK_DOCKER_TAG:-latest}" - local EMBARK_DOCKER_MOUNT_DIR="${EMBARK_DOCKER_MOUNT_DIR:-$(pwd)}" + local EMBARK_DOCKER_MOUNT_SOURCE=${EMBARK_DOCKER_MOUNT_DIR:-$(pwd)} + local EMBARK_DOCKER_MOUNT_TARGET=${EMBARK_DOCKER_MOUNT_DIR:-/dapp} + local EMBARK_DOCKER_IMAGE=${EMBARK_DOCKER_IMAGE:-statusim/embark} + local EMBARK_DOCKER_TAG=${EMBARK_DOCKER_TAG:-latest} docker run \ -it \ @@ -79,8 +81,8 @@ run_embark_docker () { -p 8556:8556 \ -p 30301:30301/udp \ -p 30303:30303 \ - -v "$EMBARK_DOCKER_MOUNT_DIR":/dapp \ - statusim/embark:"$EMBARK_DOCKER_TAG" \ + -v ${EMBARK_DOCKER_MOUNT_SOURCE}:${EMBARK_DOCKER_MOUNT_TARGET} \ + ${EMBARK_DOCKER_IMAGE}:${EMBARK_DOCKER_TAG} \ "$@" local docker_exit_status=$? From 320d70ddeb024490e36697244c026db7e2888410 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Sun, 22 Jul 2018 23:02:01 -0500 Subject: [PATCH 04/76] revise for environment bootstrapping and more flexible env/tooling --- Dockerfile | 111 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 74 insertions(+), 37 deletions(-) diff --git a/Dockerfile b/Dockerfile index db38ef4..aa60ce9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,20 +2,28 @@ FROM node:8.11.3-stretch MAINTAINER Andre Medeiros -ENV EMBARK_VERSION=3.1.5 \ - GANACHE_VERSION=6.1.4 \ - GETH_VERSION=1.8.11-dea1ce05 \ - IPFS_VERSION=0.4.15 - +# Embark: 8000 8545 8546 +# Go Ethereum: 30301/udp 30303 8545 8546 (when proxied: 8555 8556) # IPFS: 5001 8080 -# Go Ethereum: 30303/tcp 30301/udp 8545 -# Embark: 8000 8546 8545 # Swarm: 8500 -EXPOSE 5001 8080 30303/tcp 30301/udp 8545 8546 8000 8500 +EXPOSE 5001 8000 8080 8500 8545 8546 8555 8556 30301/udp 30303 -RUN adduser --disabled-password --shell /bin/bash --gecos "" embark \ - # Install geth - && curl -fsSLO --compressed "https://gethstore.blob.core.windows.net/builds/geth-alltools-linux-amd64-${GETH_VERSION}.tar.gz" \ +ARG SUEXEC_VERSION +ENV SUEXEC_VERSION=${SUEXEC_VERSION:-v0.2} +# Install su-exec +RUN cd /tmp \ + && git clone --branch ${SUEXEC_VERSION} --depth 1 \ + https://github.com/ncopa/su-exec.git 2> /dev/null \ + && cd su-exec \ + && make \ + && cp su-exec /usr/local/bin/ \ + && cd .. \ + && rm -rf su-exec + +ARG GETH_VERSION +ENV GETH_VERSION=${GETH_VERSION:-1.8.11-dea1ce05} +# Install geth +RUN curl -fsSLO --compressed "https://gethstore.blob.core.windows.net/builds/geth-alltools-linux-amd64-${GETH_VERSION}.tar.gz" \ && tar -xvzf "geth-alltools-linux-amd64-${GETH_VERSION}.tar.gz" \ && for geth_tool in \ abigen \ @@ -29,37 +37,66 @@ RUN adduser --disabled-password --shell /bin/bash --gecos "" embark \ ; do \ cp "geth-alltools-linux-amd64-${GETH_VERSION}/${geth_tool}" "/usr/local/bin/${geth_tool}"; \ done \ - && rm -rf "geth-alltools-linux-amd64-${GETH_VERSION}*"\ - # Install ipfs - && curl -fsSLO --compressed "https://dist.ipfs.io/go-ipfs/v${IPFS_VERSION}/go-ipfs_v${IPFS_VERSION}_linux-amd64.tar.gz" \ + && rm -rf "geth-alltools-linux-amd64-${GETH_VERSION}*" + +ARG IPFS_VERSION +ENV IPFS_VERSION=${IPFS_VERSION:-0.4.15} +# Install ipfs +RUN curl -fsSLO --compressed "https://dist.ipfs.io/go-ipfs/v${IPFS_VERSION}/go-ipfs_v${IPFS_VERSION}_linux-amd64.tar.gz" \ && tar -xvzf "go-ipfs_v${IPFS_VERSION}_linux-amd64.tar.gz" \ && cp go-ipfs/ipfs /usr/local/bin/ipfs \ - && rm -rf go-ipfs "go-ipfs_v${IPFS_VERSION}_linux-amd64.tar.gz" \ - && mkdir /dapp \ - && chown embark:embark /dapp + && rm -rf go-ipfs "go-ipfs_v${IPFS_VERSION}_linux-amd64.tar.gz" +# Install pip +RUN curl -fsSLO --compressed "https://bootstrap.pypa.io/get-pip.py" \ + && python get-pip.py \ + && rm get-pip.py + +# Setup unprivileged user +RUN adduser --disabled-password --shell /bin/bash --gecos "" embark \ + && mkdir -p /dapp \ + && mkdir -p /home/embark/.npm-packages \ + && chown embark:embark /dapp /home/embark/.npm-packages +COPY dot.bash_env /home/embark/.bash_env +COPY dot.bash_env_nvm_load /home/embark/.bash_env_nvm_load +COPY dot.bash_env_nvm_unload /home/embark/.bash_env_nvm_unload +COPY dot.bashrc /home/embark/.bashrc +COPY dot.npmrc /home/embark/.npmrc +RUN chown embark:embark /home/embark/.bash_env \ + && chown embark:embark /home/embark/.bashrc \ + && chown embark:embark /home/embark/.npmrc + +ARG EMBARK_VERSION +ARG GANACHE_VERSION +ARG NODEENV_VERSION +ARG NVM_VERSION +ENV EMBARK_VERSION=${EMBARK_VERSION:-3.1.5} +ENV GANACHE_VERSION=${GANACHE_VERSION:-6.1.4} +ENV NODEENV_VERSION=${NODEENV_VERSION:-1.3.2} +ENV NVM_VERSION=${NVM_VERSION:-v0.33.11} +# Install tooling and Embark Framework USER embark - -RUN mkdir /home/embark/.npm-packages \ - && echo prefix=/home/embark/.npm-packages > /home/embark/.npmrc \ - && for directive in \ - "export NPM_PACKAGES=\$HOME/.npm-packages" \ - "export NODE_PATH=\$NPM_PACKAGES/lib/node_modules:\$NODE_PATH" \ - "export PATH=\$NPM_PACKAGES/bin:\$PATH" \ - ; do \ - echo ${directive} >> /home/embark/.profile \ - && echo ${directive} >> /home/embark/.bashrc; \ - done \ - # Ensure we source the updated bashrc - && . ~/.bashrc \ - # Install embark and the simulator - && npm install -g "embark@${EMBARK_VERSION}" "ganache-cli@${GANACHE_VERSION}" \ +SHELL ["/bin/bash", "-c"] +WORKDIR /home/embark +RUN . ${HOME}/.bash_env \ + && git clone --branch ${NVM_VERSION} --depth 1 \ + https://github.com/creationix/nvm.git .nvm 2> /dev/null \ + && pip install --user nodeenv==${NODEENV_VERSION} \ + && mkdir -p ${HOME}/.local/nodeenv \ + && npm install -g "ganache-cli@${GANACHE_VERSION}" \ + && npm install -g "embark@${EMBARK_VERSION}" \ # Initialize IPFS && ipfs init \ - # Cleanup build stuff - && echo "Done" + && ipfs config --json Addresses.API '"/ip4/0.0.0.0/tcp/5001"' \ + && ipfs config --json Addresses.Gateway '"/ip4/0.0.0.0/tcp/8080"' \ + && ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["*"]' \ + && ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["GET", "POST", "PUT"]' +# Setup entrypoint and default working directory +USER root +SHELL ["/bin/sh", "-c"] +COPY docker-entrypoint.sh /usr/local/bin/ +RUN chmod +x /usr/local/bin/docker-entrypoint.sh +ENTRYPOINT ["docker-entrypoint.sh"] +CMD ["bash"] WORKDIR /dapp - -CMD ["embark"] - From 9219796b933c9a8ebd4223a436196b7b0ca4a53c Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Sun, 22 Jul 2018 23:03:10 -0500 Subject: [PATCH 05/76] supporting scripts --- docker-entrypoint.sh | 7 +++ dot.bash_env | 132 ++++++++++++++++++++++++++++++++++++++++ dot.bash_env_nvm_load | 26 ++++++++ dot.bash_env_nvm_unload | 7 +++ dot.bashrc | 2 + dot.npmrc | 0 6 files changed, 174 insertions(+) create mode 100644 docker-entrypoint.sh create mode 100644 dot.bash_env create mode 100644 dot.bash_env_nvm_load create mode 100644 dot.bash_env_nvm_unload create mode 100644 dot.bashrc create mode 100644 dot.npmrc diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100644 index 0000000..5ac10d8 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +. /home/embark/.bash_env +export BASH_ENV=/home/embark/.bash_env + +chmod a+w /dev/std* +exec su-exec embark "$@" diff --git a/dot.bash_env b/dot.bash_env new file mode 100644 index 0000000..22ab459 --- /dev/null +++ b/dot.bash_env @@ -0,0 +1,132 @@ +unset BASH_ENV +# we don't need to run more than once +if [[ -v __BASH_ENV ]]; then + return +fi +export __BASH_ENV= +# if we're not pid 1, then it depends... +if [[ $$ != 1 ]]; then + # if we didn't get loaded via .bashrc then we don't run, but a user could + # force the run with: `export BASH_ENV_OK_PID_NOT1_NOT_BASHRC=` + if [[ (! -v __BASHRC) && (! -v BASH_ENV_OK_PID_NOT_1_NOT_BASHRC) ]]; then + return + fi +fi +unset __BASHRC +# if we haven't run yet, then if we're pid 1, or we're not pid 1 but got loaded +# via .bashrc, we continue... + +unset _npm_bak_config_prefix +unset npm_config_prefix +unset NPM_CONFIG_PREFIX + +export _npm_bak_config_prefix=/home/embark/.npm-packages +export npm_config_prefix=$_npm_bak_config_prefix +export NPM_CONFIG_PREFIX=$npm_config_prefix + +export PATH=${_PATH:-$PATH} +unset _PATH +unset __PATH + +export _PATH=/home/embark/.local/bin:$PATH +export __PATH=$NPM_CONFIG_PREFIX/bin:$_PATH +export PATH=$__PATH + +unset _denac +_denac () { + if type deactivate_node &> /dev/null; then + deactivate_node + fi + + export PATH=$__PATH +} +export -f _denac + +unset denac +denac () { + _denac + case $- in + *i*) echo "Now using system version of node: $(node --version) (npm v$(npm --version))";; + esac +} +export -f denac + +unset _nac +_nac () { + local curr_arg; + curr_arg=${COMP_WORDS[COMP_CWORD]} + local envs=$(basename /home/embark/.local/nodeenv/$2*) + if [ $envs == $(echo $2*) ]; then + COMPREPLY=() + else + COMPREPLY=( $(basename /home/embark/.local/nodeenv/$2*) ); + fi +} +export -f _nac + +unset nac +nac () { + local txtbld=$(tput bold) + local txtrst=$(tput sgr0) + local bldcyn=${txtbld}$(tput setaf 6) + local bldred=${txtbld}$(tput setaf 1) + local ERROR=${bldred}ERROR${txtrst} + + if [[ -z "$1" ]]; then + echo "$ERROR: missing node environment name" + return 1 + fi + + if [[ ! -d "/home/embark/.local/nodeenv/$1" ]]; then + echo "$ERROR: no \"$1\" environment found in \/home/embark/.local/nodeenv" + return 1 + fi + + _denac + _nvm_unload + export PATH=$_PATH + + . /home/embark/.local/nodeenv/$1/bin/activate + case $- in + *i*) echo "Now using NODEENV node $(node --version) (npm v$(npm --version))";; + esac +} +export -f nac +complete -F _nac nac + +unset simple_nodeenv +simple_nodeenv () { + pushd $PWD &> /dev/null + cd /home/embark/.local/nodeenv + $(which nodeenv) --prebuilt --node $@ + popd &> /dev/null + nac $2 +} +export -f simple_nodeenv + +unset npm_completion +npm_completion () { + . <(npm completion) +} +export -f npm_completion + +unset nvm_load +nvm_load () { + . /home/embark/.bash_env_nvm_load +} +export -f nvm_load + +unset _nvm_unload +_nvm_unload () { + . /home/embark/.bash_env_nvm_unload +} +export -f _nvm_unload + +unset nvm_unload +nvm_unload () { + _nvm_unload + case $- in + *i*) echo "Now using system version of node: $(node --version) (npm v$(npm --version))";; + esac +} +export -f nvm_unload diff --git a/dot.bash_env_nvm_load b/dot.bash_env_nvm_load new file mode 100644 index 0000000..71137e0 --- /dev/null +++ b/dot.bash_env_nvm_load @@ -0,0 +1,26 @@ +_nvm_unload +_denac +unset npm_config_prefix +unset NPM_CONFIG_PREFIX +export PATH=$_PATH + +. /home/embark/.nvm/nvm.sh &> /dev/null + +if [[ (-z $(nvm alias default)) && ($1 != "no-auto-lts") ]]; then + case $- in + *i*) nvm install --lts;; + *) nvm install --lts &> /dev/null;; + esac + local auto_lts= +fi + +case $- in + *i*) npm_completion;; +esac + +if [[ (! -v auto_lts) \ + && ($(which node) = "/home/embark/.nvm/versions/"*) ]]; then + case $- in + *i*) echo "Now using NVM node $(node --version) (npm v$(npm --version))";; + esac +fi diff --git a/dot.bash_env_nvm_unload b/dot.bash_env_nvm_unload new file mode 100644 index 0000000..0a09f7e --- /dev/null +++ b/dot.bash_env_nvm_unload @@ -0,0 +1,7 @@ +if type nvm &> /dev/null; then + nvm unload +fi + +export npm_config_prefix=$_npm_bak_config_prefix +export NPM_CONFIG_PREFIX=$npm_config_prefix +export PATH=$__PATH diff --git a/dot.bashrc b/dot.bashrc new file mode 100644 index 0000000..afdf556 --- /dev/null +++ b/dot.bashrc @@ -0,0 +1,2 @@ +export __BASHRC= +. /home/embark/.bash_env diff --git a/dot.npmrc b/dot.npmrc new file mode 100644 index 0000000..e69de29 From 87eaaff3d2fb4437b034c107974bec017e2d2520 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Sun, 22 Jul 2018 23:14:29 -0500 Subject: [PATCH 06/76] make "embark run" the default command --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index aa60ce9..76db571 100644 --- a/Dockerfile +++ b/Dockerfile @@ -98,5 +98,5 @@ SHELL ["/bin/sh", "-c"] COPY docker-entrypoint.sh /usr/local/bin/ RUN chmod +x /usr/local/bin/docker-entrypoint.sh ENTRYPOINT ["docker-entrypoint.sh"] -CMD ["bash"] +CMD ["embark", "run"] WORKDIR /dapp From 65c4c9950b17226d927cdb64e201ce12a4fd7dd3 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Tue, 24 Jul 2018 15:23:47 -0500 Subject: [PATCH 07/76] "dot." -> "." -- allows more compact docker COPY --- .bash_env | 144 ++++++++++++++++++++++++++++++++++++++++ .bash_env_nvm_load | 2 + .bash_env_nvm_unload | 2 + .bashrc | 1 + dot.npmrc => .npmrc | 0 dot.bash_env | 132 ------------------------------------ dot.bash_env_nvm_load | 26 -------- dot.bash_env_nvm_unload | 7 -- dot.bashrc | 2 - 9 files changed, 149 insertions(+), 167 deletions(-) create mode 100644 .bash_env create mode 100644 .bash_env_nvm_load create mode 100644 .bash_env_nvm_unload create mode 100644 .bashrc rename dot.npmrc => .npmrc (100%) delete mode 100644 dot.bash_env delete mode 100644 dot.bash_env_nvm_load delete mode 100644 dot.bash_env_nvm_unload delete mode 100644 dot.bashrc diff --git a/.bash_env b/.bash_env new file mode 100644 index 0000000..071d07a --- /dev/null +++ b/.bash_env @@ -0,0 +1,144 @@ +unset BASH_ENV +# we don't need to run more than once +if [[ -v embark_docker_embark_user_BASH_ENV ]]; then + return +fi +export embark_docker_embark_user_BASH_ENV= + +export embark_docker_embark_user_npm_bak_config_prefix=${HOME}/.npm-packages +export npm_config_prefix=$embark_docker_embark_user_npm_bak_config_prefix +export NPM_CONFIG_PREFIX=$npm_config_prefix + +export embark_docker_embark_user_PATH_with_LOCALBIN=${HOME}/.local/bin:$PATH +export embark_docker_embark_user_PATH_with_NPM=$NPM_CONFIG_PREFIX/bin:$embark_docker_embark_user_PATH_with_LOCALBIN +export PATH=$embark_docker_embark_user_PATH_with_NPM + +nac () { + local txtbld=$(tput bold) + local txtrst=$(tput sgr0) + local bldcyn=${txtbld}$(tput setaf 6) + local bldred=${txtbld}$(tput setaf 1) + local ERROR=${bldred}ERROR${txtrst} + if [[ -z "$1" ]]; then + echo "$ERROR: missing node environment name" + return 1 + fi + if [[ ! -d "${HOME}/.local/nodeenv/$1" ]]; then + echo "$ERROR: no \"$1\" environment found in ${HOME}/.local/nodeenv" + return 1 + fi + ____nvm_unload + ____denac + export PATH=$embark_docker_embark_user_PATH_with_LOCALBIN + . ${HOME}/.local/nodeenv/$1/bin/activate + if [[ $? != 0 ]]; then + ____denac + return 1 + fi + alias deactivate_node='__denac' + case $- in + *i*) __npm_completion \ + && echo "Now using NODEENV node $(node --version) (npm v$(npm --version))";; + esac +} +export -f nac + +__nac () { + local curr_word="${COMP_WORDS[COMP_CWORD]}" + local -a envs=( $(compgen -d -- "${HOME}/.local/nodeenv/$curr_word") ) + COMPREPLY=( "${envs[@]##*/}" ) + return 0 +} +export -f __nac +complete -F __nac nac + +__denac () { + ____denac + case $- in + *i*) echo "Now using system node $(node --version) (npm v$(npm --version))";; + esac +} +export -f __denac + +____denac () { + unalias deactivate_node &> /dev/null + if type deactivate_node &> /dev/null; then + deactivate_node + fi + export PATH=$embark_docker_embark_user_PATH_with_NPM +} +export -f ____denac + +__npm_completion () { + . <(npm completion) +} +export -f __npm_completion + +nvm_load () { + __nvm_load + alias nvm_load='nvm' + alias nvm='__nvm_mask' + __nvm_mask () { + case $* in + unload*) shift 1; __nvm_unload;; + *) unalias nvm; nvm "$@"; alias nvm='__nvm_mask';; + esac + } + export -f __nvm_mask +} +export -f nvm_load + +__nvm_load () { + ____nvm_unload + ____denac + export PATH=$embark_docker_embark_user_PATH_with_LOCALBIN + . ${HOME}/.bash_env_nvm_load + . ${HOME}/.nvm/nvm.sh &> /dev/null + if [[ (-z $(nvm alias default)) && ($1 != "no-auto-lts") ]]; then + case $- in + *i*) nvm install --lts;; + *) nvm install --lts &> /dev/null;; + esac + local auto_lts= + fi + case $- in + *i*) __npm_completion;; + esac + if [[ (! -v auto_lts) \ + && ($(which node) = "${HOME}/.nvm/versions/"*) ]]; then + case $- in + *i*) echo "Now using NVM node $(node --version) (npm v$(npm --version))";; + esac + fi +} +export -f __nvm_load + +__nvm_unload () { + ____nvm_unload + case $- in + *i*) echo "Now using system node $(node --version) (npm v$(npm --version))";; + esac +} +export -f __nvm_unload + +____nvm_unload () { + unalias nvm_load &> /dev/null + unalias nvm &> /dev/null + unset __nvm_mask + if type nvm &> /dev/null; then + nvm unload + fi + export PATH=$embark_docker_embark_user_PATH_with_NPM + . ${HOME}/.bash_env_nvm_unload +} +export -f ____nvm_unload + +simple_nodeenv () { + pushd $PWD &> /dev/null + cd ${HOME}/.local/nodeenv + nodeenv --prebuilt --node $@ + popd &> /dev/null + unalias nac &> /dev/null + nac $2 +} +export -f simple_nodeenv diff --git a/.bash_env_nvm_load b/.bash_env_nvm_load new file mode 100644 index 0000000..b7d09cf --- /dev/null +++ b/.bash_env_nvm_load @@ -0,0 +1,2 @@ +unset npm_config_prefix +unset NPM_CONFIG_PREFIX diff --git a/.bash_env_nvm_unload b/.bash_env_nvm_unload new file mode 100644 index 0000000..5e650f7 --- /dev/null +++ b/.bash_env_nvm_unload @@ -0,0 +1,2 @@ +export npm_config_prefix=$embark_docker_embark_user_npm_bak_config_prefix +export NPM_CONFIG_PREFIX=$npm_config_prefix diff --git a/.bashrc b/.bashrc new file mode 100644 index 0000000..b1df03c --- /dev/null +++ b/.bashrc @@ -0,0 +1 @@ +. ${HOME}/.bash_env diff --git a/dot.npmrc b/.npmrc similarity index 100% rename from dot.npmrc rename to .npmrc diff --git a/dot.bash_env b/dot.bash_env deleted file mode 100644 index 22ab459..0000000 --- a/dot.bash_env +++ /dev/null @@ -1,132 +0,0 @@ -unset BASH_ENV -# we don't need to run more than once -if [[ -v __BASH_ENV ]]; then - return -fi -export __BASH_ENV= -# if we're not pid 1, then it depends... -if [[ $$ != 1 ]]; then - # if we didn't get loaded via .bashrc then we don't run, but a user could - # force the run with: `export BASH_ENV_OK_PID_NOT1_NOT_BASHRC=` - if [[ (! -v __BASHRC) && (! -v BASH_ENV_OK_PID_NOT_1_NOT_BASHRC) ]]; then - return - fi -fi -unset __BASHRC -# if we haven't run yet, then if we're pid 1, or we're not pid 1 but got loaded -# via .bashrc, we continue... - -unset _npm_bak_config_prefix -unset npm_config_prefix -unset NPM_CONFIG_PREFIX - -export _npm_bak_config_prefix=/home/embark/.npm-packages -export npm_config_prefix=$_npm_bak_config_prefix -export NPM_CONFIG_PREFIX=$npm_config_prefix - -export PATH=${_PATH:-$PATH} -unset _PATH -unset __PATH - -export _PATH=/home/embark/.local/bin:$PATH -export __PATH=$NPM_CONFIG_PREFIX/bin:$_PATH -export PATH=$__PATH - -unset _denac -_denac () { - if type deactivate_node &> /dev/null; then - deactivate_node - fi - - export PATH=$__PATH -} -export -f _denac - -unset denac -denac () { - _denac - case $- in - *i*) echo "Now using system version of node: $(node --version) (npm v$(npm --version))";; - esac -} -export -f denac - -unset _nac -_nac () { - local curr_arg; - curr_arg=${COMP_WORDS[COMP_CWORD]} - local envs=$(basename /home/embark/.local/nodeenv/$2*) - if [ $envs == $(echo $2*) ]; then - COMPREPLY=() - else - COMPREPLY=( $(basename /home/embark/.local/nodeenv/$2*) ); - fi -} -export -f _nac - -unset nac -nac () { - local txtbld=$(tput bold) - local txtrst=$(tput sgr0) - local bldcyn=${txtbld}$(tput setaf 6) - local bldred=${txtbld}$(tput setaf 1) - local ERROR=${bldred}ERROR${txtrst} - - if [[ -z "$1" ]]; then - echo "$ERROR: missing node environment name" - return 1 - fi - - if [[ ! -d "/home/embark/.local/nodeenv/$1" ]]; then - echo "$ERROR: no \"$1\" environment found in \/home/embark/.local/nodeenv" - return 1 - fi - - _denac - _nvm_unload - export PATH=$_PATH - - . /home/embark/.local/nodeenv/$1/bin/activate - case $- in - *i*) echo "Now using NODEENV node $(node --version) (npm v$(npm --version))";; - esac -} -export -f nac -complete -F _nac nac - -unset simple_nodeenv -simple_nodeenv () { - pushd $PWD &> /dev/null - cd /home/embark/.local/nodeenv - $(which nodeenv) --prebuilt --node $@ - popd &> /dev/null - nac $2 -} -export -f simple_nodeenv - -unset npm_completion -npm_completion () { - . <(npm completion) -} -export -f npm_completion - -unset nvm_load -nvm_load () { - . /home/embark/.bash_env_nvm_load -} -export -f nvm_load - -unset _nvm_unload -_nvm_unload () { - . /home/embark/.bash_env_nvm_unload -} -export -f _nvm_unload - -unset nvm_unload -nvm_unload () { - _nvm_unload - case $- in - *i*) echo "Now using system version of node: $(node --version) (npm v$(npm --version))";; - esac -} -export -f nvm_unload diff --git a/dot.bash_env_nvm_load b/dot.bash_env_nvm_load deleted file mode 100644 index 71137e0..0000000 --- a/dot.bash_env_nvm_load +++ /dev/null @@ -1,26 +0,0 @@ -_nvm_unload -_denac -unset npm_config_prefix -unset NPM_CONFIG_PREFIX -export PATH=$_PATH - -. /home/embark/.nvm/nvm.sh &> /dev/null - -if [[ (-z $(nvm alias default)) && ($1 != "no-auto-lts") ]]; then - case $- in - *i*) nvm install --lts;; - *) nvm install --lts &> /dev/null;; - esac - local auto_lts= -fi - -case $- in - *i*) npm_completion;; -esac - -if [[ (! -v auto_lts) \ - && ($(which node) = "/home/embark/.nvm/versions/"*) ]]; then - case $- in - *i*) echo "Now using NVM node $(node --version) (npm v$(npm --version))";; - esac -fi diff --git a/dot.bash_env_nvm_unload b/dot.bash_env_nvm_unload deleted file mode 100644 index 0a09f7e..0000000 --- a/dot.bash_env_nvm_unload +++ /dev/null @@ -1,7 +0,0 @@ -if type nvm &> /dev/null; then - nvm unload -fi - -export npm_config_prefix=$_npm_bak_config_prefix -export NPM_CONFIG_PREFIX=$npm_config_prefix -export PATH=$__PATH diff --git a/dot.bashrc b/dot.bashrc deleted file mode 100644 index afdf556..0000000 --- a/dot.bashrc +++ /dev/null @@ -1,2 +0,0 @@ -export __BASHRC= -. /home/embark/.bash_env From 34096b1f132b2d9b1bd07a49a859f272ddf75b25 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Tue, 24 Jul 2018 15:24:37 -0500 Subject: [PATCH 08/76] docker + user entry --- docker-entrypoint.sh | 3 +-- user-entrypoint.sh | 3 +++ 2 files changed, 4 insertions(+), 2 deletions(-) mode change 100644 => 100755 docker-entrypoint.sh create mode 100755 user-entrypoint.sh diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh old mode 100644 new mode 100755 index 5ac10d8..92dd4b7 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -1,7 +1,6 @@ #!/bin/bash -. /home/embark/.bash_env export BASH_ENV=/home/embark/.bash_env chmod a+w /dev/std* -exec su-exec embark "$@" +exec su-exec embark user-entrypoint.sh "$@" diff --git a/user-entrypoint.sh b/user-entrypoint.sh new file mode 100755 index 0000000..5fc4448 --- /dev/null +++ b/user-entrypoint.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +exec "$@" From ef84fdc4918aff4564d65c5774e2c8856aa27f72 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Tue, 24 Jul 2018 15:24:44 -0500 Subject: [PATCH 09/76] script (not run during build) for adding some cli tools --- install-extras.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100755 install-extras.sh diff --git a/install-extras.sh b/install-extras.sh new file mode 100755 index 0000000..26b4362 --- /dev/null +++ b/install-extras.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +apt-get update +apt-get install -y \ + less \ + lsof \ + net-tools \ + parallel \ + silversearcher-ag \ + tmux \ + vim + +echo will cite | parallel --bibtex >/dev/null From 74451acf552022bcb8b89c74d9129f26cb58b12c Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Tue, 24 Jul 2018 15:25:46 -0500 Subject: [PATCH 10/76] no need to unset --- run.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/run.sh b/run.sh index e80aef9..d6ddd04 100755 --- a/run.sh +++ b/run.sh @@ -1,7 +1,5 @@ #!/usr/bin/env bash -unset run_embark_docker - run_embark_docker () { local oldopts="" case $- in From 9bd9bb1064e0be6769343c227080028ca8dafbf6 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Tue, 24 Jul 2018 15:25:55 -0500 Subject: [PATCH 11/76] prefer $PWD to $(pwd) --- run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run.sh b/run.sh index d6ddd04..58fc0ad 100755 --- a/run.sh +++ b/run.sh @@ -62,7 +62,7 @@ run_embark_docker () { fi fi - local EMBARK_DOCKER_MOUNT_SOURCE=${EMBARK_DOCKER_MOUNT_DIR:-$(pwd)} + local EMBARK_DOCKER_MOUNT_SOURCE=${EMBARK_DOCKER_MOUNT_DIR:-$PWD} local EMBARK_DOCKER_MOUNT_TARGET=${EMBARK_DOCKER_MOUNT_DIR:-/dapp} local EMBARK_DOCKER_IMAGE=${EMBARK_DOCKER_IMAGE:-statusim/embark} local EMBARK_DOCKER_TAG=${EMBARK_DOCKER_TAG:-latest} From 7356aed639a7579b1ff7cced627a31796ba74013 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Tue, 24 Jul 2018 15:26:07 -0500 Subject: [PATCH 12/76] forward host TERM value to container --- run.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/run.sh b/run.sh index 58fc0ad..a6ac2c3 100755 --- a/run.sh +++ b/run.sh @@ -80,6 +80,7 @@ run_embark_docker () { -p 30301:30301/udp \ -p 30303:30303 \ -v ${EMBARK_DOCKER_MOUNT_SOURCE}:${EMBARK_DOCKER_MOUNT_TARGET} \ + -e "TERM=${TERM}" \ ${EMBARK_DOCKER_IMAGE}:${EMBARK_DOCKER_TAG} \ "$@" From 1eac4c861be9903f9149bdc435050a59c25f43d9 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Tue, 24 Jul 2018 15:26:32 -0500 Subject: [PATCH 13/76] multi-stage build --- Dockerfile | 175 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 104 insertions(+), 71 deletions(-) diff --git a/Dockerfile b/Dockerfile index 76db571..9a6a447 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,102 +1,135 @@ -FROM node:8.11.3-stretch +# multi-stage builder images +# ------------------------------------------------------------------------------ -MAINTAINER Andre Medeiros +FROM node:8.11.3-stretch as builder-base -# Embark: 8000 8545 8546 -# Go Ethereum: 30301/udp 30303 8545 8546 (when proxied: 8555 8556) -# IPFS: 5001 8080 -# Swarm: 8500 -EXPOSE 5001 8000 8080 8500 8545 8546 8555 8556 30301/udp 30303 - -ARG SUEXEC_VERSION -ENV SUEXEC_VERSION=${SUEXEC_VERSION:-v0.2} -# Install su-exec -RUN cd /tmp \ - && git clone --branch ${SUEXEC_VERSION} --depth 1 \ - https://github.com/ncopa/su-exec.git 2> /dev/null \ - && cd su-exec \ - && make \ - && cp su-exec /usr/local/bin/ \ - && cd .. \ - && rm -rf su-exec +# ------------------------------------------------------------------------------ +FROM builder-base as builder-geth ARG GETH_VERSION ENV GETH_VERSION=${GETH_VERSION:-1.8.11-dea1ce05} -# Install geth -RUN curl -fsSLO --compressed "https://gethstore.blob.core.windows.net/builds/geth-alltools-linux-amd64-${GETH_VERSION}.tar.gz" \ - && tar -xvzf "geth-alltools-linux-amd64-${GETH_VERSION}.tar.gz" \ - && for geth_tool in \ - abigen \ - bootnode \ - evm \ - geth \ - puppeth \ - rlpdump \ - swarm \ - wnode \ - ; do \ - cp "geth-alltools-linux-amd64-${GETH_VERSION}/${geth_tool}" "/usr/local/bin/${geth_tool}"; \ - done \ - && rm -rf "geth-alltools-linux-amd64-${GETH_VERSION}*" +RUN export url="https://gethstore.blob.core.windows.net/builds" \ + && export platform="geth-alltools-linux-amd64" \ + && curl -fsSLO --compressed "${url}/${platform}-${GETH_VERSION}.tar.gz" \ + && tar -xvzf geth-alltools* \ + && rm geth-alltools*/COPYING +# ------------------------------------------------------------------------------ + +FROM builder-base as builder-ipfs ARG IPFS_VERSION ENV IPFS_VERSION=${IPFS_VERSION:-0.4.15} -# Install ipfs -RUN curl -fsSLO --compressed "https://dist.ipfs.io/go-ipfs/v${IPFS_VERSION}/go-ipfs_v${IPFS_VERSION}_linux-amd64.tar.gz" \ - && tar -xvzf "go-ipfs_v${IPFS_VERSION}_linux-amd64.tar.gz" \ - && cp go-ipfs/ipfs /usr/local/bin/ipfs \ - && rm -rf go-ipfs "go-ipfs_v${IPFS_VERSION}_linux-amd64.tar.gz" +RUN export url="https://dist.ipfs.io/go-ipfs" \ + && export ver="v${IPFS_VERSION}/go-ipfs_v${IPFS_VERSION}" \ + && export platform="linux-amd64" \ + && curl -fsSLO --compressed "${url}/${ver}_${platform}.tar.gz" \ + && tar -xvzf go-ipfs* -# Install pip -RUN curl -fsSLO --compressed "https://bootstrap.pypa.io/get-pip.py" \ +# ------------------------------------------------------------------------------ + +FROM builder-base as builder-micro +ARG MICRO_VERSION +ENV MICRO_VERSION=${MICRO_VERSION:-1.4.0} +RUN export url="https://github.com/zyedidia/micro/releases/download" \ + && export ver="v${MICRO_VERSION}/micro-${MICRO_VERSION}" \ + && export platform="linux64" \ + && curl -fsSLO --compressed "${url}/${ver}-${platform}.tar.gz" \ + && tar -xvzf micro-${MICRO_VERSION}* + +# ------------------------------------------------------------------------------ + +FROM builder-base as builder-suexec +ARG SUEXEC_VERSION +ENV SUEXEC_VERSION=${SUEXEC_VERSION:-v0.2} +RUN git clone --branch ${SUEXEC_VERSION} \ + --depth 1 \ + https://github.com/ncopa/su-exec.git 2> /dev/null \ + && cd su-exec \ + && make + +# final image +# ------------------------------------------------------------------------------ + +FROM builder-base + +LABEL maintainer="Andre Medeiros " + +ARG __CODESET +ARG __LANG +ARG __LANGUAGE +ARG __LC_ALL +RUN export DEBIAN_FRONTEND=noninteractive \ + && apt-get update \ + && apt-get install -y locales \ + && export __CODESET=${__CODESET:-UTF-8} \ + && export __LANG=${__LANG:-en_US.$__CODESET} \ + && export __LANGUAGE=${__LANGUAGE:-en_US:en} \ + && export __LC_ALL=${__LC_ALL:-en_US.$__CODESET} \ + && sed -i \ + -e "s/# ${__LANG} ${__CODESET}/${__LANG} ${__CODESET}/" \ + /etc/locale.gen \ + && locale-gen --purge "${__LANG}" \ + && dpkg-reconfigure locales \ + && update-locale LANG=${__LANG} LANGUAGE=${__LANGUAGE} LC_ALL=${__LC_ALL} \ + && unset DEBIAN_FRONTEND \ + && rm -rf /var/lib/apt/lists/* \ + && adduser --disabled-password --shell /bin/bash --gecos "" embark \ + && mkdir -p /dapp \ + && chown embark:embark /dapp \ + && curl -fsSLO --compressed "https://bootstrap.pypa.io/get-pip.py" \ && python get-pip.py \ && rm get-pip.py - -# Setup unprivileged user -RUN adduser --disabled-password --shell /bin/bash --gecos "" embark \ - && mkdir -p /dapp \ - && mkdir -p /home/embark/.npm-packages \ - && chown embark:embark /dapp /home/embark/.npm-packages -COPY dot.bash_env /home/embark/.bash_env -COPY dot.bash_env_nvm_load /home/embark/.bash_env_nvm_load -COPY dot.bash_env_nvm_unload /home/embark/.bash_env_nvm_unload -COPY dot.bashrc /home/embark/.bashrc -COPY dot.npmrc /home/embark/.npmrc -RUN chown embark:embark /home/embark/.bash_env \ - && chown embark:embark /home/embark/.bashrc \ - && chown embark:embark /home/embark/.npmrc +ENV LANG=${__LANG:-en_US.${__CODESET:-UTF-8}} ARG EMBARK_VERSION ARG GANACHE_VERSION ARG NODEENV_VERSION ARG NVM_VERSION -ENV EMBARK_VERSION=${EMBARK_VERSION:-3.1.5} -ENV GANACHE_VERSION=${GANACHE_VERSION:-6.1.4} -ENV NODEENV_VERSION=${NODEENV_VERSION:-1.3.2} -ENV NVM_VERSION=${NVM_VERSION:-v0.33.11} -# Install tooling and Embark Framework +ENV EMBARK_VERSION=${EMBARK_VERSION:-3.1.5} \ + GANACHE_VERSION=${GANACHE_VERSION:-6.1.4} \ + NODEENV_VERSION=${NODEENV_VERSION:-1.3.2} \ + NVM_VERSION=${NVM_VERSION:-v0.33.11} +COPY --from=builder-ipfs /go-ipfs/ipfs /usr/local/bin/ USER embark SHELL ["/bin/bash", "-c"] WORKDIR /home/embark -RUN . ${HOME}/.bash_env \ - && git clone --branch ${NVM_VERSION} --depth 1 \ - https://github.com/creationix/nvm.git .nvm 2> /dev/null \ +COPY .bash_env \ + .bash_env_nvm_load \ + .bash_env_nvm_unload \ + .bashrc \ + .npmrc \ + ./ +RUN mkdir -p .npm-packages \ + .local/nodeenv \ + && . .bash_env \ && pip install --user nodeenv==${NODEENV_VERSION} \ - && mkdir -p ${HOME}/.local/nodeenv \ - && npm install -g "ganache-cli@${GANACHE_VERSION}" \ + && git clone --branch ${NVM_VERSION} --depth 1 \ + https://github.com/creationix/nvm.git .nvm 2> /dev/null \ && npm install -g "embark@${EMBARK_VERSION}" \ - # Initialize IPFS + "ganache-cli@${GANACHE_VERSION}" \ && ipfs init \ && ipfs config --json Addresses.API '"/ip4/0.0.0.0/tcp/5001"' \ && ipfs config --json Addresses.Gateway '"/ip4/0.0.0.0/tcp/8080"' \ && ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["*"]' \ && ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["GET", "POST", "PUT"]' -# Setup entrypoint and default working directory USER root SHELL ["/bin/sh", "-c"] -COPY docker-entrypoint.sh /usr/local/bin/ -RUN chmod +x /usr/local/bin/docker-entrypoint.sh +WORKDIR / +COPY docker-entrypoint.sh \ + user-entrypoint.sh \ + install-extras.sh \ + /usr/local/bin/ + +WORKDIR /dapp ENTRYPOINT ["docker-entrypoint.sh"] CMD ["embark", "run"] -WORKDIR /dapp +# Embark: 8000 8545 8546 +# Go Ethereum: 30301/udp 30303 8545 8546 (when proxied: 8555 8556) +# IPFS: 5001 8080 +# Swarm: 8500 +EXPOSE 5001 8000 8080 8500 8545 8546 8555 8556 30301/udp 30303 + +COPY --from=builder-geth /geth-alltools* /usr/local/bin/ +COPY --from=builder-micro /micro*/micro /usr/local/bin/ +COPY --from=builder-suexec /su-exec/su-exec /usr/local/bin/ From a6ec833c38f8fb8b6a3919c012162bb6075aca1d Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Tue, 24 Jul 2018 15:38:47 -0500 Subject: [PATCH 14/76] env override for extra run opts --- run.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/run.sh b/run.sh index a6ac2c3..cfd5d4c 100755 --- a/run.sh +++ b/run.sh @@ -65,6 +65,7 @@ run_embark_docker () { local EMBARK_DOCKER_MOUNT_SOURCE=${EMBARK_DOCKER_MOUNT_DIR:-$PWD} local EMBARK_DOCKER_MOUNT_TARGET=${EMBARK_DOCKER_MOUNT_DIR:-/dapp} local EMBARK_DOCKER_IMAGE=${EMBARK_DOCKER_IMAGE:-statusim/embark} + local EMBARK_DOCKER_EXTRA_RUN_OPTS=${EMBARK_DOCKER_EXTRA_RUN_OPTS:-""} local EMBARK_DOCKER_TAG=${EMBARK_DOCKER_TAG:-latest} docker run \ @@ -81,6 +82,7 @@ run_embark_docker () { -p 30303:30303 \ -v ${EMBARK_DOCKER_MOUNT_SOURCE}:${EMBARK_DOCKER_MOUNT_TARGET} \ -e "TERM=${TERM}" \ + "${EMBARK_DOCKER_EXTRA_RUN_OPTS}" \ ${EMBARK_DOCKER_IMAGE}:${EMBARK_DOCKER_TAG} \ "$@" From 7098260ce54e24dee6879cc276487e042b44f8a1 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Tue, 24 Jul 2018 16:39:53 -0500 Subject: [PATCH 15/76] linebreak --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 9a6a447..9b92803 100644 --- a/Dockerfile +++ b/Dockerfile @@ -103,7 +103,8 @@ RUN mkdir -p .npm-packages \ .local/nodeenv \ && . .bash_env \ && pip install --user nodeenv==${NODEENV_VERSION} \ - && git clone --branch ${NVM_VERSION} --depth 1 \ + && git clone --branch ${NVM_VERSION} \ + --depth 1 \ https://github.com/creationix/nvm.git .nvm 2> /dev/null \ && npm install -g "embark@${EMBARK_VERSION}" \ "ganache-cli@${GANACHE_VERSION}" \ From 2a36bee8234b163bf2f8e753fa7d402cacfa160a Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Tue, 24 Jul 2018 17:17:55 -0500 Subject: [PATCH 16/76] provide dummy extra run opts, in case none are provided on the cli --- run.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/run.sh b/run.sh index cfd5d4c..74984c4 100755 --- a/run.sh +++ b/run.sh @@ -62,10 +62,11 @@ run_embark_docker () { fi fi + local dummy="-e __embark_docker_runsh" local EMBARK_DOCKER_MOUNT_SOURCE=${EMBARK_DOCKER_MOUNT_DIR:-$PWD} local EMBARK_DOCKER_MOUNT_TARGET=${EMBARK_DOCKER_MOUNT_DIR:-/dapp} + local EMBARK_DOCKER_EXTRA_RUN_OPTS=${EMBARK_DOCKER_EXTRA_RUN_OPTS:-$dummy} local EMBARK_DOCKER_IMAGE=${EMBARK_DOCKER_IMAGE:-statusim/embark} - local EMBARK_DOCKER_EXTRA_RUN_OPTS=${EMBARK_DOCKER_EXTRA_RUN_OPTS:-""} local EMBARK_DOCKER_TAG=${EMBARK_DOCKER_TAG:-latest} docker run \ From 48b854f7f19f0d163e054c0f849dae16e8c51d1e Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Tue, 24 Jul 2018 17:18:25 -0500 Subject: [PATCH 17/76] simplify use of -e --- run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run.sh b/run.sh index 74984c4..515dc38 100755 --- a/run.sh +++ b/run.sh @@ -82,7 +82,7 @@ run_embark_docker () { -p 30301:30301/udp \ -p 30303:30303 \ -v ${EMBARK_DOCKER_MOUNT_SOURCE}:${EMBARK_DOCKER_MOUNT_TARGET} \ - -e "TERM=${TERM}" \ + -e TERM \ "${EMBARK_DOCKER_EXTRA_RUN_OPTS}" \ ${EMBARK_DOCKER_IMAGE}:${EMBARK_DOCKER_TAG} \ "$@" From bb72888cb981f3340163541a9874129484c9e5fc Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Tue, 24 Jul 2018 17:19:35 -0500 Subject: [PATCH 18/76] prefer ARG w/ defaults vs. ARG+ENV --- Dockerfile | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9b92803..3c2a3ab 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,13 @@ # multi-stage builder images # ------------------------------------------------------------------------------ -FROM node:8.11.3-stretch as builder-base +ARG NODE_TAG=8.11.3-stretch +FROM node:${NODE_TAG} as builder-base # ------------------------------------------------------------------------------ FROM builder-base as builder-geth -ARG GETH_VERSION -ENV GETH_VERSION=${GETH_VERSION:-1.8.11-dea1ce05} +ARG GETH_VERSION=1.8.11-dea1ce05 RUN export url="https://gethstore.blob.core.windows.net/builds" \ && export platform="geth-alltools-linux-amd64" \ && curl -fsSLO --compressed "${url}/${platform}-${GETH_VERSION}.tar.gz" \ @@ -17,8 +17,7 @@ RUN export url="https://gethstore.blob.core.windows.net/builds" \ # ------------------------------------------------------------------------------ FROM builder-base as builder-ipfs -ARG IPFS_VERSION -ENV IPFS_VERSION=${IPFS_VERSION:-0.4.15} +ARG IPFS_VERSION=0.4.15 RUN export url="https://dist.ipfs.io/go-ipfs" \ && export ver="v${IPFS_VERSION}/go-ipfs_v${IPFS_VERSION}" \ && export platform="linux-amd64" \ @@ -28,8 +27,7 @@ RUN export url="https://dist.ipfs.io/go-ipfs" \ # ------------------------------------------------------------------------------ FROM builder-base as builder-micro -ARG MICRO_VERSION -ENV MICRO_VERSION=${MICRO_VERSION:-1.4.0} +ARG MICRO_VERSION=1.4.0 RUN export url="https://github.com/zyedidia/micro/releases/download" \ && export ver="v${MICRO_VERSION}/micro-${MICRO_VERSION}" \ && export platform="linux64" \ @@ -39,8 +37,7 @@ RUN export url="https://github.com/zyedidia/micro/releases/download" \ # ------------------------------------------------------------------------------ FROM builder-base as builder-suexec -ARG SUEXEC_VERSION -ENV SUEXEC_VERSION=${SUEXEC_VERSION:-v0.2} +ARG SUEXEC_VERSION=v0.2 RUN git clone --branch ${SUEXEC_VERSION} \ --depth 1 \ https://github.com/ncopa/su-exec.git 2> /dev/null \ @@ -80,16 +77,8 @@ RUN export DEBIAN_FRONTEND=noninteractive \ && python get-pip.py \ && rm get-pip.py ENV LANG=${__LANG:-en_US.${__CODESET:-UTF-8}} - -ARG EMBARK_VERSION -ARG GANACHE_VERSION -ARG NODEENV_VERSION -ARG NVM_VERSION -ENV EMBARK_VERSION=${EMBARK_VERSION:-3.1.5} \ - GANACHE_VERSION=${GANACHE_VERSION:-6.1.4} \ - NODEENV_VERSION=${NODEENV_VERSION:-1.3.2} \ - NVM_VERSION=${NVM_VERSION:-v0.33.11} COPY --from=builder-ipfs /go-ipfs/ipfs /usr/local/bin/ + USER embark SHELL ["/bin/bash", "-c"] WORKDIR /home/embark @@ -99,6 +88,10 @@ COPY .bash_env \ .bashrc \ .npmrc \ ./ +ARG EMBARK_VERSION=3.1.5 +ARG GANACHE_VERSION=6.1.4 +ARG NODEENV_VERSION=1.3.2 +ARG NVM_VERSION=v0.33.11 RUN mkdir -p .npm-packages \ .local/nodeenv \ && . .bash_env \ From 4a4555c57bb356bc12c256bf3134e31e9a16adbf Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Tue, 24 Jul 2018 17:29:23 -0500 Subject: [PATCH 19/76] linebreak --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 3c2a3ab..b81c3d1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -76,6 +76,7 @@ RUN export DEBIAN_FRONTEND=noninteractive \ && curl -fsSLO --compressed "https://bootstrap.pypa.io/get-pip.py" \ && python get-pip.py \ && rm get-pip.py + ENV LANG=${__LANG:-en_US.${__CODESET:-UTF-8}} COPY --from=builder-ipfs /go-ipfs/ipfs /usr/local/bin/ From aa2b9e485f0466a8aeac2bd94623c04e6649ebfb Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Tue, 24 Jul 2018 17:39:42 -0500 Subject: [PATCH 20/76] decl order --- run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run.sh b/run.sh index 515dc38..b53b09d 100755 --- a/run.sh +++ b/run.sh @@ -63,9 +63,9 @@ run_embark_docker () { fi local dummy="-e __embark_docker_runsh" + local EMBARK_DOCKER_EXTRA_RUN_OPTS=${EMBARK_DOCKER_EXTRA_RUN_OPTS:-$dummy} local EMBARK_DOCKER_MOUNT_SOURCE=${EMBARK_DOCKER_MOUNT_DIR:-$PWD} local EMBARK_DOCKER_MOUNT_TARGET=${EMBARK_DOCKER_MOUNT_DIR:-/dapp} - local EMBARK_DOCKER_EXTRA_RUN_OPTS=${EMBARK_DOCKER_EXTRA_RUN_OPTS:-$dummy} local EMBARK_DOCKER_IMAGE=${EMBARK_DOCKER_IMAGE:-statusim/embark} local EMBARK_DOCKER_TAG=${EMBARK_DOCKER_TAG:-latest} From 7d19051575035e5789f0206e4f30a6bc1a2e5b9d Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Tue, 24 Jul 2018 18:10:48 -0500 Subject: [PATCH 21/76] use a 6+ version of npm --- Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dockerfile b/Dockerfile index b81c3d1..7934423 100644 --- a/Dockerfile +++ b/Dockerfile @@ -92,6 +92,7 @@ COPY .bash_env \ ARG EMBARK_VERSION=3.1.5 ARG GANACHE_VERSION=6.1.4 ARG NODEENV_VERSION=1.3.2 +ARG NPM_VERSION=6.2.0 ARG NVM_VERSION=v0.33.11 RUN mkdir -p .npm-packages \ .local/nodeenv \ @@ -100,6 +101,7 @@ RUN mkdir -p .npm-packages \ && git clone --branch ${NVM_VERSION} \ --depth 1 \ https://github.com/creationix/nvm.git .nvm 2> /dev/null \ + && npm install -g "npm@${NPM_VERSION}" \ && npm install -g "embark@${EMBARK_VERSION}" \ "ganache-cli@${GANACHE_VERSION}" \ && ipfs init \ From 03e4df7222c77d3b68e54c5a2254ed9e26edb715 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Tue, 24 Jul 2018 18:16:00 -0500 Subject: [PATCH 22/76] not using bldcyn --- .bash_env | 1 - 1 file changed, 1 deletion(-) diff --git a/.bash_env b/.bash_env index 071d07a..6a8de06 100644 --- a/.bash_env +++ b/.bash_env @@ -16,7 +16,6 @@ export PATH=$embark_docker_embark_user_PATH_with_NPM nac () { local txtbld=$(tput bold) local txtrst=$(tput sgr0) - local bldcyn=${txtbld}$(tput setaf 6) local bldred=${txtbld}$(tput setaf 1) local ERROR=${bldred}ERROR${txtrst} if [[ -z "$1" ]]; then From bb0dc869d03006e7149941fe189b4e8ce450daed Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Tue, 24 Jul 2018 18:55:40 -0500 Subject: [PATCH 23/76] whitespace --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 52be928..99a468e 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ An exception to this is the NodeJS version, which needs to be updated in the `FR ## Building -Building requires Docker to be installed on your local machine. +Building requires Docker to be installed on your local machine. ### Scripted From ce66114a444923709fd2ef0226f9d70cb46678d2 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Tue, 24 Jul 2018 18:55:54 -0500 Subject: [PATCH 24/76] refer to ARG --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index 99a468e..7dfa4e4 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,7 @@ ## Updating versions * Open `Dockerfile` -* On the `ENV` directive, update necessary versions. - -An exception to this is the NodeJS version, which needs to be updated in the `FROM` directive instead. +* On the `ARG` directives, update necessary versions. ## Building From 759b78970185c3c72bd734c2fc22b60121df1f5f Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Tue, 24 Jul 2018 18:56:07 -0500 Subject: [PATCH 25/76] Quick start --- README.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/README.md b/README.md index 7dfa4e4..7550932 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,40 @@ # Embark for Docker +## Quick start + +In a Bash shell: +``` shell +source <(curl 'https://raw.githubusercontent.com/embark-framework/embark-docker/master/run.sh') +run_embark_docker embark demo +cd embark_demo +run_embark_docker +``` + +With overrides: + +``` shell +export EMBARK_DOCKER_EXTRA_RUN_OPTS='--rm' +export EMBARK_DOCKER_IMAGE=statusim/embark +export EMBARK_DOCKER_TAG=custom +export EMBARK_DOCKERFILE='https://github.com/embark-framework/embark-docker.git#some/branch' +export EMBARK_VERSION='embark-framework/embark#/features/branch' +export NODE_TAG=10.7.0 +export RUNNER='https://raw.githubusercontent.com/embark-framework/embark-docker/some/branch/run.sh' + +docker build \ + -t $EMBARK_DOCKER_IMAGE:$EMBARK_DOCKER_TAG + --build-arg EMBARK_VERSION=$EMBARK_VERSION + --build-arg NODE_TAG=$NODE_TAG + $EMBARK_DOCKERFILE + +source <(curl $RUNNER) +run_embark_docker embark demo +cd embark_demo +run_embark_docker +``` + +Review the [Dockerfile](https://github.com/embark-framework/embark-docker/blob/master/Dockerfile) and [run.sh](https://github.com/embark-framework/embark-docker/blob/master/run.sh#L66-L70) for the full lists of possible overrides. + ## Updating versions * Open `Dockerfile` From d1b9f67cdbaea08847b03b75b4081c97c0038cc9 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Tue, 24 Jul 2018 18:57:50 -0500 Subject: [PATCH 26/76] wording re: overrides --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7550932..be866d4 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ cd embark_demo run_embark_docker ``` -Review the [Dockerfile](https://github.com/embark-framework/embark-docker/blob/master/Dockerfile) and [run.sh](https://github.com/embark-framework/embark-docker/blob/master/run.sh#L66-L70) for the full lists of possible overrides. +Review the [Dockerfile](https://github.com/embark-framework/embark-docker/blob/master/Dockerfile) and [run.sh](https://github.com/embark-framework/embark-docker/blob/master/run.sh#L66-L70) to see all the possible overrides. ## Updating versions From f5bf50b60b3474df0297cdfe67eb3801468e6b26 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Tue, 24 Jul 2018 22:00:41 -0500 Subject: [PATCH 27/76] rm stray / --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index be866d4..d7a0305 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ export EMBARK_DOCKER_EXTRA_RUN_OPTS='--rm' export EMBARK_DOCKER_IMAGE=statusim/embark export EMBARK_DOCKER_TAG=custom export EMBARK_DOCKERFILE='https://github.com/embark-framework/embark-docker.git#some/branch' -export EMBARK_VERSION='embark-framework/embark#/features/branch' +export EMBARK_VERSION='embark-framework/embark#features/branch' export NODE_TAG=10.7.0 export RUNNER='https://raw.githubusercontent.com/embark-framework/embark-docker/some/branch/run.sh' From 63563f25fd00a7ed5d9b68ff6ac40b47d81fb87d Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Tue, 24 Jul 2018 22:02:27 -0500 Subject: [PATCH 28/76] rev cont lines in README --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d7a0305..263c73d 100644 --- a/README.md +++ b/README.md @@ -22,10 +22,10 @@ export NODE_TAG=10.7.0 export RUNNER='https://raw.githubusercontent.com/embark-framework/embark-docker/some/branch/run.sh' docker build \ - -t $EMBARK_DOCKER_IMAGE:$EMBARK_DOCKER_TAG - --build-arg EMBARK_VERSION=$EMBARK_VERSION - --build-arg NODE_TAG=$NODE_TAG - $EMBARK_DOCKERFILE + --build-arg EMBARK_VERSION=$EMBARK_VERSION \ + --build-arg NODE_TAG=$NODE_TAG \ + -t $EMBARK_DOCKER_IMAGE:$EMBARK_DOCKER_TAG \ + $EMBARK_DOCKERFILE source <(curl $RUNNER) run_embark_docker embark demo From 987799ff478ed565d4cca729512142b628ecb8c4 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Tue, 24 Jul 2018 22:04:40 -0500 Subject: [PATCH 29/76] wording --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 263c73d..9dd2516 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ cd embark_demo run_embark_docker ``` -Review the [Dockerfile](https://github.com/embark-framework/embark-docker/blob/master/Dockerfile) and [run.sh](https://github.com/embark-framework/embark-docker/blob/master/run.sh#L66-L70) to see all the possible overrides. +Review the [Dockerfile](https://github.com/embark-framework/embark-docker/blob/master/Dockerfile) and [run.sh](https://github.com/embark-framework/embark-docker/blob/master/run.sh#L66-L70) for all possible overrides. ## Updating versions From 93bea147ce430b7f4a4fe71190668c09853c1fa5 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Tue, 24 Jul 2018 22:27:03 -0500 Subject: [PATCH 30/76] shortcuts --- README.md | 37 +++++++++++++++++++++++++++++++++---- run.sh | 13 ++++++++++--- 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 9dd2516..7a4692d 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,9 @@ In a Bash shell: ``` shell source <(curl 'https://raw.githubusercontent.com/embark-framework/embark-docker/master/run.sh') -run_embark_docker embark demo +run_embark demo cd embark_demo -run_embark_docker +run_embark ``` With overrides: @@ -28,13 +28,42 @@ docker build \ $EMBARK_DOCKERFILE source <(curl $RUNNER) -run_embark_docker embark demo +run_embark demo cd embark_demo -run_embark_docker +run_embark ``` Review the [Dockerfile](https://github.com/embark-framework/embark-docker/blob/master/Dockerfile) and [run.sh](https://github.com/embark-framework/embark-docker/blob/master/run.sh#L66-L70) for all possible overrides. +### Shortcuts + +The following are equivalent: + +``` shell +run_embark demo +``` +``` shell +run_embark embark demo +``` + +These are also equivlent: + +``` shell +run_embark +``` +``` shell +run_embark embark run +``` + +Other `embark` commands and non-embark commands should be indicated explicitly: + +``` shell +run_embark embark version +``` +``` shell +run_embark ps -ef +``` + ## Updating versions * Open `Dockerfile` diff --git a/run.sh b/run.sh index b53b09d..68e0816 100755 --- a/run.sh +++ b/run.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -run_embark_docker () { +run_embark () { local oldopts="" case $- in *e*) oldopts="set -e";; @@ -69,6 +69,13 @@ run_embark_docker () { local EMBARK_DOCKER_IMAGE=${EMBARK_DOCKER_IMAGE:-statusim/embark} local EMBARK_DOCKER_TAG=${EMBARK_DOCKER_TAG:-latest} + local -a cmd= + if [[ "$1" = "demo" ]]; then + cmd=( $(echo "embark $@") ) + else + cmd=( $(echo "$@") ) + fi + docker run \ -it \ -p 5001:5001 \ @@ -85,7 +92,7 @@ run_embark_docker () { -e TERM \ "${EMBARK_DOCKER_EXTRA_RUN_OPTS}" \ ${EMBARK_DOCKER_IMAGE}:${EMBARK_DOCKER_TAG} \ - "$@" + "${cmd[@]}" local docker_exit_status=$? @@ -103,5 +110,5 @@ run_embark_docker () { } if [[ "$0" = "$BASH_SOURCE" ]]; then - run_embark_docker "$@" + run_embark "$@" fi From 66b36740b0a99da11d2f66f859b327a7d44b3c65 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Wed, 25 Jul 2018 10:13:46 -0500 Subject: [PATCH 31/76] nac sets up alias denac, ____denac unaliases denac --- .bash_env | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.bash_env b/.bash_env index 6a8de06..b3e2231 100644 --- a/.bash_env +++ b/.bash_env @@ -34,6 +34,7 @@ nac () { ____denac return 1 fi + alias denac='deactivate_node' alias deactivate_node='__denac' case $- in *i*) __npm_completion \ @@ -60,6 +61,7 @@ __denac () { export -f __denac ____denac () { + unalias denac &> /dev/null unalias deactivate_node &> /dev/null if type deactivate_node &> /dev/null; then deactivate_node From 32131f0bca7bb3303cbb2bb8afdd35147dc63c21 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Wed, 25 Jul 2018 11:49:45 -0500 Subject: [PATCH 32/76] chown embark user's dotfiles --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 7934423..85b4342 100644 --- a/Dockerfile +++ b/Dockerfile @@ -83,7 +83,8 @@ COPY --from=builder-ipfs /go-ipfs/ipfs /usr/local/bin/ USER embark SHELL ["/bin/bash", "-c"] WORKDIR /home/embark -COPY .bash_env \ +COPY --chown=embark:embark \ + .bash_env \ .bash_env_nvm_load \ .bash_env_nvm_unload \ .bashrc \ From 1cd56d6f4c87eb61175160ca4342ba5aff53dc49 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Wed, 25 Jul 2018 11:50:07 -0500 Subject: [PATCH 33/76] env var NODE_VERSION should reflect effects of nvm, nodeenv --- .bash_env | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.bash_env b/.bash_env index b3e2231..c80126d 100644 --- a/.bash_env +++ b/.bash_env @@ -34,11 +34,12 @@ nac () { ____denac return 1 fi + export NODE_VERSION=$(node --version) alias denac='deactivate_node' alias deactivate_node='__denac' case $- in *i*) __npm_completion \ - && echo "Now using NODEENV node $(node --version) (npm v$(npm --version))";; + ; echo "Now using NODEENV node $NODE_VERSION (npm v$(npm --version))";; esac } export -f nac @@ -67,6 +68,7 @@ ____denac () { deactivate_node fi export PATH=$embark_docker_embark_user_PATH_with_NPM + export NODE_VERSION=$(node --version) } export -f ____denac @@ -84,6 +86,7 @@ nvm_load () { unload*) shift 1; __nvm_unload;; *) unalias nvm; nvm "$@"; alias nvm='__nvm_mask';; esac + export NODE_VERSION=$(node --version) } export -f __nvm_mask } @@ -107,8 +110,9 @@ __nvm_load () { esac if [[ (! -v auto_lts) \ && ($(which node) = "${HOME}/.nvm/versions/"*) ]]; then + export NODE_VERSION=$(node --version) case $- in - *i*) echo "Now using NVM node $(node --version) (npm v$(npm --version))";; + *i*) echo "Now using NVM node $NODE_VERSION (npm v$(npm --version))";; esac fi } @@ -117,7 +121,7 @@ export -f __nvm_load __nvm_unload () { ____nvm_unload case $- in - *i*) echo "Now using system node $(node --version) (npm v$(npm --version))";; + *i*) echo "Now using system node $NODE_VERSION (npm v$(npm --version))";; esac } export -f __nvm_unload @@ -131,6 +135,7 @@ ____nvm_unload () { fi export PATH=$embark_docker_embark_user_PATH_with_NPM . ${HOME}/.bash_env_nvm_unload + export NODE_VERSION=$(node --version) } export -f ____nvm_unload From c9676b4a1b88905618f356088612412554ec1ca7 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Wed, 25 Jul 2018 15:16:44 -0500 Subject: [PATCH 34/76] auto prefix all embark commands --- run.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/run.sh b/run.sh index 68e0816..dca0d73 100755 --- a/run.sh +++ b/run.sh @@ -75,6 +75,10 @@ run_embark () { else cmd=( $(echo "$@") ) fi + case $1 in + -V|--version|-h|--help|new|demo|build|run|blockchain|simulator|test|\ + reset|graph|upload|version) cmd=( "embark" "$cmd" );; + esac docker run \ -it \ From 58ece39cfac5da0d68b7ccbd18f81272dfb8f25a Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Wed, 25 Jul 2018 15:16:58 -0500 Subject: [PATCH 35/76] properly handle $@ --- run.sh | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/run.sh b/run.sh index dca0d73..7096314 100755 --- a/run.sh +++ b/run.sh @@ -69,12 +69,7 @@ run_embark () { local EMBARK_DOCKER_IMAGE=${EMBARK_DOCKER_IMAGE:-statusim/embark} local EMBARK_DOCKER_TAG=${EMBARK_DOCKER_TAG:-latest} - local -a cmd= - if [[ "$1" = "demo" ]]; then - cmd=( $(echo "embark $@") ) - else - cmd=( $(echo "$@") ) - fi + local -a cmd=( "$@" ) case $1 in -V|--version|-h|--help|new|demo|build|run|blockchain|simulator|test|\ reset|graph|upload|version) cmd=( "embark" "$cmd" );; From 59c4e76208861133c85b046d1063a2b0510d2dbd Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Wed, 25 Jul 2018 15:17:31 -0500 Subject: [PATCH 36/76] rev shortcuts --- README.md | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7a4692d..8162e20 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,19 @@ Review the [Dockerfile](https://github.com/embark-framework/embark-docker/blob/m ### Shortcuts -The following are equivalent: +These are equivlent: + +``` shell +run_embark +``` +``` shell +run_embark run +``` +``` shell +run_embark embark run +``` + +The following are also equivalent: ``` shell run_embark demo @@ -46,10 +58,10 @@ run_embark demo run_embark embark demo ``` -These are also equivlent: +The same is true for the rest of the `embark` commands. To see the full list: ``` shell -run_embark +run_embark --help ``` ``` shell run_embark embark run From 489d8554084296c048877d12bb02f816e801283b Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Wed, 25 Jul 2018 15:17:39 -0500 Subject: [PATCH 37/76] explain compound commands --- README.md | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 8162e20..51afe70 100644 --- a/README.md +++ b/README.md @@ -63,19 +63,64 @@ The same is true for the rest of the `embark` commands. To see the full list: ``` shell run_embark --help ``` -``` shell -run_embark embark run -``` -Other `embark` commands and non-embark commands should be indicated explicitly: +### Compound commands + +A single command with options can be supplied directly: ``` shell -run_embark embark version +run_embark bash ``` ``` shell run_embark ps -ef ``` +Compound commands should be passed to `bash -[i]c`: + +``` shell +run_embark bash -c 'exec bash << "SCRIPT" + +simple_nodeenv 10.7.0 my_node +node --version +echo $(which node) +npm i -g http-server +exec http-server -p 10000 + +SCRIPT +' +``` + +When executing compound commands via `docer exec` in a running embark +container, `su-exec` and `bash -ic` can be used together: + +``` shell +docker exec -it su-exec embark \ + bash -ic 'exec bash << "SCRIPT" + +simple_nodeenv 10.7.0 my_other_node +npm i -g http-server +exec http-server -p 10001 + +SCRIPT +' +``` + +Alternatively, to go non-interactive, manually source the embark user's +`.bash_env`: + +``` shell +docker exec -it su-exec embark \ + bash -c 'exec bash << "SCRIPT" + +. ~/.bash_env +simple_nodeenv 10.7.0 more_nodez +npm i -g http-server +exec http-server -p 10002 + +SCRIPT +' +``` + ## Updating versions * Open `Dockerfile` From 9ca2c457fe9fcd620ffc2c107452f59e03a0fe5f Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Wed, 25 Jul 2018 15:17:59 -0500 Subject: [PATCH 38/76] be careful re: quotes and shell vars --- .bash_env | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.bash_env b/.bash_env index c80126d..f4b5be1 100644 --- a/.bash_env +++ b/.bash_env @@ -82,7 +82,7 @@ nvm_load () { alias nvm_load='nvm' alias nvm='__nvm_mask' __nvm_mask () { - case $* in + case "$*" in unload*) shift 1; __nvm_unload;; *) unalias nvm; nvm "$@"; alias nvm='__nvm_mask';; esac @@ -142,9 +142,12 @@ export -f ____nvm_unload simple_nodeenv () { pushd $PWD &> /dev/null cd ${HOME}/.local/nodeenv - nodeenv --prebuilt --node $@ + nodeenv --prebuilt --node "$@" + if [[ $? != 0 ]]; then + popd &> /dev/null + return 1 + fi popd &> /dev/null - unalias nac &> /dev/null - nac $2 + nac "$2" } export -f simple_nodeenv From ed3677b2ce8515bd1b5a78bedeb32033664cdfc0 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Wed, 25 Jul 2018 15:52:06 -0500 Subject: [PATCH 39/76] pass $1 to __nvm_load --- .bash_env | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.bash_env b/.bash_env index f4b5be1..a1b3dec 100644 --- a/.bash_env +++ b/.bash_env @@ -78,7 +78,7 @@ __npm_completion () { export -f __npm_completion nvm_load () { - __nvm_load + __nvm_load $1 alias nvm_load='nvm' alias nvm='__nvm_mask' __nvm_mask () { From 3848fc68a62a0313ad66344fb7c89d7a45c371b9 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Wed, 25 Jul 2018 15:52:49 -0500 Subject: [PATCH 40/76] formatting --- README.md | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 51afe70..cb3a2e7 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,11 @@ cd embark_demo run_embark ``` -Review the [Dockerfile](https://github.com/embark-framework/embark-docker/blob/master/Dockerfile) and [run.sh](https://github.com/embark-framework/embark-docker/blob/master/run.sh#L66-L70) for all possible overrides. +Review the +[Dockerfile](https://github.com/embark-framework/embark-docker/blob/master/Dockerfile) +and +[run.sh](https://github.com/embark-framework/embark-docker/blob/master/run.sh#L66-L70) +for all possible overrides. ### Shortcuts @@ -142,16 +146,19 @@ To release, add `--release` as a parameter of the build script. ### Manually -Building and releasing manually isn't too hard either, but there are a couple steps. +Building and releasing manually isn't too hard either, but there are a couple +steps. #### Tags -To facilitate the images being found, we tag them with the following rules (as an example, the `3.1.5` version will be used.) +To facilitate the images being found, we tag them with the following rules (as +an example, the `3.1.5` version will be used.) - Tag with `statusim/embark:latest` if `3.1.5` is the latest version. - Tag with `statusim/embark:3.1.5` - Tag with `statusim/embark:3.1` if `3.1.5` is the highest patch level on `3.1` -- Tag with `statusim/embark:3` if `3.1.5` is the highest minor and patch level on `3` +- Tag with `statusim/embark:3` if `3.1.5` is the highest minor and patch level + on `3` #### Generating the image @@ -179,7 +186,8 @@ $ ruby script/build --release ### Manual -Pushing the tags manually implies that the image has been previously built. To push your local images, run: +Pushing the tags manually implies that the image has been previously built. To +push your local images, run: ``` docker push statusim/embark:version From ba486ee0c49868bc61e2f6d47cffeb642c1f6b28 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Wed, 25 Jul 2018 15:52:57 -0500 Subject: [PATCH 41/76] rev examples --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index cb3a2e7..6bc81c1 100644 --- a/README.md +++ b/README.md @@ -101,8 +101,7 @@ container, `su-exec` and `bash -ic` can be used together: docker exec -it su-exec embark \ bash -ic 'exec bash << "SCRIPT" -simple_nodeenv 10.7.0 my_other_node -npm i -g http-server +nac my_node exec http-server -p 10001 SCRIPT @@ -117,7 +116,9 @@ docker exec -it su-exec embark \ bash -c 'exec bash << "SCRIPT" . ~/.bash_env -simple_nodeenv 10.7.0 more_nodez +nvm_load no-auto-lts +nvm install v10.6.0 +echo $(which node) npm i -g http-server exec http-server -p 10002 From cc1a63c0968de6fba1f4f56fffc87dcf51e6f66f Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Wed, 25 Jul 2018 16:45:00 -0500 Subject: [PATCH 42/76] rm unnecessary shift --- .bash_env | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.bash_env b/.bash_env index a1b3dec..024eeae 100644 --- a/.bash_env +++ b/.bash_env @@ -83,7 +83,7 @@ nvm_load () { alias nvm='__nvm_mask' __nvm_mask () { case "$*" in - unload*) shift 1; __nvm_unload;; + unload*) __nvm_unload;; *) unalias nvm; nvm "$@"; alias nvm='__nvm_mask';; esac export NODE_VERSION=$(node --version) From df82c1cc448af13c9dd95ed927a3c68ee8fa5a86 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Wed, 25 Jul 2018 19:15:53 -0500 Subject: [PATCH 43/76] fix things (spaces, cont lines) causing editor to weirdly re/indent --- .bash_env | 22 ++++++++++------------ run.sh | 6 +++--- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/.bash_env b/.bash_env index 024eeae..550c2a2 100644 --- a/.bash_env +++ b/.bash_env @@ -38,8 +38,7 @@ nac () { alias denac='deactivate_node' alias deactivate_node='__denac' case $- in - *i*) __npm_completion \ - ; echo "Now using NODEENV node $NODE_VERSION (npm v$(npm --version))";; + *i*) __npm_completion; echo "Now using NODEENV node $NODE_VERSION (npm v$(npm --version))" ;; esac } export -f nac @@ -56,7 +55,7 @@ complete -F __nac nac __denac () { ____denac case $- in - *i*) echo "Now using system node $(node --version) (npm v$(npm --version))";; + *i*) echo "Now using system node $(node --version) (npm v$(npm --version))" ;; esac } export -f __denac @@ -83,8 +82,8 @@ nvm_load () { alias nvm='__nvm_mask' __nvm_mask () { case "$*" in - unload*) __nvm_unload;; - *) unalias nvm; nvm "$@"; alias nvm='__nvm_mask';; + unload*) __nvm_unload ;; + *) unalias nvm; nvm "$@"; alias nvm='__nvm_mask' ;; esac export NODE_VERSION=$(node --version) } @@ -100,19 +99,18 @@ __nvm_load () { . ${HOME}/.nvm/nvm.sh &> /dev/null if [[ (-z $(nvm alias default)) && ($1 != "no-auto-lts") ]]; then case $- in - *i*) nvm install --lts;; - *) nvm install --lts &> /dev/null;; + *i*) nvm install --lts ;; + *) nvm install --lts &> /dev/null ;; esac local auto_lts= fi case $- in - *i*) __npm_completion;; + *i*) __npm_completion ;; esac - if [[ (! -v auto_lts) \ - && ($(which node) = "${HOME}/.nvm/versions/"*) ]]; then + if [[ (! -v auto_lts) && ($(which node) = "${HOME}/.nvm/versions/"*) ]]; then export NODE_VERSION=$(node --version) case $- in - *i*) echo "Now using NVM node $NODE_VERSION (npm v$(npm --version))";; + *i*) echo "Now using NVM node $NODE_VERSION (npm v$(npm --version))" ;; esac fi } @@ -121,7 +119,7 @@ export -f __nvm_load __nvm_unload () { ____nvm_unload case $- in - *i*) echo "Now using system node $NODE_VERSION (npm v$(npm --version))";; + *i*) echo "Now using system node $NODE_VERSION (npm v$(npm --version))" ;; esac } export -f __nvm_unload diff --git a/run.sh b/run.sh index 7096314..99468da 100755 --- a/run.sh +++ b/run.sh @@ -3,8 +3,8 @@ run_embark () { local oldopts="" case $- in - *e*) oldopts="set -e";; - *) oldopts="set +e";; + *e*) oldopts="set -e" ;; + *) oldopts="set +e" ;; esac if [[ $(shopt -po history) = "set -o history" ]]; then oldopts="$oldopts; set -o history" @@ -72,7 +72,7 @@ run_embark () { local -a cmd=( "$@" ) case $1 in -V|--version|-h|--help|new|demo|build|run|blockchain|simulator|test|\ - reset|graph|upload|version) cmd=( "embark" "$cmd" );; + reset|graph|upload|version) cmd=( "embark" "$cmd" ) ;; esac docker run \ From b09815c051d5a3ceb198c26f78d65e2a32183a7f Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Thu, 26 Jul 2018 14:15:36 -0500 Subject: [PATCH 44/76] support multiple extra run opts, e.g. "--rm -v ..." --- run.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/run.sh b/run.sh index 99468da..fabe833 100755 --- a/run.sh +++ b/run.sh @@ -64,6 +64,7 @@ run_embark () { local dummy="-e __embark_docker_runsh" local EMBARK_DOCKER_EXTRA_RUN_OPTS=${EMBARK_DOCKER_EXTRA_RUN_OPTS:-$dummy} + local -a extra_run_opts=( $EMBARK_DOCKER_EXTRA_RUN_OPTS ) local EMBARK_DOCKER_MOUNT_SOURCE=${EMBARK_DOCKER_MOUNT_DIR:-$PWD} local EMBARK_DOCKER_MOUNT_TARGET=${EMBARK_DOCKER_MOUNT_DIR:-/dapp} local EMBARK_DOCKER_IMAGE=${EMBARK_DOCKER_IMAGE:-statusim/embark} @@ -89,7 +90,7 @@ run_embark () { -p 30303:30303 \ -v ${EMBARK_DOCKER_MOUNT_SOURCE}:${EMBARK_DOCKER_MOUNT_TARGET} \ -e TERM \ - "${EMBARK_DOCKER_EXTRA_RUN_OPTS}" \ + "${extra_run_opts[@]}" \ ${EMBARK_DOCKER_IMAGE}:${EMBARK_DOCKER_TAG} \ "${cmd[@]}" From 813c52957a10ebe65e90ac5078fec0aa3c96a339 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Mon, 30 Jul 2018 17:50:30 -0500 Subject: [PATCH 45/76] use bit.ly link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6bc81c1..4d6d104 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ In a Bash shell: ``` shell -source <(curl 'https://raw.githubusercontent.com/embark-framework/embark-docker/master/run.sh') +source <(curl https://bit.ly/run_embark) run_embark demo cd embark_demo run_embark From 43e02f38680085713abd4bcf2aebe1e7d278cb1e Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Tue, 31 Jul 2018 14:17:16 -0500 Subject: [PATCH 46/76] reorg some files so top-level of repo is cleaner --- Dockerfile | 16 ++++++++-------- .bash_env => env/.bash_env | 0 .bash_env_nvm_load => env/.bash_env_nvm_load | 0 .bash_env_nvm_unload => env/.bash_env_nvm_unload | 0 .bashrc => env/.bashrc | 0 .npmrc => env/.npmrc | 0 docker-entrypoint.sh => env/docker-entrypoint.sh | 0 install-extras.sh => env/install-extras.sh | 0 user-entrypoint.sh => env/user-entrypoint.sh | 0 9 files changed, 8 insertions(+), 8 deletions(-) rename .bash_env => env/.bash_env (100%) rename .bash_env_nvm_load => env/.bash_env_nvm_load (100%) rename .bash_env_nvm_unload => env/.bash_env_nvm_unload (100%) rename .bashrc => env/.bashrc (100%) rename .npmrc => env/.npmrc (100%) rename docker-entrypoint.sh => env/docker-entrypoint.sh (100%) rename install-extras.sh => env/install-extras.sh (100%) rename user-entrypoint.sh => env/user-entrypoint.sh (100%) diff --git a/Dockerfile b/Dockerfile index 85b4342..41de07f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -84,11 +84,11 @@ USER embark SHELL ["/bin/bash", "-c"] WORKDIR /home/embark COPY --chown=embark:embark \ - .bash_env \ - .bash_env_nvm_load \ - .bash_env_nvm_unload \ - .bashrc \ - .npmrc \ + env/.bash_env \ + env/.bash_env_nvm_load \ + env/.bash_env_nvm_unload \ + env/.bashrc \ + env/.npmrc \ ./ ARG EMBARK_VERSION=3.1.5 ARG GANACHE_VERSION=6.1.4 @@ -114,9 +114,9 @@ RUN mkdir -p .npm-packages \ USER root SHELL ["/bin/sh", "-c"] WORKDIR / -COPY docker-entrypoint.sh \ - user-entrypoint.sh \ - install-extras.sh \ +COPY env/docker-entrypoint.sh \ + env/user-entrypoint.sh \ + env/install-extras.sh \ /usr/local/bin/ WORKDIR /dapp diff --git a/.bash_env b/env/.bash_env similarity index 100% rename from .bash_env rename to env/.bash_env diff --git a/.bash_env_nvm_load b/env/.bash_env_nvm_load similarity index 100% rename from .bash_env_nvm_load rename to env/.bash_env_nvm_load diff --git a/.bash_env_nvm_unload b/env/.bash_env_nvm_unload similarity index 100% rename from .bash_env_nvm_unload rename to env/.bash_env_nvm_unload diff --git a/.bashrc b/env/.bashrc similarity index 100% rename from .bashrc rename to env/.bashrc diff --git a/.npmrc b/env/.npmrc similarity index 100% rename from .npmrc rename to env/.npmrc diff --git a/docker-entrypoint.sh b/env/docker-entrypoint.sh similarity index 100% rename from docker-entrypoint.sh rename to env/docker-entrypoint.sh diff --git a/install-extras.sh b/env/install-extras.sh similarity index 100% rename from install-extras.sh rename to env/install-extras.sh diff --git a/user-entrypoint.sh b/env/user-entrypoint.sh similarity index 100% rename from user-entrypoint.sh rename to env/user-entrypoint.sh From b487c4be54f95c68fcbee68433cc0c7a6a593cf4 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Tue, 31 Jul 2018 22:30:23 -0500 Subject: [PATCH 47/76] rev embark user environment --- env/.bash_env | 96 +++++++++++++++------------------------- env/.bash_env_denac | 2 + env/.bash_env_nvm_unload | 2 - env/.bashrc | 6 +++ env/nodez.theme.bash | 65 +++++++++++++++++++++++++++ 5 files changed, 109 insertions(+), 62 deletions(-) create mode 100644 env/.bash_env_denac delete mode 100644 env/.bash_env_nvm_unload create mode 100644 env/nodez.theme.bash diff --git a/env/.bash_env b/env/.bash_env index 550c2a2..5c67b9c 100644 --- a/env/.bash_env +++ b/env/.bash_env @@ -1,17 +1,8 @@ +# need a prompt indicating versions, etc. ... probably install bash-it + unset BASH_ENV -# we don't need to run more than once -if [[ -v embark_docker_embark_user_BASH_ENV ]]; then - return -fi -export embark_docker_embark_user_BASH_ENV= -export embark_docker_embark_user_npm_bak_config_prefix=${HOME}/.npm-packages -export npm_config_prefix=$embark_docker_embark_user_npm_bak_config_prefix -export NPM_CONFIG_PREFIX=$npm_config_prefix - -export embark_docker_embark_user_PATH_with_LOCALBIN=${HOME}/.local/bin:$PATH -export embark_docker_embark_user_PATH_with_NPM=$NPM_CONFIG_PREFIX/bin:$embark_docker_embark_user_PATH_with_LOCALBIN -export PATH=$embark_docker_embark_user_PATH_with_NPM +export PATH=${HOME}/.local/bin:$PATH nac () { local txtbld=$(tput bold) @@ -26,19 +17,18 @@ nac () { echo "$ERROR: no \"$1\" environment found in ${HOME}/.local/nodeenv" return 1 fi - ____nvm_unload - ____denac - export PATH=$embark_docker_embark_user_PATH_with_LOCALBIN + __nvm_unload + __denac . ${HOME}/.local/nodeenv/$1/bin/activate if [[ $? != 0 ]]; then - ____denac + __denac return 1 fi - export NODE_VERSION=$(node --version) + __versions_export alias denac='deactivate_node' alias deactivate_node='__denac' case $- in - *i*) __npm_completion; echo "Now using NODEENV node $NODE_VERSION (npm v$(npm --version))" ;; + *i*) __npm_completion ;; esac } export -f nac @@ -53,23 +43,16 @@ export -f __nac complete -F __nac nac __denac () { - ____denac - case $- in - *i*) echo "Now using system node $(node --version) (npm v$(npm --version))" ;; - esac -} -export -f __denac - -____denac () { unalias denac &> /dev/null unalias deactivate_node &> /dev/null if type deactivate_node &> /dev/null; then deactivate_node fi - export PATH=$embark_docker_embark_user_PATH_with_NPM - export NODE_VERSION=$(node --version) + . ${HOME}/.bash_env_denac + unset NODE_VERSION + unset NPM_VERSION } -export -f ____denac +export -f __denac __npm_completion () { . <(npm completion) @@ -77,65 +60,44 @@ __npm_completion () { export -f __npm_completion nvm_load () { - __nvm_load $1 + __nvm_load alias nvm_load='nvm' alias nvm='__nvm_mask' __nvm_mask () { case "$*" in unload*) __nvm_unload ;; - *) unalias nvm; nvm "$@"; alias nvm='__nvm_mask' ;; + *) unalias nvm; nvm "$@"; alias nvm='__nvm_mask'; __versions_export ;; esac - export NODE_VERSION=$(node --version) } export -f __nvm_mask } export -f nvm_load __nvm_load () { - ____nvm_unload - ____denac - export PATH=$embark_docker_embark_user_PATH_with_LOCALBIN + __nvm_unload + __denac . ${HOME}/.bash_env_nvm_load . ${HOME}/.nvm/nvm.sh &> /dev/null - if [[ (-z $(nvm alias default)) && ($1 != "no-auto-lts") ]]; then + if [[ $(which node) = "${HOME}/.nvm/versions/"* ]]; then + __versions_export case $- in - *i*) nvm install --lts ;; - *) nvm install --lts &> /dev/null ;; - esac - local auto_lts= - fi - case $- in - *i*) __npm_completion ;; - esac - if [[ (! -v auto_lts) && ($(which node) = "${HOME}/.nvm/versions/"*) ]]; then - export NODE_VERSION=$(node --version) - case $- in - *i*) echo "Now using NVM node $NODE_VERSION (npm v$(npm --version))" ;; + *i*) __npm_completion ;; esac fi } export -f __nvm_load __nvm_unload () { - ____nvm_unload - case $- in - *i*) echo "Now using system node $NODE_VERSION (npm v$(npm --version))" ;; - esac -} -export -f __nvm_unload - -____nvm_unload () { unalias nvm_load &> /dev/null unalias nvm &> /dev/null unset __nvm_mask if type nvm &> /dev/null; then nvm unload fi - export PATH=$embark_docker_embark_user_PATH_with_NPM - . ${HOME}/.bash_env_nvm_unload - export NODE_VERSION=$(node --version) + unset NODE_VERSION + unset NPM_VERSION } -export -f ____nvm_unload +export -f __nvm_unload simple_nodeenv () { pushd $PWD &> /dev/null @@ -149,3 +111,17 @@ simple_nodeenv () { nac "$2" } export -f simple_nodeenv + +__versions_export () { + if type node &> /dev/null; then + local node_version=$(node --version) + export NODE_VERSION=${node_version##v} + export NPM_VERSION=$(npm --version) + else + unset NODE_VERSION + unset NPM_VERSION + fi +} +export -f __versions_export + +nvm_load diff --git a/env/.bash_env_denac b/env/.bash_env_denac new file mode 100644 index 0000000..b7d09cf --- /dev/null +++ b/env/.bash_env_denac @@ -0,0 +1,2 @@ +unset npm_config_prefix +unset NPM_CONFIG_PREFIX diff --git a/env/.bash_env_nvm_unload b/env/.bash_env_nvm_unload deleted file mode 100644 index 5e650f7..0000000 --- a/env/.bash_env_nvm_unload +++ /dev/null @@ -1,2 +0,0 @@ -export npm_config_prefix=$embark_docker_embark_user_npm_bak_config_prefix -export NPM_CONFIG_PREFIX=$npm_config_prefix diff --git a/env/.bashrc b/env/.bashrc index b1df03c..59179fb 100644 --- a/env/.bashrc +++ b/env/.bashrc @@ -1 +1,7 @@ . ${HOME}/.bash_env + +. /usr/share/bash-completion/completions/git + +export BASH_IT=${HOME}/.bash_it +export BASH_IT_THEME="nodez" +. ${BASH_IT}/bash_it.sh diff --git a/env/nodez.theme.bash b/env/nodez.theme.bash new file mode 100644 index 0000000..63c56a8 --- /dev/null +++ b/env/nodez.theme.bash @@ -0,0 +1,65 @@ +SCM_THEME_PROMPT_PREFIX="" +SCM_THEME_PROMPT_SUFFIX="" + +SCM_THEME_PROMPT_DIRTY=" ${bold_red}✗${normal}" +SCM_THEME_PROMPT_CLEAN=" ${bold_green}✓${normal}" +SCM_GIT_CHAR="${bold_green}±${normal}" +SCM_SVN_CHAR="${bold_cyan}⑆${normal}" +SCM_HG_CHAR="${bold_red}☿${normal}" + +__nodez_char_node="${bold_green}🄽 ${normal}" +__nodez_char_npm=📦 + +__nodez_ne() { + local env= + if [[ -v NVM_DIR ]]; then + env="nvm" + fi + if [[ -v NODE_VIRTUAL_ENV ]]; then + env="${NODE_VIRTUAL_ENV##*/}" + fi + if [[ -v NODE_VERSION ]]; then + [ "$env" != "" ] && echo "[${bold_yellow}$env${normal}" + else + [ "$env" != "" ] && echo "[${bold_yellow}$env${normal}]" + fi +} + +__nodez_nv() { + [[ -v NODE_VERSION ]] \ + && echo "→${__nodez_char_node}${NODE_VERSION}${__nodez_char_npm}${NPM_VERSION}]" +} + +__nodez_scm_prompt() { + [[ $(scm_char) != $SCM_NONE_CHAR ]] \ + && echo "[$(scm_char)][$(scm_prompt_info)]" +} + +case $TERM in + xterm*) + __nodez_title="\[\033]0;\w\007\]" ;; + *) + __nodez_title="" ;; +esac + +__nodez_ve(){ + [[ -n "$VIRTUAL_ENV" ]] \ + && echo "(${bold_purple}${VIRTUAL_ENV##*/}${normal})" +} + +prompt() { + local host="${green}\h${normal}"; + PS1="${__nodez_title}┌─" + PS1+="$(__nodez_ve)" + PS1+="[$host]" + PS1+="$(__nodez_ne)$(__nodez_nv)" + PS1+="$(__nodez_scm_prompt)" + PS1+="[${cyan}\\w${normal}]" + PS1+=" +└─▪ " +} + +PS2="└─▪ " +PS3=">> " + +safe_append_prompt_command prompt From 54945e5e4144d2affe8ccdf4265626084883d58e Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Tue, 31 Jul 2018 22:33:06 -0500 Subject: [PATCH 48/76] smarter arrangement of ARG, ENV --- Dockerfile | 71 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 56 insertions(+), 15 deletions(-) diff --git a/Dockerfile b/Dockerfile index 41de07f..b4e9006 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,34 @@ +ARG __CODESET=UTF-8 +ARG __LANG=en_US.${__CODESET} +ARG __LANGUAGE=en_US:en +ARG __LC_ALL=en_US.${__CODESET} +ARG BUILDER_BASE_IMAGE=buildpack-deps +ARG BUILDER_BASE_TAG=stretch +ARG EMBARK_VERSION=3.1.5 +ARG GANACHE_VERSION=6.1.4 +ARG GETH_VERSION=1.8.11-dea1ce05 +ARG IPFS_VERSION=0.4.15 +ARG MICRO_VERSION=1.4.0 +ARG NODE_VERSION=8.11.3 +ARG NODEENV_VERSION=1.3.2 +ARG NPM_VERSION=6.2.0 +ARG NVM_VERSION=0.33.11 +ARG SUEXEC_VERSION=0.2 + # multi-stage builder images # ------------------------------------------------------------------------------ ARG NODE_TAG=8.11.3-stretch FROM node:${NODE_TAG} as builder-base +ARG __CODESET +ARG __LANG +ARG __LANGUAGE +ARG __LC_ALL # ------------------------------------------------------------------------------ FROM builder-base as builder-geth -ARG GETH_VERSION=1.8.11-dea1ce05 +ARG GETH_VERSION RUN export url="https://gethstore.blob.core.windows.net/builds" \ && export platform="geth-alltools-linux-amd64" \ && curl -fsSLO --compressed "${url}/${platform}-${GETH_VERSION}.tar.gz" \ @@ -17,7 +38,7 @@ RUN export url="https://gethstore.blob.core.windows.net/builds" \ # ------------------------------------------------------------------------------ FROM builder-base as builder-ipfs -ARG IPFS_VERSION=0.4.15 +ARG IPFS_VERSION RUN export url="https://dist.ipfs.io/go-ipfs" \ && export ver="v${IPFS_VERSION}/go-ipfs_v${IPFS_VERSION}" \ && export platform="linux-amd64" \ @@ -27,7 +48,7 @@ RUN export url="https://dist.ipfs.io/go-ipfs" \ # ------------------------------------------------------------------------------ FROM builder-base as builder-micro -ARG MICRO_VERSION=1.4.0 +ARG MICRO_VERSION RUN export url="https://github.com/zyedidia/micro/releases/download" \ && export ver="v${MICRO_VERSION}/micro-${MICRO_VERSION}" \ && export platform="linux64" \ @@ -37,8 +58,8 @@ RUN export url="https://github.com/zyedidia/micro/releases/download" \ # ------------------------------------------------------------------------------ FROM builder-base as builder-suexec -ARG SUEXEC_VERSION=v0.2 -RUN git clone --branch ${SUEXEC_VERSION} \ +ARG SUEXEC_VERSION +RUN git clone --branch v${SUEXEC_VERSION} \ --depth 1 \ https://github.com/ncopa/su-exec.git 2> /dev/null \ && cd su-exec \ @@ -51,10 +72,6 @@ FROM builder-base LABEL maintainer="Andre Medeiros " -ARG __CODESET -ARG __LANG -ARG __LANGUAGE -ARG __LC_ALL RUN export DEBIAN_FRONTEND=noninteractive \ && apt-get update \ && apt-get install -y locales \ @@ -71,13 +88,18 @@ RUN export DEBIAN_FRONTEND=noninteractive \ && unset DEBIAN_FRONTEND \ && rm -rf /var/lib/apt/lists/* \ && adduser --disabled-password --shell /bin/bash --gecos "" embark \ +ARG EMBARK_VERSION +ARG GANACHE_VERSION +ARG NODE_VERSION +ARG NODEENV_VERSION +ARG NPM_VERSION +ARG NVM_VERSION && mkdir -p /dapp \ && chown embark:embark /dapp \ && curl -fsSLO --compressed "https://bootstrap.pypa.io/get-pip.py" \ && python get-pip.py \ && rm get-pip.py -ENV LANG=${__LANG:-en_US.${__CODESET:-UTF-8}} COPY --from=builder-ipfs /go-ipfs/ipfs /usr/local/bin/ USER embark @@ -90,11 +112,6 @@ COPY --chown=embark:embark \ env/.bashrc \ env/.npmrc \ ./ -ARG EMBARK_VERSION=3.1.5 -ARG GANACHE_VERSION=6.1.4 -ARG NODEENV_VERSION=1.3.2 -ARG NPM_VERSION=6.2.0 -ARG NVM_VERSION=v0.33.11 RUN mkdir -p .npm-packages \ .local/nodeenv \ && . .bash_env \ @@ -112,6 +129,30 @@ RUN mkdir -p .npm-packages \ && ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["GET", "POST", "PUT"]' USER root +ARG __CODESET +ARG __LANG +ARG __LANGUAGE +ARG __LC_ALL +ARG BUILDER_BASE_IMAGE +ARG BUILDER_BASE_TAG +ARG GETH_VERSION +ARG IPFS_VERSION +ARG MICRO_VERSION +ARG SUEXEC_VERSION +ENV __CODESET=${__CODESET} \ + __LANG=${__LANG} \ + __LANGUAGE=${__LANGUAGE} \ + __LC_ALL=${__LC_ALL} \ + BUILDER_BASE_IMAGE=${BUILDER_BASE_IMAGE} \ + BUILDER_BASE_TAG=${BUILDER_BASE_TAG} \ + EMBARK_VERSION=${EMBARK_VERSION} \ + GANACHE_VERSION=${GANACHE_VERSION} \ + GETH_VERSION=${GETH_VERSION} \ + IPFS_VERSION=${IPFS_VERSION} \ + MICRO_VERSION=${MICRO_VERSION} \ + NODEENV_VERSION=${NODEENV_VERSION} \ + NVM_VERSION=${NVM_VERSION} \ + SUEXEC_VERSION=${SUEXEC_VERSION} SHELL ["/bin/sh", "-c"] WORKDIR / COPY env/docker-entrypoint.sh \ From 3c1699fe10b1403c2d6fafbbb91280f473e66a98 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Tue, 31 Jul 2018 22:35:09 -0500 Subject: [PATCH 49/76] node from nvm (no system node) --- Dockerfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index b4e9006..b540c93 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,8 +18,7 @@ ARG SUEXEC_VERSION=0.2 # multi-stage builder images # ------------------------------------------------------------------------------ -ARG NODE_TAG=8.11.3-stretch -FROM node:${NODE_TAG} as builder-base +FROM ${BUILDER_BASE_IMAGE}:${BUILDER_BASE_TAG} as builder-base ARG __CODESET ARG __LANG ARG __LANGUAGE @@ -119,6 +118,8 @@ RUN mkdir -p .npm-packages \ && git clone --branch ${NVM_VERSION} \ --depth 1 \ https://github.com/creationix/nvm.git .nvm 2> /dev/null \ + && . .nvm/nvm.sh \ + && nvm install v${NODE_VERSION} \ && npm install -g "npm@${NPM_VERSION}" \ && npm install -g "embark@${EMBARK_VERSION}" \ "ganache-cli@${GANACHE_VERSION}" \ From 49eb9ad338dd34e7aa0b3a035d913c093dd8843d Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Tue, 31 Jul 2018 22:36:06 -0500 Subject: [PATCH 50/76] locale config,gen in builder-base --- Dockerfile | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/Dockerfile b/Dockerfile index b540c93..c8a0092 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,6 +23,20 @@ ARG __CODESET ARG __LANG ARG __LANGUAGE ARG __LC_ALL +SHELL ["/bin/bash", "-c"] +RUN export DEBIAN_FRONTEND=noninteractive \ + && apt-get update \ + && apt-get install -y locales \ + && sed -i \ + -e "s/# ${__LANG} ${__CODESET}/${__LANG} ${__CODESET}/" \ + /etc/locale.gen \ + && locale-gen --purge "${__LANG}" \ + && dpkg-reconfigure locales \ + && update-locale LANG=${__LANG} LANGUAGE=${__LANGUAGE} LC_ALL=${__LC_ALL} \ + && unset DEBIAN_FRONTEND \ + && rm -rf /var/lib/apt/lists/* +ENV LANG=${__LANG} +SHELL ["/bin/sh", "-c"] # ------------------------------------------------------------------------------ @@ -71,21 +85,6 @@ FROM builder-base LABEL maintainer="Andre Medeiros " -RUN export DEBIAN_FRONTEND=noninteractive \ - && apt-get update \ - && apt-get install -y locales \ - && export __CODESET=${__CODESET:-UTF-8} \ - && export __LANG=${__LANG:-en_US.$__CODESET} \ - && export __LANGUAGE=${__LANGUAGE:-en_US:en} \ - && export __LC_ALL=${__LC_ALL:-en_US.$__CODESET} \ - && sed -i \ - -e "s/# ${__LANG} ${__CODESET}/${__LANG} ${__CODESET}/" \ - /etc/locale.gen \ - && locale-gen --purge "${__LANG}" \ - && dpkg-reconfigure locales \ - && update-locale LANG=${__LANG} LANGUAGE=${__LANGUAGE} LC_ALL=${__LC_ALL} \ - && unset DEBIAN_FRONTEND \ - && rm -rf /var/lib/apt/lists/* \ && adduser --disabled-password --shell /bin/bash --gecos "" embark \ ARG EMBARK_VERSION ARG GANACHE_VERSION From c90f473d521c07aab0282c18de75acc93f23d5cf Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Tue, 31 Jul 2018 22:37:12 -0500 Subject: [PATCH 51/76] root and embark user RUNs use bash shell --- Dockerfile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index c8a0092..d1cdc26 100644 --- a/Dockerfile +++ b/Dockerfile @@ -85,13 +85,14 @@ FROM builder-base LABEL maintainer="Andre Medeiros " - && adduser --disabled-password --shell /bin/bash --gecos "" embark \ ARG EMBARK_VERSION ARG GANACHE_VERSION ARG NODE_VERSION ARG NODEENV_VERSION ARG NPM_VERSION ARG NVM_VERSION +SHELL ["/bin/bash", "-c"] +RUN adduser --disabled-password --shell /bin/bash --gecos "" embark \ && mkdir -p /dapp \ && chown embark:embark /dapp \ && curl -fsSLO --compressed "https://bootstrap.pypa.io/get-pip.py" \ @@ -99,9 +100,7 @@ ARG NVM_VERSION && rm get-pip.py COPY --from=builder-ipfs /go-ipfs/ipfs /usr/local/bin/ - USER embark -SHELL ["/bin/bash", "-c"] WORKDIR /home/embark COPY --chown=embark:embark \ env/.bash_env \ From 0735512bb45044bcc0b4df7298160e5c39e7a270 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Tue, 31 Jul 2018 22:39:24 -0500 Subject: [PATCH 52/76] rev embark user RUN --- Dockerfile | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index d1cdc26..631a9a8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -109,13 +109,19 @@ COPY --chown=embark:embark \ env/.bashrc \ env/.npmrc \ ./ -RUN mkdir -p .npm-packages \ - .local/nodeenv \ - && . .bash_env \ +RUN git clone --depth 1 \ + https://github.com/Bash-it/bash-it.git \ + .bash_it 2> /dev/null \ + && export BASH_IT=${HOME}/.bash_it \ + && . ${BASH_IT}/bash_it.sh \ + && bash-it enable completion nvm \ + && mkdir -p .bash_it/custom/themes/nodez \ && pip install --user nodeenv==${NODEENV_VERSION} \ - && git clone --branch ${NVM_VERSION} \ + && mkdir -p .local/nodeenv \ + && git clone --branch v${NVM_VERSION} \ --depth 1 \ - https://github.com/creationix/nvm.git .nvm 2> /dev/null \ + https://github.com/creationix/nvm.git \ + .nvm 2> /dev/null \ && . .nvm/nvm.sh \ && nvm install v${NODE_VERSION} \ && npm install -g "npm@${NPM_VERSION}" \ From 2ddee2df40d5fb0204578b531dfcb0d0b681584a Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Tue, 31 Jul 2018 22:39:47 -0500 Subject: [PATCH 53/76] COPYs last, when possible --- Dockerfile | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/Dockerfile b/Dockerfile index 631a9a8..123f4eb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -102,13 +102,6 @@ RUN adduser --disabled-password --shell /bin/bash --gecos "" embark \ COPY --from=builder-ipfs /go-ipfs/ipfs /usr/local/bin/ USER embark WORKDIR /home/embark -COPY --chown=embark:embark \ - env/.bash_env \ - env/.bash_env_nvm_load \ - env/.bash_env_nvm_unload \ - env/.bashrc \ - env/.npmrc \ - ./ RUN git clone --depth 1 \ https://github.com/Bash-it/bash-it.git \ .bash_it 2> /dev/null \ @@ -133,7 +126,6 @@ RUN git clone --depth 1 \ && ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["*"]' \ && ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["GET", "POST", "PUT"]' -USER root ARG __CODESET ARG __LANG ARG __LANGUAGE @@ -159,12 +151,7 @@ ENV __CODESET=${__CODESET} \ NVM_VERSION=${NVM_VERSION} \ SUEXEC_VERSION=${SUEXEC_VERSION} SHELL ["/bin/sh", "-c"] -WORKDIR / -COPY env/docker-entrypoint.sh \ - env/user-entrypoint.sh \ - env/install-extras.sh \ - /usr/local/bin/ - +USER root WORKDIR /dapp ENTRYPOINT ["docker-entrypoint.sh"] CMD ["embark", "run"] @@ -177,3 +164,17 @@ EXPOSE 5001 8000 8080 8500 8545 8546 8555 8556 30301/udp 30303 COPY --from=builder-geth /geth-alltools* /usr/local/bin/ COPY --from=builder-micro /micro*/micro /usr/local/bin/ COPY --from=builder-suexec /su-exec/su-exec /usr/local/bin/ +COPY env/docker-entrypoint.sh \ + env/user-entrypoint.sh \ + env/install-extras.sh \ + /usr/local/bin/ +COPY --chown=embark:embark \ + env/.bash_env \ + env/.bash_env_denac \ + env/.bash_env_nvm_load \ + env/.bashrc \ + env/.npmrc \ + /home/embark/ +COPY --chown=embark:embark \ + env/nodez.theme.bash \ + /home/embark/.bash_it/custom/themes/nodez/ From 926685782e3a870f07c78bff087a7c0787d66c9a Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Wed, 1 Aug 2018 11:22:39 -0500 Subject: [PATCH 54/76] rm comment -- won't attempt to version control bash-it for now --- env/.bash_env | 2 -- 1 file changed, 2 deletions(-) diff --git a/env/.bash_env b/env/.bash_env index 5c67b9c..c4cc0fc 100644 --- a/env/.bash_env +++ b/env/.bash_env @@ -1,5 +1,3 @@ -# need a prompt indicating versions, etc. ... probably install bash-it - unset BASH_ENV export PATH=${HOME}/.local/bin:$PATH From ada6cce8d3d3da1a27e6b265b5ba342380b02741 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Wed, 1 Aug 2018 11:23:31 -0500 Subject: [PATCH 55/76] enable nvm completion upon nvm_load --- Dockerfile | 1 - env/.bash_env | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 123f4eb..4f9ec05 100644 --- a/Dockerfile +++ b/Dockerfile @@ -107,7 +107,6 @@ RUN git clone --depth 1 \ .bash_it 2> /dev/null \ && export BASH_IT=${HOME}/.bash_it \ && . ${BASH_IT}/bash_it.sh \ - && bash-it enable completion nvm \ && mkdir -p .bash_it/custom/themes/nodez \ && pip install --user nodeenv==${NODEENV_VERSION} \ && mkdir -p .local/nodeenv \ diff --git a/env/.bash_env b/env/.bash_env index c4cc0fc..85ad206 100644 --- a/env/.bash_env +++ b/env/.bash_env @@ -76,6 +76,10 @@ __nvm_load () { __denac . ${HOME}/.bash_env_nvm_load . ${HOME}/.nvm/nvm.sh &> /dev/null + case $- in + *i*) bash-it enable completion nvm &> /dev/null; \ + . ${BASH_IT}/completion/available/nvm.completion.bash ;; + esac if [[ $(which node) = "${HOME}/.nvm/versions/"* ]]; then __versions_export case $- in From 3653afc45fe95fc004e3e937dc8f699ec88ac2e1 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Wed, 1 Aug 2018 11:23:44 -0500 Subject: [PATCH 56/76] prefer nodeenv by default --- Dockerfile | 7 +++++-- env/.bash_env | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4f9ec05..b38c831 100644 --- a/Dockerfile +++ b/Dockerfile @@ -110,12 +110,15 @@ RUN git clone --depth 1 \ && mkdir -p .bash_it/custom/themes/nodez \ && pip install --user nodeenv==${NODEENV_VERSION} \ && mkdir -p .local/nodeenv \ + && export PATH=${HOME}/.local/bin:$PATH \ + && nodeenv --prebuilt \ + --node ${NODE_VERSION} \ + .local/nodeenv/default \ && git clone --branch v${NVM_VERSION} \ --depth 1 \ https://github.com/creationix/nvm.git \ .nvm 2> /dev/null \ - && . .nvm/nvm.sh \ - && nvm install v${NODE_VERSION} \ + && . .local/nodeenv/default/bin/activate \ && npm install -g "npm@${NPM_VERSION}" \ && npm install -g "embark@${EMBARK_VERSION}" \ "ganache-cli@${GANACHE_VERSION}" \ diff --git a/env/.bash_env b/env/.bash_env index 85ad206..1f24db7 100644 --- a/env/.bash_env +++ b/env/.bash_env @@ -126,4 +126,4 @@ __versions_export () { } export -f __versions_export -nvm_load +nac default From b8f4b0ce899f0ece8ad1ff2947de5fa2b71aa970 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Wed, 1 Aug 2018 11:24:45 -0500 Subject: [PATCH 57/76] cleanup theme --- env/nodez.theme.bash | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/env/nodez.theme.bash b/env/nodez.theme.bash index 63c56a8..9ee2716 100644 --- a/env/nodez.theme.bash +++ b/env/nodez.theme.bash @@ -18,16 +18,21 @@ __nodez_ne() { if [[ -v NODE_VIRTUAL_ENV ]]; then env="${NODE_VIRTUAL_ENV##*/}" fi - if [[ -v NODE_VERSION ]]; then - [ "$env" != "" ] && echo "[${bold_yellow}$env${normal}" - else - [ "$env" != "" ] && echo "[${bold_yellow}$env${normal}]" + if [[ "$env" != "" ]]; then + env="[${bold_yellow}$env${normal}" + if [[ ! -v NODE_VERSION ]]; then + env+="]" + fi + echo "$env" fi } __nodez_nv() { - [[ -v NODE_VERSION ]] \ - && echo "→${__nodez_char_node}${NODE_VERSION}${__nodez_char_npm}${NPM_VERSION}]" + if [[ -v NODE_VERSION ]]; then + local nv="=${__nodez_char_node}${NODE_VERSION}" + nv+="${__nodez_char_npm}${NPM_VERSION}]" + echo "$nv" + fi } __nodez_scm_prompt() { From ac7e46550c030422942ffad86b0b181219933b10 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Wed, 1 Aug 2018 11:31:35 -0500 Subject: [PATCH 58/76] give credit --- env/nodez.theme.bash | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/env/nodez.theme.bash b/env/nodez.theme.bash index 9ee2716..4786cd3 100644 --- a/env/nodez.theme.bash +++ b/env/nodez.theme.bash @@ -1,3 +1,7 @@ +# Author: Michael Bradley (https://github.com/michaelsbradleyjr/) +# Based on the zorg theme: +# https://github.com/Bash-it/bash-it/blob/master/themes/zork/zork.theme.bash + SCM_THEME_PROMPT_PREFIX="" SCM_THEME_PROMPT_SUFFIX="" From a1aa03db15ad66cf313286353e4e9d3cff9756a6 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Wed, 1 Aug 2018 21:29:49 -0500 Subject: [PATCH 59/76] stub for exec.sh --- exec.sh | 2 ++ 1 file changed, 2 insertions(+) create mode 100755 exec.sh diff --git a/exec.sh b/exec.sh new file mode 100755 index 0000000..35abbc2 --- /dev/null +++ b/exec.sh @@ -0,0 +1,2 @@ +# TODO: helper script that offers for `docker exec ` similar conveniences as +# run.sh provides for `docker run` From 3601291b94c245c4def3987612d4d9b29fe04617 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Wed, 1 Aug 2018 21:30:52 -0500 Subject: [PATCH 60/76] move override-ables to the top --- run.sh | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/run.sh b/run.sh index fabe833..837b51e 100755 --- a/run.sh +++ b/run.sh @@ -1,16 +1,13 @@ #!/usr/bin/env bash run_embark () { - local oldopts="" - case $- in - *e*) oldopts="set -e" ;; - *) oldopts="set +e" ;; - esac - if [[ $(shopt -po history) = "set -o history" ]]; then - oldopts="$oldopts; set -o history" - fi - set +e - set +o history + local EMBARK_DOCKER_EXTRA_RUN_OPTS=${EMBARK_DOCKER_EXTRA_RUN_OPTS:-"-e __embark_docker_runsh"} + local EMBARK_DOCKER_MOUNT_SOURCE=${EMBARK_DOCKER_MOUNT_DIR:-$PWD} + local EMBARK_DOCKER_MOUNT_TARGET=${EMBARK_DOCKER_MOUNT_DIR:-/dapp} + local EMBARK_DOCKER_IMAGE=${EMBARK_DOCKER_IMAGE:-statusim/embark} + local EMBARK_DOCKER_RUN=${EMBARK_DOCKER_RUN} + local EMBARK_DOCKER_RUN_INTERACTIVE=${EMBARK_DOCKER_RUN_INTERACTIVE:-false} + local EMBARK_DOCKER_TAG=${EMBARK_DOCKER_TAG:-latest} local txtbld=$(tput bold) local txtrst=$(tput sgr0) @@ -23,6 +20,17 @@ run_embark () { local INFO=${bldcyn}INFO${txtrst} local WARNING=${bldylw}WARNING${txtrst} + local oldopts="" + case $- in + *e*) oldopts="set -e" ;; + *) oldopts="set +e" ;; + esac + if [[ $(shopt -po history) = "set -o history" ]]; then + oldopts="$oldopts; set -o history" + fi + set +e + set +o history + check_bash_version () { if [[ $BASH_VERSINFO -lt 4 ]]; then echo "$ERROR: this script requires Bash version >= 4.0" @@ -62,13 +70,7 @@ run_embark () { fi fi - local dummy="-e __embark_docker_runsh" - local EMBARK_DOCKER_EXTRA_RUN_OPTS=${EMBARK_DOCKER_EXTRA_RUN_OPTS:-$dummy} local -a extra_run_opts=( $EMBARK_DOCKER_EXTRA_RUN_OPTS ) - local EMBARK_DOCKER_MOUNT_SOURCE=${EMBARK_DOCKER_MOUNT_DIR:-$PWD} - local EMBARK_DOCKER_MOUNT_TARGET=${EMBARK_DOCKER_MOUNT_DIR:-/dapp} - local EMBARK_DOCKER_IMAGE=${EMBARK_DOCKER_IMAGE:-statusim/embark} - local EMBARK_DOCKER_TAG=${EMBARK_DOCKER_TAG:-latest} local -a cmd=( "$@" ) case $1 in From 0288f14b21ee538be1070c3ab998fbba1110be84 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Wed, 1 Aug 2018 21:31:07 -0500 Subject: [PATCH 61/76] formatting --- run.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/run.sh b/run.sh index 837b51e..c9360f1 100755 --- a/run.sh +++ b/run.sh @@ -37,7 +37,6 @@ run_embark () { return 1 fi } - check_bash_version if [[ $? = 1 ]]; then @@ -56,7 +55,6 @@ run_embark () { return 127 fi } - check_docker if [[ $? = 127 ]]; then From 00add9f6ccad8c43118ee9103729d0042c42ae50 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Wed, 1 Aug 2018 21:32:47 -0500 Subject: [PATCH 62/76] advanced scripting capability --- run.sh | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/run.sh b/run.sh index c9360f1..98913e0 100755 --- a/run.sh +++ b/run.sh @@ -68,13 +68,40 @@ run_embark () { fi fi + local -a cmd=( "$@" ) local -a extra_run_opts=( $EMBARK_DOCKER_EXTRA_RUN_OPTS ) - local -a cmd=( "$@" ) - case $1 in - -V|--version|-h|--help|new|demo|build|run|blockchain|simulator|test|\ - reset|graph|upload|version) cmd=( "embark" "$cmd" ) ;; - esac + if [[ -z "$EMBARK_DOCKER_RUN" ]]; then + case $1 in + -V|--version|-h|--help|new|demo|build|run|blockchain|simulator|test|\ + reset|graph|upload|version) cmd=( "embark" "$cmd" ) ;; + esac + else + local i_flag= + if [[ $EMBARK_DOCKER_RUN_INTERACTIVE = true ]]; then + i_flag='i' + else + i_flag='' + fi + + local run_script=$(< "$EMBARK_DOCKER_RUN") +# do not remove empty lines below +# do not add indentation to lines below + run_script="exec bash -s $@ << 'SCRIPT' +td=\$(mktemp -d) +cat << 'RUN' > \$td/run_script +$run_script +RUN + +chmod +x \$td/run_script +exec \$td/run_script $@ +SCRIPT + +" +# do not remove empty lines above +# do not add indentation to lines above + cmd=( "bash" "-${i_flag}c" "$run_script" ) + fi docker run \ -it \ From 377eef2e988aac8d298a56eedef5ccaca03280f9 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Wed, 1 Aug 2018 21:33:06 -0500 Subject: [PATCH 63/76] wrap vars w/ quotes --- run.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/run.sh b/run.sh index 98913e0..06c930c 100755 --- a/run.sh +++ b/run.sh @@ -115,10 +115,10 @@ SCRIPT -p 8556:8556 \ -p 30301:30301/udp \ -p 30303:30303 \ - -v ${EMBARK_DOCKER_MOUNT_SOURCE}:${EMBARK_DOCKER_MOUNT_TARGET} \ + -v "${EMBARK_DOCKER_MOUNT_SOURCE}:${EMBARK_DOCKER_MOUNT_TARGET}" \ -e TERM \ "${extra_run_opts[@]}" \ - ${EMBARK_DOCKER_IMAGE}:${EMBARK_DOCKER_TAG} \ + "${EMBARK_DOCKER_IMAGE}:${EMBARK_DOCKER_TAG}" \ "${cmd[@]}" local docker_exit_status=$? From 822ce63a462fae8d532a962997806620f0b17cd9 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Wed, 1 Aug 2018 21:34:27 -0500 Subject: [PATCH 64/76] expand README --- README.md | 223 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 195 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 4d6d104..8fd0673 100644 --- a/README.md +++ b/README.md @@ -6,20 +6,28 @@ In a Bash shell: ``` shell source <(curl https://bit.ly/run_embark) run_embark demo +# ^ will create an embark_demo directory in the docker host's $PWD cd embark_demo run_embark ``` -With overrides: +## Usage via `run.sh` + +[`run.sh`](https://github.com/embark-framework/embark-docker/blob/master/run.sh) +is a Bash script that simplifies usage of the embark container: publishing +ports, bind mounting a host volume, and so on. + +Many aspects of the script's behavior can be overridden with environment +variables, and that approach can be (optionally) combined with `docker build`: ``` shell export EMBARK_DOCKER_EXTRA_RUN_OPTS='--rm' export EMBARK_DOCKER_IMAGE=statusim/embark export EMBARK_DOCKER_TAG=custom -export EMBARK_DOCKERFILE='https://github.com/embark-framework/embark-docker.git#some/branch' +export EMBARK_DOCKERFILE='https://github.com/embark-framework/embark-docker.git#develop' export EMBARK_VERSION='embark-framework/embark#features/branch' export NODE_TAG=10.7.0 -export RUNNER='https://raw.githubusercontent.com/embark-framework/embark-docker/some/branch/run.sh' +export RUNNER='https://raw.githubusercontent.com/embark-framework/embark-docker/master/run.sh' docker build \ --build-arg EMBARK_VERSION=$EMBARK_VERSION \ @@ -36,7 +44,7 @@ run_embark Review the [Dockerfile](https://github.com/embark-framework/embark-docker/blob/master/Dockerfile) and -[run.sh](https://github.com/embark-framework/embark-docker/blob/master/run.sh#L66-L70) +[run.sh](https://github.com/embark-framework/embark-docker/blob/master/run.sh) for all possible overrides. ### Shortcuts @@ -68,7 +76,72 @@ The same is true for the rest of the `embark` commands. To see the full list: run_embark --help ``` -### Compound commands +### Utilities + +The container comes equipped with +[nodeenv](https://github.com/ekalinin/nodeenv) and +[nvm](https://github.com/creationix/nvm). A `default` Node.js environment is +installed via `nodeenv` during image build and placed in +`~embark/.local/nodeenv/default`. Both `nodeenv` and `nvm` can be used in +interactive and non-interactive scripts. + +#### `nodeenv` + +These are equivalent: + +``` shell +nodeenv --prebuilt --node 10.7.0 ~/.local/nodeenv/my_node +``` +``` shell +simple_nodeenv 10.7.0 my_node +``` + +Activate and deactivate environments with `nac` and `denac`: + +``` shell +nac my_node +``` +``` shell +denac +``` + +Note that `simple_nodeenv` automatically activates an environment after +installation, while `nodeenv` does not. + +#### `nvm` + +If `nvm` is preferable, it needs to be loaded first: + +``` shell +nvm_load +nvm install --latest-npm 8.11.3 +``` + +`nvm deactivate` and `nvm unload` will work as expected. It's also possible to +move between `nodeenv` and `nvm` environments without first deactivating or +unloading: + +``` shell +nac default +nvm_load && nvm use v10.7.0 +# ^ assuming 10.7.0 is already installed +nac default +``` + +#### `install-extras.sh` + +Some nice-to-have utilities are not installed by default, but this can be done +by running +[`install-extras.sh`](https://github.com/embark-framework/embark-docker/blob/master/env/install-extras.sh) +as the `root` user in an already running container: + +``` shell +docker exec -it $container_id install-extras.sh +``` + +### Commands + +#### Simple A single command with options can be supplied directly: @@ -76,66 +149,160 @@ A single command with options can be supplied directly: run_embark bash ``` ``` shell +run_embark node -i -e 'console.log(process.version)' +# ^ press return again to get a blank REPL prompt +``` +``` shell run_embark ps -ef ``` +#### Compound + Compound commands should be passed to `bash -[i]c`: +``` shell +run_embark bash -c 'ps -ef && ls / ; which embark' +``` +``` shell +run_embark bash -c 'nvm_load && nvm install --latest-npm 8.11.3 && node --version && npm --version' +``` + +Bash +[here-documents](https://www.gnu.org/software/bash/manual/html_node/Redirections.html#Here-Documents) +can be used to compose scripts without employing an abundance of `&&`, `;`, and +`\`: + ``` shell run_embark bash -c 'exec bash << "SCRIPT" simple_nodeenv 10.7.0 my_node -node --version -echo $(which node) npm i -g http-server -exec http-server -p 10000 +exec http-server -p 8000 SCRIPT ' ``` +Since `run.sh` mounts the docker host's `$PWD` into the container's `/dapp`, and +since `/dapp` is the container's default working directory, it's also possible +to do: + +``` shell +run_embark ./my_script.sh +# ^ assuming my_script.sh is in the docker host's $PWD +``` + +Just make sure the script has a `#!` line and that you did `chmod +x +my_script.sh` on the docker host before invoking `run_embark`. + +##### `$EMBARK_DOCKER_RUN` + +For greater flexibility, you can specify a script with +`$EMBARK_DOCKER_RUN`. Arguments passed to `run_embark` will be forwarded to the +script, and extra flags can be provided to `docker run` to forward docker host +environment variables. + +Keep in mind that such scripts will be run as the `embark` user owing to the +container's entrypoint. + +``` shell +#!/bin/bash + +# this script is located at /path/to/my_script.sh on the docker host, not necessarily in host's $PWD + +# dangling " + +c=container! +echo $HOST_HOSTNAME +echo $HOSTNAME +echo $@ +echo $1 +# a comment +echo $2 +echo $3 +eval echo \\\$\$3 +# another comment +``` +Invoke with: +``` shell +EMBARK_DOCKER_EXTRA_RUN_OPTS="-e HOST_HOSTNAME=$HOSTNAME" +EMBARK_DOCKER_RUN=/path/to/my_script.sh + +a=host! + +run_embark $a b c +``` + +Node.js variant: +``` javascript +#!/usr/bin/env node + +// this script is located at /path/to/my_node_script.js on the docker host, not necessarily in host's $PWD + +const o = {c: 'container!'}; + +console.log(process.env.HOST_HOSTNAME); +console.log(process.env.HOSTNAME); +console.log(JSON.stringify(process.argv)); +console.log(process.argv[2]); +console.log(process.argv[3]); +console.log(process.argv[4]); +console.log(o[process.argv[4]]); +``` +Invoke the same way: +``` shell +EMBARK_DOCKER_EXTRA_RUN_OPTS="-e HOST_HOSTNAME=$HOSTNAME" +EMBARK_DOCKER_RUN=/path/to/my_node_script.js + +a=host! + +run_embark $a b c +``` + +#### `docker exec` + When executing compound commands via `docer exec` in a running embark -container, `su-exec` and `bash -ic` can be used together: +container, `su-exec` and `bash -[i]c` can be used together: ``` shell -docker exec -it su-exec embark \ +docker exec -it $container_id su-exec embark \ bash -ic 'exec bash << "SCRIPT" -nac my_node -exec http-server -p 10001 +simple_nodeenv 10.7.0 my_node +npm i -g http-server +exec http-server -p 8000 SCRIPT ' ``` -Alternatively, to go non-interactive, manually source the embark user's -`.bash_env`: +To go non-interactive, manually source the embark user's `.bash_env`: ``` shell -docker exec -it su-exec embark \ +docker exec -it $container_id su-exec embark \ bash -c 'exec bash << "SCRIPT" . ~/.bash_env -nvm_load no-auto-lts -nvm install v10.6.0 -echo $(which node) +simple_nodeenv 10.7.0 my_node npm i -g http-server -exec http-server -p 10002 +exec http-server -p 8000 SCRIPT ' ``` -## Updating versions +## Container development + +### Updating versions * Open `Dockerfile` * On the `ARG` directives, update necessary versions. -## Building +### Building Building requires Docker to be installed on your local machine. -### Scripted +#### Scripted If you have Ruby installed in your system, run: @@ -145,12 +312,12 @@ $ ruby script/build To release, add `--release` as a parameter of the build script. -### Manually +#### Manually Building and releasing manually isn't too hard either, but there are a couple steps. -#### Tags +##### Tags To facilitate the images being found, we tag them with the following rules (as an example, the `3.1.5` version will be used.) @@ -161,7 +328,7 @@ an example, the `3.1.5` version will be used.) - Tag with `statusim/embark:3` if `3.1.5` is the highest minor and patch level on `3` -#### Generating the image +##### Generating the image To generate the image, run: @@ -169,7 +336,7 @@ To generate the image, run: docker build . -t statusim/embark: [...tags] ``` -## Releasing +### Releasing Releasing requires that you're authenticated to Docker Hub. To do so, run: @@ -177,7 +344,7 @@ Releasing requires that you're authenticated to Docker Hub. To do so, run: $ docker login ``` -### Scripted +#### Scripted If you have Ruby installed in your system, run: @@ -185,7 +352,7 @@ If you have Ruby installed in your system, run: $ ruby script/build --release ``` -### Manual +#### Manual Pushing the tags manually implies that the image has been previously built. To push your local images, run: From aa3e915549e5663ef57d0ecc797feddfe4e4c47e Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Wed, 1 Aug 2018 21:36:40 -0500 Subject: [PATCH 65/76] links should work --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8fd0673..0cfc79f 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,8 @@ variables, and that approach can be (optionally) combined with `docker build`: export EMBARK_DOCKER_EXTRA_RUN_OPTS='--rm' export EMBARK_DOCKER_IMAGE=statusim/embark export EMBARK_DOCKER_TAG=custom -export EMBARK_DOCKERFILE='https://github.com/embark-framework/embark-docker.git#develop' -export EMBARK_VERSION='embark-framework/embark#features/branch' +export EMBARK_DOCKERFILE='https://github.com/embark-framework/embark-docker.git#master' +export EMBARK_VERSION='embark-framework/embark#develop' export NODE_TAG=10.7.0 export RUNNER='https://raw.githubusercontent.com/embark-framework/embark-docker/master/run.sh' From b6a2abdb0aff153184f7e932f7b453659bfd7f89 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Wed, 1 Aug 2018 21:43:21 -0500 Subject: [PATCH 66/76] commands should work --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0cfc79f..ef34af2 100644 --- a/README.md +++ b/README.md @@ -268,7 +268,7 @@ container, `su-exec` and `bash -[i]c` can be used together: docker exec -it $container_id su-exec embark \ bash -ic 'exec bash << "SCRIPT" -simple_nodeenv 10.7.0 my_node +simple_nodeenv 10.7.0 my_node || nac my_node npm i -g http-server exec http-server -p 8000 @@ -283,7 +283,7 @@ docker exec -it $container_id su-exec embark \ bash -c 'exec bash << "SCRIPT" . ~/.bash_env -simple_nodeenv 10.7.0 my_node +simple_nodeenv 10.7.0 my_node || nac my_node npm i -g http-server exec http-server -p 8000 From c7b4ec25d06942e0f81d86a93d3e666fd1fbad91 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Wed, 1 Aug 2018 21:51:05 -0500 Subject: [PATCH 67/76] note re: quotes issues and envsubst w.r.t. here-docs --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ef34af2..5802bb6 100644 --- a/README.md +++ b/README.md @@ -170,7 +170,10 @@ run_embark bash -c 'nvm_load && nvm install --latest-npm 8.11.3 && node --versio Bash [here-documents](https://www.gnu.org/software/bash/manual/html_node/Redirections.html#Here-Documents) can be used to compose scripts without employing an abundance of `&&`, `;`, and -`\`: +`\`. Just be mindful of umatched quotes and quotes-escaping when building +meta-scripts; in such scenarios, use of +[envsubst](https://www.gnu.org/software/gettext/manual/html_node/envsubst-Invocation.html) +is probably called for. ``` shell run_embark bash -c 'exec bash << "SCRIPT" From 052a63183ef36548644826497dda63b1872f73d1 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Thu, 2 Aug 2018 09:47:25 -0500 Subject: [PATCH 68/76] don't need to source bash-it during build --- Dockerfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index b38c831..f30a5e6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -105,8 +105,6 @@ WORKDIR /home/embark RUN git clone --depth 1 \ https://github.com/Bash-it/bash-it.git \ .bash_it 2> /dev/null \ - && export BASH_IT=${HOME}/.bash_it \ - && . ${BASH_IT}/bash_it.sh \ && mkdir -p .bash_it/custom/themes/nodez \ && pip install --user nodeenv==${NODEENV_VERSION} \ && mkdir -p .local/nodeenv \ From 8c106bffd40c8e941582dbc9ba9f8ee7571b2af4 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Thu, 2 Aug 2018 09:48:03 -0500 Subject: [PATCH 69/76] reorder dir creation, installs --- Dockerfile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index f30a5e6..11f3580 100644 --- a/Dockerfile +++ b/Dockerfile @@ -106,16 +106,16 @@ RUN git clone --depth 1 \ https://github.com/Bash-it/bash-it.git \ .bash_it 2> /dev/null \ && mkdir -p .bash_it/custom/themes/nodez \ - && pip install --user nodeenv==${NODEENV_VERSION} \ - && mkdir -p .local/nodeenv \ - && export PATH=${HOME}/.local/bin:$PATH \ - && nodeenv --prebuilt \ - --node ${NODE_VERSION} \ - .local/nodeenv/default \ && git clone --branch v${NVM_VERSION} \ --depth 1 \ https://github.com/creationix/nvm.git \ .nvm 2> /dev/null \ + && export PATH=${HOME}/.local/bin:$PATH \ + && pip install --user nodeenv==${NODEENV_VERSION} \ + && mkdir -p .local/nodeenv \ + && nodeenv --prebuilt \ + --node ${NODE_VERSION} \ + .local/nodeenv/default \ && . .local/nodeenv/default/bin/activate \ && npm install -g "npm@${NPM_VERSION}" \ && npm install -g "embark@${EMBARK_VERSION}" \ From e77dbd736a1c9ef3f104abeb2426ab88cce6fc75 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Thu, 2 Aug 2018 12:25:16 -0500 Subject: [PATCH 70/76] revise strategy for `docker run` options, extra options --- run.sh | 92 +++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 65 insertions(+), 27 deletions(-) diff --git a/run.sh b/run.sh index 06c930c..c5cae5d 100755 --- a/run.sh +++ b/run.sh @@ -1,14 +1,43 @@ #!/usr/bin/env bash run_embark () { - local EMBARK_DOCKER_EXTRA_RUN_OPTS=${EMBARK_DOCKER_EXTRA_RUN_OPTS:-"-e __embark_docker_runsh"} local EMBARK_DOCKER_MOUNT_SOURCE=${EMBARK_DOCKER_MOUNT_DIR:-$PWD} local EMBARK_DOCKER_MOUNT_TARGET=${EMBARK_DOCKER_MOUNT_DIR:-/dapp} local EMBARK_DOCKER_IMAGE=${EMBARK_DOCKER_IMAGE:-statusim/embark} local EMBARK_DOCKER_RUN=${EMBARK_DOCKER_RUN} local EMBARK_DOCKER_RUN_INTERACTIVE=${EMBARK_DOCKER_RUN_INTERACTIVE:-false} + local EMBARK_DOCKER_RUN_OPTS_REPLACE=${EMBARK_DOCKER_RUN_OPTS_REPLACE:-false} local EMBARK_DOCKER_TAG=${EMBARK_DOCKER_TAG:-latest} + local -a run_opts=( + "-i" + "-t" + "-p" + "5001:5001" + "-p" + "8000:8000" + "-p" + "8080:8080" + "-p" + "8500:8500" + "-p" + "8545:8545" + "-p" + "8546:8546" + "-p" + "8555:8555" + "-p" + "8556:8556" + "-p" + "30301:30301/udp" + "-p" + "30303:30303" + "-v" + "${EMBARK_DOCKER_MOUNT_SOURCE}:${EMBARK_DOCKER_MOUNT_TARGET}" + "-e" + "TERM" + ) + local txtbld=$(tput bold) local txtrst=$(tput sgr0) @@ -20,7 +49,7 @@ run_embark () { local INFO=${bldcyn}INFO${txtrst} local WARNING=${bldylw}WARNING${txtrst} - local oldopts="" + local oldopts case $- in *e*) oldopts="set -e" ;; *) oldopts="set +e" ;; @@ -68,16 +97,42 @@ run_embark () { fi fi - local -a cmd=( "$@" ) - local -a extra_run_opts=( $EMBARK_DOCKER_EXTRA_RUN_OPTS ) + local had_run_opts=false + local -a _run_opts=() + local -a _cmd=() + local -a cmd + + while [[ ! -z "$1" ]]; do + if [[ "$1" = "--" ]]; then + had_run_opts=true + else + if [[ $had_run_opts = true ]]; then + _cmd=( "${_cmd[@]}" "$1" ) + else + _run_opts=( "${_run_opts[@]}" "$1" ) + fi + fi + shift + done + + if [[ $had_run_opts = true ]]; then + cmd=( "${_cmd[@]}" ) + if [[ $EMBARK_DOCKER_RUN_OPTS_REPLACE = true ]]; then + run_opts=( "${_run_opts[@]}" ) + else + run_opts=( "${run_opts[@]}" "${_run_opts[@]}" ) + fi + else + cmd=( "${_run_opts[@]}" ) + fi if [[ -z "$EMBARK_DOCKER_RUN" ]]; then - case $1 in + case "${cmd[0]}" in -V|--version|-h|--help|new|demo|build|run|blockchain|simulator|test|\ - reset|graph|upload|version) cmd=( "embark" "$cmd" ) ;; + reset|graph|upload|version) cmd=( "embark" "${cmd[@]}" ) ;; esac else - local i_flag= + local i_flag if [[ $EMBARK_DOCKER_RUN_INTERACTIVE = true ]]; then i_flag='i' else @@ -85,39 +140,22 @@ run_embark () { fi local run_script=$(< "$EMBARK_DOCKER_RUN") -# do not remove empty lines below # do not add indentation to lines below - run_script="exec bash -s $@ << 'SCRIPT' + run_script="exec bash -s ${cmd[@]} << 'SCRIPT' td=\$(mktemp -d) cat << 'RUN' > \$td/run_script $run_script RUN - chmod +x \$td/run_script -exec \$td/run_script $@ +exec \$td/run_script \$@ SCRIPT - " -# do not remove empty lines above # do not add indentation to lines above cmd=( "bash" "-${i_flag}c" "$run_script" ) fi docker run \ - -it \ - -p 5001:5001 \ - -p 8000:8000 \ - -p 8080:8080 \ - -p 8500:8500 \ - -p 8545:8545 \ - -p 8546:8546 \ - -p 8555:8555 \ - -p 8556:8556 \ - -p 30301:30301/udp \ - -p 30303:30303 \ - -v "${EMBARK_DOCKER_MOUNT_SOURCE}:${EMBARK_DOCKER_MOUNT_TARGET}" \ - -e TERM \ - "${extra_run_opts[@]}" \ + "${run_opts[@]}" \ "${EMBARK_DOCKER_IMAGE}:${EMBARK_DOCKER_TAG}" \ "${cmd[@]}" From 11c89d970145222720ce94de5c5b794c62515b4e Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Thu, 2 Aug 2018 12:51:08 -0500 Subject: [PATCH 71/76] rev README w.r.t. run.sh changes --- README.md | 48 +++++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 5802bb6..79ee7b0 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,13 @@ In a Bash shell: ``` shell source <(curl https://bit.ly/run_embark) run_embark demo -# ^ will create an embark_demo directory in the docker host's $PWD cd embark_demo run_embark ``` +Note that the `run_embark demo` command will create an `embark_demo` directory in +the docker host's `$PWD`. + ## Usage via `run.sh` [`run.sh`](https://github.com/embark-framework/embark-docker/blob/master/run.sh) @@ -21,12 +23,11 @@ Many aspects of the script's behavior can be overridden with environment variables, and that approach can be (optionally) combined with `docker build`: ``` shell -export EMBARK_DOCKER_EXTRA_RUN_OPTS='--rm' export EMBARK_DOCKER_IMAGE=statusim/embark export EMBARK_DOCKER_TAG=custom export EMBARK_DOCKERFILE='https://github.com/embark-framework/embark-docker.git#master' export EMBARK_VERSION='embark-framework/embark#develop' -export NODE_TAG=10.7.0 +export NODE_VERSION=10.7.0 export RUNNER='https://raw.githubusercontent.com/embark-framework/embark-docker/master/run.sh' docker build \ @@ -36,9 +37,9 @@ docker build \ $EMBARK_DOCKERFILE source <(curl $RUNNER) -run_embark demo +run_embark --rm -- demo cd embark_demo -run_embark +run_embark --rm -- ``` Review the @@ -47,6 +48,20 @@ and [run.sh](https://github.com/embark-framework/embark-docker/blob/master/run.sh) for all possible overrides. +It's possible to pass additional options to `docker run` by specifying them +before `--`: + +``` shell +run_embark [docker-run-opts] -- [command] +``` + +To completely replace the default `docker run` options: + +``` shell +EMBARK_DOCKER_RUN_OPTS_REPLACE=true +run_embark [docker-run-opts] -- [command] +``` + ### Shortcuts These are equivlent: @@ -82,7 +97,10 @@ The container comes equipped with [nodeenv](https://github.com/ekalinin/nodeenv) and [nvm](https://github.com/creationix/nvm). A `default` Node.js environment is installed via `nodeenv` during image build and placed in -`~embark/.local/nodeenv/default`. Both `nodeenv` and `nvm` can be used in +`~embark/.local/nodeenv/default`. The `default` environment is automatically +activated by the container's entrypoint. + +Both `nodeenv` and `nvm` can be used in interactive and non-interactive scripts. #### `nodeenv` @@ -205,16 +223,13 @@ For greater flexibility, you can specify a script with script, and extra flags can be provided to `docker run` to forward docker host environment variables. -Keep in mind that such scripts will be run as the `embark` user owing to the +Keep in mind that such scripts will run as the `embark` user owing to the container's entrypoint. ``` shell #!/bin/bash - # this script is located at /path/to/my_script.sh on the docker host, not necessarily in host's $PWD - # dangling " - c=container! echo $HOST_HOSTNAME echo $HOSTNAME @@ -228,22 +243,16 @@ eval echo \\\$\$3 ``` Invoke with: ``` shell -EMBARK_DOCKER_EXTRA_RUN_OPTS="-e HOST_HOSTNAME=$HOSTNAME" EMBARK_DOCKER_RUN=/path/to/my_script.sh - a=host! - -run_embark $a b c +run_embark -e HOST_HOSTNAME=$HOSTNAME -- $a b c ``` Node.js variant: ``` javascript #!/usr/bin/env node - // this script is located at /path/to/my_node_script.js on the docker host, not necessarily in host's $PWD - const o = {c: 'container!'}; - console.log(process.env.HOST_HOSTNAME); console.log(process.env.HOSTNAME); console.log(JSON.stringify(process.argv)); @@ -254,12 +263,9 @@ console.log(o[process.argv[4]]); ``` Invoke the same way: ``` shell -EMBARK_DOCKER_EXTRA_RUN_OPTS="-e HOST_HOSTNAME=$HOSTNAME" EMBARK_DOCKER_RUN=/path/to/my_node_script.js - a=host! - -run_embark $a b c +run_embark -e HOST_HOSTNAME=$HOSTNAME -- $a b c ``` #### `docker exec` From 1c54a3196cb297afc0aee638d9bb176ccc143556 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Thu, 2 Aug 2018 12:54:46 -0500 Subject: [PATCH 72/76] mention micro --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 79ee7b0..8080c30 100644 --- a/README.md +++ b/README.md @@ -146,6 +146,11 @@ nvm_load && nvm use v10.7.0 nac default ``` +#### `micro` + +The [micro](https://github.com/zyedidia/micro) editor is installed during image +build, should you need to edit files within a running container. + #### `install-extras.sh` Some nice-to-have utilities are not installed by default, but this can be done From 87abc0bfe0021b657b1ec2eeea873458455e53ef Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Thu, 2 Aug 2018 13:43:05 -0500 Subject: [PATCH 73/76] need to wrap in quotes (paths could have spaces), fix var name --- run.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/run.sh b/run.sh index c5cae5d..88f2ac3 100755 --- a/run.sh +++ b/run.sh @@ -1,13 +1,13 @@ #!/usr/bin/env bash run_embark () { - local EMBARK_DOCKER_MOUNT_SOURCE=${EMBARK_DOCKER_MOUNT_DIR:-$PWD} - local EMBARK_DOCKER_MOUNT_TARGET=${EMBARK_DOCKER_MOUNT_DIR:-/dapp} - local EMBARK_DOCKER_IMAGE=${EMBARK_DOCKER_IMAGE:-statusim/embark} - local EMBARK_DOCKER_RUN=${EMBARK_DOCKER_RUN} + local EMBARK_DOCKER_MOUNT_SOURCE="${EMBARK_DOCKER_MOUNT_SOURCE:-$PWD}" + local EMBARK_DOCKER_MOUNT_TARGET="${EMBARK_DOCKER_MOUNT_TARGET:-/dapp}" + local EMBARK_DOCKER_IMAGE="${EMBARK_DOCKER_IMAGE:-statusim/embark}" + local EMBARK_DOCKER_RUN="${EMBARK_DOCKER_RUN}" local EMBARK_DOCKER_RUN_INTERACTIVE=${EMBARK_DOCKER_RUN_INTERACTIVE:-false} local EMBARK_DOCKER_RUN_OPTS_REPLACE=${EMBARK_DOCKER_RUN_OPTS_REPLACE:-false} - local EMBARK_DOCKER_TAG=${EMBARK_DOCKER_TAG:-latest} + local EMBARK_DOCKER_TAG="${EMBARK_DOCKER_TAG:-latest}" local -a run_opts=( "-i" From eaf05016fb2a20a8ebf62d9990a5b2392035a752 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Thu, 2 Aug 2018 14:08:22 -0500 Subject: [PATCH 74/76] EMBARK_DOCKER_RUN_RM --- README.md | 18 ++++++++++++++++-- run.sh | 5 +++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8080c30..ec522a8 100644 --- a/README.md +++ b/README.md @@ -37,9 +37,9 @@ docker build \ $EMBARK_DOCKERFILE source <(curl $RUNNER) -run_embark --rm -- demo +run_embark demo cd embark_demo -run_embark --rm -- +run_embark ``` Review the @@ -62,6 +62,20 @@ EMBARK_DOCKER_RUN_OPTS_REPLACE=true run_embark [docker-run-opts] -- [command] ``` +By default `run.sh` invokes `docker run` with the +[`--rm`](https://docs.docker.com/engine/reference/run/#clean-up---rm) option, +making the embark container ephemeral, i.e. it will not persist on the docker +host's file system after the container exits. To override this behavior: + +``` shell +EMBARK_DOCKER_RUN_RM=false +run_embark [docker-run-opts] -- [command] +``` + +Note that if you have `EMBARK_DOCKER_RUN_OPTS_REPLACE=true`, then `--rm` would +need to be provided in `[docker-run-opts]`, i.e. `EMBARK_DOCKER_RUN_RM` will be +effectively ignored. + ### Shortcuts These are equivlent: diff --git a/run.sh b/run.sh index 88f2ac3..ea3666f 100755 --- a/run.sh +++ b/run.sh @@ -7,6 +7,7 @@ run_embark () { local EMBARK_DOCKER_RUN="${EMBARK_DOCKER_RUN}" local EMBARK_DOCKER_RUN_INTERACTIVE=${EMBARK_DOCKER_RUN_INTERACTIVE:-false} local EMBARK_DOCKER_RUN_OPTS_REPLACE=${EMBARK_DOCKER_RUN_OPTS_REPLACE:-false} + local EMBARK_DOCKER_RUN_RM=${EMBARK_DOCKER_RUN_RM:-true} local EMBARK_DOCKER_TAG="${EMBARK_DOCKER_TAG:-latest}" local -a run_opts=( @@ -38,6 +39,10 @@ run_embark () { "TERM" ) + if [[ $EMBARK_DOCKER_RUN_RM = true ]]; then + run_opts=( "${run_opts[@]}" "--rm" ) + fi + local txtbld=$(tput bold) local txtrst=$(tput sgr0) From 94d4493a789267e241cf35f80f2e35de6bcf160c Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Thu, 2 Aug 2018 14:12:15 -0500 Subject: [PATCH 75/76] should refer to `run_embark` vs. `run.sh` in some places --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ec522a8..e15d982 100644 --- a/README.md +++ b/README.md @@ -17,9 +17,10 @@ the docker host's `$PWD`. [`run.sh`](https://github.com/embark-framework/embark-docker/blob/master/run.sh) is a Bash script that simplifies usage of the embark container: publishing -ports, bind mounting a host volume, and so on. +ports, bind mounting a host volume, and so on. The script exports a shell +function named `run_embark`. -Many aspects of the script's behavior can be overridden with environment +Many aspects of `run_embark`'s behavior can be overridden with environment variables, and that approach can be (optionally) combined with `docker build`: ``` shell @@ -62,7 +63,7 @@ EMBARK_DOCKER_RUN_OPTS_REPLACE=true run_embark [docker-run-opts] -- [command] ``` -By default `run.sh` invokes `docker run` with the +By default `run_embark` invokes `docker run` with the [`--rm`](https://docs.docker.com/engine/reference/run/#clean-up---rm) option, making the embark container ephemeral, i.e. it will not persist on the docker host's file system after the container exits. To override this behavior: @@ -223,7 +224,7 @@ SCRIPT ' ``` -Since `run.sh` mounts the docker host's `$PWD` into the container's `/dapp`, and +Since `run_embark` mounts the docker host's `$PWD` into the container's `/dapp`, and since `/dapp` is the container's default working directory, it's also possible to do: From d6e455cc2778c741832bd22b46f9644bbd010ac6 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Thu, 2 Aug 2018 14:33:36 -0500 Subject: [PATCH 76/76] don't attempt to toggle history --- run.sh | 4 ---- 1 file changed, 4 deletions(-) diff --git a/run.sh b/run.sh index ea3666f..9781cb3 100755 --- a/run.sh +++ b/run.sh @@ -59,11 +59,7 @@ run_embark () { *e*) oldopts="set -e" ;; *) oldopts="set +e" ;; esac - if [[ $(shopt -po history) = "set -o history" ]]; then - oldopts="$oldopts; set -o history" - fi set +e - set +o history check_bash_version () { if [[ $BASH_VERSINFO -lt 4 ]]; then