diff options
author | Lewis Marshall <lewis@lmars.net> | 2017-06-01 18:52:18 +0800 |
---|---|---|
committer | Felix Lange <fjl@users.noreply.github.com> | 2017-06-01 18:52:18 +0800 |
commit | 0036e2a74761413200ce3a8ed316ecb721895f60 (patch) | |
tree | 1ac94ec2c89a9055999056cd6d99e2955c4409fd /swarm/dev/run.sh | |
parent | 727eadacca761e4abb4273a87dc601bb79d3167d (diff) | |
download | dexon-0036e2a74761413200ce3a8ed316ecb721895f60.tar dexon-0036e2a74761413200ce3a8ed316ecb721895f60.tar.gz dexon-0036e2a74761413200ce3a8ed316ecb721895f60.tar.bz2 dexon-0036e2a74761413200ce3a8ed316ecb721895f60.tar.lz dexon-0036e2a74761413200ce3a8ed316ecb721895f60.tar.xz dexon-0036e2a74761413200ce3a8ed316ecb721895f60.tar.zst dexon-0036e2a74761413200ce3a8ed316ecb721895f60.zip |
swarm/dev: add development environment (#14332)
This PR adds a Swarm development environment which can be run in a
Docker container and provides scripts for building binaries and running
Swarm clusters.
Diffstat (limited to 'swarm/dev/run.sh')
-rwxr-xr-x | swarm/dev/run.sh | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/swarm/dev/run.sh b/swarm/dev/run.sh new file mode 100755 index 000000000..2ad600ded --- /dev/null +++ b/swarm/dev/run.sh @@ -0,0 +1,90 @@ +#!/usr/bin/env bash +# +# A script to build and run the Swarm development environment using Docker. + +set -e + +ROOT="$(cd "$(dirname "$0")/../.." && pwd)" + +# DEFAULT_NAME is the default name for the Docker image and container +DEFAULT_NAME="swarm-dev" + +usage() { + cat >&2 <<USAGE +usage: $0 [options] + +Build and run the Swarm development environment. + +Depends on Docker being installed locally. + +OPTIONS: + -n, --name NAME Docker image and container name [default: ${DEFAULT_NAME}] + -d, --docker-args ARGS Custom args to pass to 'docker run' (e.g. '-p 8000:8000' to expose a port) + -h, --help Show this message +USAGE +} + +main() { + local name="${DEFAULT_NAME}" + local docker_args="" + parse_args "$@" + build_image + run_image +} + +parse_args() { + while true; do + case "$1" in + -h | --help) + usage + exit 0 + ;; + -n | --name) + if [[ -z "$2" ]]; then + echo "ERROR: --name flag requires an argument" >&2 + exit 1 + fi + name="$2" + shift 2 + ;; + -d | --docker-args) + if [[ -z "$2" ]]; then + echo "ERROR: --docker-args flag requires an argument" >&2 + exit 1 + fi + docker_args="$2" + shift 2 + ;; + *) + break + ;; + esac + done + + if [[ $# -ne 0 ]]; then + usage + echo "ERROR: invalid arguments" >&2 + exit 1 + fi +} + +build_image() { + docker build --tag "${name}" "${ROOT}/swarm/dev" +} + +run_image() { + exec docker run \ + --privileged \ + --interactive \ + --tty \ + --rm \ + --hostname "${name}" \ + --name "${name}" \ + --volume "${ROOT}:/go/src/github.com/ethereum/go-ethereum" \ + --volume "/var/run/docker.sock:/var/run/docker.sock" \ + ${docker_args} \ + "${name}" \ + /bin/bash +} + +main "$@" |