Merge pull request #4 from embark-framework/features/env-flexibility
env flexibility — round 2
This commit is contained in:
commit
e8c66c9258
223
Dockerfile
223
Dockerfile
|
@ -1,65 +1,180 @@
|
|||
FROM node:8.11.3-stretch
|
||||
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
|
||||
|
||||
MAINTAINER Andre Medeiros <andre@status.im>
|
||||
# multi-stage builder images
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
ENV EMBARK_VERSION=3.1.5 \
|
||||
GANACHE_VERSION=6.1.4 \
|
||||
GETH_VERSION=1.8.11-dea1ce05 \
|
||||
IPFS_VERSION=0.4.15
|
||||
FROM ${BUILDER_BASE_IMAGE}:${BUILDER_BASE_TAG} as builder-base
|
||||
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"]
|
||||
|
||||
# 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
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
FROM builder-base as builder-geth
|
||||
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" \
|
||||
&& tar -xvzf geth-alltools* \
|
||||
&& rm geth-alltools*/COPYING
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
FROM builder-base as builder-ipfs
|
||||
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" \
|
||||
&& curl -fsSLO --compressed "${url}/${ver}_${platform}.tar.gz" \
|
||||
&& tar -xvzf go-ipfs*
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
FROM builder-base as builder-micro
|
||||
ARG MICRO_VERSION
|
||||
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
|
||||
RUN git clone --branch v${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 <andre@status.im>"
|
||||
|
||||
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 \
|
||||
# Install geth
|
||||
&& 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}*"\
|
||||
# Install ipfs
|
||||
&& 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
|
||||
&& 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
|
||||
|
||||
COPY --from=builder-ipfs /go-ipfs/ipfs /usr/local/bin/
|
||||
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}" \
|
||||
# Initialize IPFS
|
||||
WORKDIR /home/embark
|
||||
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 \
|
||||
&& 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}" \
|
||||
"ganache-cli@${GANACHE_VERSION}" \
|
||||
&& 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"]'
|
||||
|
||||
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"]
|
||||
USER root
|
||||
WORKDIR /dapp
|
||||
ENTRYPOINT ["docker-entrypoint.sh"]
|
||||
CMD ["embark", "run"]
|
||||
# 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
|
||||
|
||||
CMD ["embark"]
|
||||
|
||||
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/
|
||||
|
|
358
README.md
358
README.md
|
@ -1,17 +1,337 @@
|
|||
# Embark for Docker
|
||||
|
||||
## Updating versions
|
||||
## Quick start
|
||||
|
||||
In a Bash shell:
|
||||
``` shell
|
||||
source <(curl https://bit.ly/run_embark)
|
||||
run_embark demo
|
||||
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)
|
||||
is a Bash script that simplifies usage of the embark container: publishing
|
||||
ports, bind mounting a host volume, and so on. The script exports a shell
|
||||
function named `run_embark`.
|
||||
|
||||
Many aspects of `run_embark`'s behavior can be overridden with environment
|
||||
variables, and that approach can be (optionally) combined with `docker build`:
|
||||
|
||||
``` shell
|
||||
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_VERSION=10.7.0
|
||||
export RUNNER='https://raw.githubusercontent.com/embark-framework/embark-docker/master/run.sh'
|
||||
|
||||
docker build \
|
||||
--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 demo
|
||||
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)
|
||||
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]
|
||||
```
|
||||
|
||||
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:
|
||||
|
||||
``` 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:
|
||||
|
||||
``` shell
|
||||
run_embark
|
||||
```
|
||||
``` shell
|
||||
run_embark run
|
||||
```
|
||||
``` shell
|
||||
run_embark embark run
|
||||
```
|
||||
|
||||
The following are also equivalent:
|
||||
|
||||
``` shell
|
||||
run_embark demo
|
||||
```
|
||||
``` shell
|
||||
run_embark embark demo
|
||||
```
|
||||
|
||||
The same is true for the rest of the `embark` commands. To see the full list:
|
||||
|
||||
``` shell
|
||||
run_embark --help
|
||||
```
|
||||
|
||||
### 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`. 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`
|
||||
|
||||
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
|
||||
```
|
||||
|
||||
#### `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
|
||||
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:
|
||||
|
||||
``` shell
|
||||
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
|
||||
`\`. 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"
|
||||
|
||||
simple_nodeenv 10.7.0 my_node
|
||||
npm i -g http-server
|
||||
exec http-server -p 8000
|
||||
|
||||
SCRIPT
|
||||
'
|
||||
```
|
||||
|
||||
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:
|
||||
|
||||
``` 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 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_RUN=/path/to/my_script.sh
|
||||
a=host!
|
||||
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));
|
||||
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_RUN=/path/to/my_node_script.js
|
||||
a=host!
|
||||
run_embark -e HOST_HOSTNAME=$HOSTNAME -- $a b c
|
||||
```
|
||||
|
||||
#### `docker exec`
|
||||
|
||||
When executing compound commands via `docer exec` in a running embark
|
||||
container, `su-exec` and `bash -[i]c` can be used together:
|
||||
|
||||
``` shell
|
||||
docker exec -it $container_id su-exec embark \
|
||||
bash -ic 'exec bash << "SCRIPT"
|
||||
|
||||
simple_nodeenv 10.7.0 my_node || nac my_node
|
||||
npm i -g http-server
|
||||
exec http-server -p 8000
|
||||
|
||||
SCRIPT
|
||||
'
|
||||
```
|
||||
|
||||
To go non-interactive, manually source the embark user's `.bash_env`:
|
||||
|
||||
``` shell
|
||||
docker exec -it $container_id su-exec embark \
|
||||
bash -c 'exec bash << "SCRIPT"
|
||||
|
||||
. ~/.bash_env
|
||||
simple_nodeenv 10.7.0 my_node || nac my_node
|
||||
npm i -g http-server
|
||||
exec http-server -p 8000
|
||||
|
||||
SCRIPT
|
||||
'
|
||||
```
|
||||
|
||||
## Container development
|
||||
|
||||
### Updating versions
|
||||
|
||||
* Open `Dockerfile`
|
||||
* On the `ENV` directive, update necessary versions.
|
||||
* On the `ARG` directives, update necessary versions.
|
||||
|
||||
An exception to this is the NodeJS version, which needs to be updated in the `FROM` directive instead.
|
||||
### Building
|
||||
|
||||
## Building
|
||||
Building requires Docker to be installed on your local machine.
|
||||
|
||||
Building requires Docker to be installed on your local machine.
|
||||
|
||||
### Scripted
|
||||
#### Scripted
|
||||
|
||||
If you have Ruby installed in your system, run:
|
||||
|
||||
|
@ -21,20 +341,23 @@ $ 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.
|
||||
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.)
|
||||
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
|
||||
##### Generating the image
|
||||
|
||||
To generate the image, run:
|
||||
|
||||
|
@ -42,7 +365,7 @@ To generate the image, run:
|
|||
docker build . -t statusim/embark:<version> [...tags]
|
||||
```
|
||||
|
||||
## Releasing
|
||||
### Releasing
|
||||
|
||||
Releasing requires that you're authenticated to Docker Hub. To do so, run:
|
||||
|
||||
|
@ -50,7 +373,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:
|
||||
|
||||
|
@ -58,9 +381,10 @@ 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:
|
||||
Pushing the tags manually implies that the image has been previously built. To
|
||||
push your local images, run:
|
||||
|
||||
```
|
||||
docker push statusim/embark:version
|
||||
|
|
|
@ -0,0 +1,129 @@
|
|||
unset BASH_ENV
|
||||
|
||||
export PATH=${HOME}/.local/bin:$PATH
|
||||
|
||||
nac () {
|
||||
local txtbld=$(tput bold)
|
||||
local txtrst=$(tput sgr0)
|
||||
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
|
||||
. ${HOME}/.local/nodeenv/$1/bin/activate
|
||||
if [[ $? != 0 ]]; then
|
||||
__denac
|
||||
return 1
|
||||
fi
|
||||
__versions_export
|
||||
alias denac='deactivate_node'
|
||||
alias deactivate_node='__denac'
|
||||
case $- in
|
||||
*i*) __npm_completion ;;
|
||||
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 () {
|
||||
unalias denac &> /dev/null
|
||||
unalias deactivate_node &> /dev/null
|
||||
if type deactivate_node &> /dev/null; then
|
||||
deactivate_node
|
||||
fi
|
||||
. ${HOME}/.bash_env_denac
|
||||
unset NODE_VERSION
|
||||
unset NPM_VERSION
|
||||
}
|
||||
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*) __nvm_unload ;;
|
||||
*) unalias nvm; nvm "$@"; alias nvm='__nvm_mask'; __versions_export ;;
|
||||
esac
|
||||
}
|
||||
export -f __nvm_mask
|
||||
}
|
||||
export -f nvm_load
|
||||
|
||||
__nvm_load () {
|
||||
__nvm_unload
|
||||
__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
|
||||
*i*) __npm_completion ;;
|
||||
esac
|
||||
fi
|
||||
}
|
||||
export -f __nvm_load
|
||||
|
||||
__nvm_unload () {
|
||||
unalias nvm_load &> /dev/null
|
||||
unalias nvm &> /dev/null
|
||||
unset __nvm_mask
|
||||
if type nvm &> /dev/null; then
|
||||
nvm unload
|
||||
fi
|
||||
unset NODE_VERSION
|
||||
unset NPM_VERSION
|
||||
}
|
||||
export -f __nvm_unload
|
||||
|
||||
simple_nodeenv () {
|
||||
pushd $PWD &> /dev/null
|
||||
cd ${HOME}/.local/nodeenv
|
||||
nodeenv --prebuilt --node "$@"
|
||||
if [[ $? != 0 ]]; then
|
||||
popd &> /dev/null
|
||||
return 1
|
||||
fi
|
||||
popd &> /dev/null
|
||||
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
|
||||
|
||||
nac default
|
|
@ -0,0 +1,2 @@
|
|||
unset npm_config_prefix
|
||||
unset NPM_CONFIG_PREFIX
|
|
@ -0,0 +1,2 @@
|
|||
unset npm_config_prefix
|
||||
unset NPM_CONFIG_PREFIX
|
|
@ -0,0 +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
|
|
@ -0,0 +1,6 @@
|
|||
#!/bin/bash
|
||||
|
||||
export BASH_ENV=/home/embark/.bash_env
|
||||
|
||||
chmod a+w /dev/std*
|
||||
exec su-exec embark user-entrypoint.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
|
|
@ -0,0 +1,74 @@
|
|||
# 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=""
|
||||
|
||||
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 [[ "$env" != "" ]]; then
|
||||
env="[${bold_yellow}$env${normal}"
|
||||
if [[ ! -v NODE_VERSION ]]; then
|
||||
env+="]"
|
||||
fi
|
||||
echo "$env"
|
||||
fi
|
||||
}
|
||||
|
||||
__nodez_nv() {
|
||||
if [[ -v NODE_VERSION ]]; then
|
||||
local nv="=${__nodez_char_node}${NODE_VERSION}"
|
||||
nv+="${__nodez_char_npm}${NPM_VERSION}]"
|
||||
echo "$nv"
|
||||
fi
|
||||
}
|
||||
|
||||
__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
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
|
||||
exec "$@"
|
|
@ -0,0 +1,2 @@
|
|||
# TODO: helper script that offers for `docker exec ` similar conveniences as
|
||||
# run.sh provides for `docker run`
|
|
@ -0,0 +1,180 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
run_embark () {
|
||||
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_RUN_RM=${EMBARK_DOCKER_RUN_RM:-true}
|
||||
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"
|
||||
)
|
||||
|
||||
if [[ $EMBARK_DOCKER_RUN_RM = true ]]; then
|
||||
run_opts=( "${run_opts[@]}" "--rm" )
|
||||
fi
|
||||
|
||||
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}
|
||||
|
||||
local oldopts
|
||||
case $- in
|
||||
*e*) oldopts="set -e" ;;
|
||||
*) oldopts="set +e" ;;
|
||||
esac
|
||||
set +e
|
||||
|
||||
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 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 "${cmd[0]}" 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 add indentation to lines below
|
||||
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 \$@
|
||||
SCRIPT
|
||||
"
|
||||
# do not add indentation to lines above
|
||||
cmd=( "bash" "-${i_flag}c" "$run_script" )
|
||||
fi
|
||||
|
||||
docker run \
|
||||
"${run_opts[@]}" \
|
||||
"${EMBARK_DOCKER_IMAGE}:${EMBARK_DOCKER_TAG}" \
|
||||
"${cmd[@]}"
|
||||
|
||||
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 "$@"
|
||||
fi
|
Loading…
Reference in New Issue