forked from ethereum/go-ethereum
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
swarm/dev: add development environment (ethereum#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.
- Loading branch information
Showing
11 changed files
with
726 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
bin/* | ||
cluster/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
bin/* | ||
cluster/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
FROM ubuntu:xenial | ||
|
||
# install build + test dependencies | ||
RUN apt-get update && \ | ||
apt-get install --yes --no-install-recommends \ | ||
ca-certificates \ | ||
curl \ | ||
fuse \ | ||
g++ \ | ||
gcc \ | ||
git \ | ||
iproute2 \ | ||
iputils-ping \ | ||
less \ | ||
libc6-dev \ | ||
make \ | ||
pkg-config \ | ||
&& \ | ||
apt-get clean | ||
|
||
# install Go | ||
ENV GO_VERSION 1.8.1 | ||
RUN curl -fSLo golang.tar.gz "https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz" && \ | ||
tar -xzf golang.tar.gz -C /usr/local && \ | ||
rm golang.tar.gz | ||
ENV GOPATH /go | ||
ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH | ||
|
||
# install docker CLI | ||
RUN curl -fSLo docker.tar.gz https://get.docker.com/builds/Linux/x86_64/docker-17.04.0-ce.tgz && \ | ||
tar -xzf docker.tar.gz -C /usr/local/bin --strip-components=1 docker/docker && \ | ||
rm docker.tar.gz | ||
|
||
# install jq | ||
RUN curl -fSLo /usr/local/bin/jq https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64 && \ | ||
chmod +x /usr/local/bin/jq | ||
|
||
# install govendor | ||
RUN go get -u github.com/kardianos/govendor | ||
|
||
# add custom bashrc | ||
ADD bashrc /root/.bashrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.PHONY: build cluster test | ||
|
||
default: build | ||
|
||
build: | ||
go build -o bin/swarm github.com/ethereum/go-ethereum/cmd/swarm | ||
go build -o bin/geth github.com/ethereum/go-ethereum/cmd/geth | ||
go build -o bin/bootnode github.com/ethereum/go-ethereum/cmd/bootnode | ||
|
||
cluster: build | ||
scripts/boot-cluster.sh | ||
|
||
test: | ||
go test -v github.com/ethereum/go-ethereum/swarm/... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Swarm development environment | ||
============================= | ||
|
||
The Swarm development environment is a Linux bash shell which can be run in a | ||
Docker container and provides a predictable build and test environment. | ||
|
||
### Start the Docker container | ||
|
||
Run the `run.sh` script to build the Docker image and run it, you will then be | ||
at a bash prompt inside the `swarm/dev` directory. | ||
|
||
### Build binaries | ||
|
||
Run `make` to build the `swarm`, `geth` and `bootnode` binaries into the | ||
`swarm/dev/bin` directory. | ||
|
||
### Boot a cluster | ||
|
||
Run `make cluster` to start a 3 node Swarm cluster, or run | ||
`scripts/boot-cluster.sh --size N` to boot a cluster of size N. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
export ROOT="${GOPATH}/src/github.com/ethereum/go-ethereum" | ||
export PATH="${ROOT}/swarm/dev/bin:${PATH}" | ||
|
||
cd "${ROOT}/swarm/dev" | ||
|
||
cat <<WELCOME | ||
============================================= | ||
Welcome to the swarm development environment. | ||
- Run 'make' to build the swarm, geth and bootnode binaries | ||
- Run 'make test' to run the swarm unit tests | ||
- Run 'make cluster' to start a swarm cluster | ||
- Run 'exit' to exit the development environment | ||
See the 'scripts' directory for some useful scripts. | ||
============================================= | ||
WELCOME |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 "$@" |
Oops, something went wrong.