github.com/jincm/wesharechain@v0.0.0-20210122032815-1537409ce26a/chain/swarm/dev/run.sh (about) 1 #!/usr/bin/env bash 2 # 3 # A script to build and run the Swarm development environment using Docker. 4 5 set -e 6 7 ROOT="$(cd "$(dirname "$0")/../.." && pwd)" 8 9 # DEFAULT_NAME is the default name for the Docker image and container 10 DEFAULT_NAME="swarm-dev" 11 12 usage() { 13 cat >&2 <<USAGE 14 usage: $0 [options] 15 16 Build and run the Swarm development environment. 17 18 Depends on Docker being installed locally. 19 20 OPTIONS: 21 -n, --name NAME Docker image and container name [default: ${DEFAULT_NAME}] 22 -d, --docker-args ARGS Custom args to pass to 'docker run' (e.g. '-p 8000:8000' to expose a port) 23 -h, --help Show this message 24 USAGE 25 } 26 27 main() { 28 local name="${DEFAULT_NAME}" 29 local docker_args="" 30 parse_args "$@" 31 build_image 32 run_image 33 } 34 35 parse_args() { 36 while true; do 37 case "$1" in 38 -h | --help) 39 usage 40 exit 0 41 ;; 42 -n | --name) 43 if [[ -z "$2" ]]; then 44 echo "ERROR: --name flag requires an argument" >&2 45 exit 1 46 fi 47 name="$2" 48 shift 2 49 ;; 50 -d | --docker-args) 51 if [[ -z "$2" ]]; then 52 echo "ERROR: --docker-args flag requires an argument" >&2 53 exit 1 54 fi 55 docker_args="$2" 56 shift 2 57 ;; 58 *) 59 break 60 ;; 61 esac 62 done 63 64 if [[ $# -ne 0 ]]; then 65 usage 66 echo "ERROR: invalid arguments" >&2 67 exit 1 68 fi 69 } 70 71 build_image() { 72 docker build --tag "${name}" "${ROOT}/swarm/dev" 73 } 74 75 run_image() { 76 exec docker run \ 77 --privileged \ 78 --interactive \ 79 --tty \ 80 --rm \ 81 --hostname "${name}" \ 82 --name "${name}" \ 83 --volume "${ROOT}:/go/src/github.com/ethereum/go-ethereum" \ 84 --volume "/var/run/docker.sock:/var/run/docker.sock" \ 85 ${docker_args} \ 86 "${name}" \ 87 /bin/bash 88 } 89 90 main "$@"