Skip to content

Commit

Permalink
feat(vagrant): add Vagrant instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Nov 2, 2019
1 parent 6fb3722 commit 7e509c0
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.vagrant
/dapps

# emacs
*~

Expand Down
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
.vagrant

# Demo
demo
dapps

# scripts
scripts
Expand Down
42 changes: 38 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,51 @@
# Agoric Javascript Smart Contract Platform

## Getting Started
## Prerequisites

### Vagrant

To run a standardized Linux distribution with all the required development tools, you probably want [Vagrant](https://www.vagrantup.com/docs/):

```sh
vagrant up --provider=docker
# or
vagrant up --provider=virtualbox
# then
vagrant ssh
```

The Vagrant setup has synchronized filesystem access with the workspace directory on your host system, so you can use your favourite IDE to modify the files, and just run Linux commands on the SSH connection.


### Developing on the current OS

If you don't use Vagrant, you can develop on your own local operating system.

NOTE: You will need Go 1.12 or newer to run the Agoric VM.

```sh
# Install the agoric devtool.
# NOTE: If you can't do this, use `npx agoric` each time you see `agoric`
npm install -g agoric
```

or:

```sh
# Run the agoric devtool.
npx agoric [...options]
```

## Your first Agoric Dapp

Here is a simple script for how to get started.

```sh
cd dapps
# Initialize your dapp project.
agoric init my-dapp
# Note: Change the `demo` name to something meaningful.
agoric init demo
# Go to its directory.
cd my-dapp
cd demo
# Install Javascript/Go dependencies.
agoric install
# Run the local vat machine.
Expand Down
94 changes: 94 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
#
# Vagrant box for Debian with cosmic-swingset dependencies
#
# use one of:
# vagrant up --provider=docker
# vagrant up --provider=virtualbox

NODE_VERSION = "12.x"
GO_VERSION = "1.12.7"

CURRENT_DIR = File.dirname(__FILE__)

$script = <<SCRIPT
export DEBIAN_FRONTEND=noninteractive
apt-get update && apt-get install -y --no-install-recommends \
apt-transport-https \
ca-certificates \
unzip \
curl \
gnupg2 dirmngr \
software-properties-common \
vim
echo "Installing Node.js #{NODE_VERSION}"
curl -sL https:/deb.nodesource.com/setup_#{NODE_VERSION} | bash -
# apt-get install -y nodejs build-essential git
echo "Installing Go #{GO_VERSION}"
curl https://dl.google.com/go/go#{GO_VERSION}.linux-amd64.tar.gz > go#{GO_VERSION}.linux-amd64.tar.gz
tar -C /usr/local -zxf go#{GO_VERSION}.linux-amd64.tar.gz
cat > /etc/profile.d/99-golang.sh <<\EOF
GOROOT=/usr/local/go
GOPATH=\\\$HOME/go
PATH=\\\$GOPATH/bin:\\\$GOROOT/bin:\\\$PATH
export GOROOT GOPATH
EOF
apt-get update && apt-get install -y nodejs build-essential git rsync build-essential
cd /vagrant && npm install -g .
echo "Enjoy! :)"
SCRIPT

def get_ipaddr(hostname, default)
return Socket::getaddrinfo(hostname, nil)[0][3]
rescue SocketError
return default
end

Vagrant.configure("2") do |config|
config.vm.box = "debian/contrib-stretch64"
config.vm.hostname = "dev-agoric"

private_network_ip = get_ipaddr(config.vm.hostname, "10.10.10.11")
config.vm.network "private_network", ip: private_network_ip

config.vm.provision "shell", inline: $script
config.vm.provision "shell", inline: "echo 'cd /vagrant' >> .bash_profile", privileged: false

config.vm.post_up_message = \
"The private network IP address is: #{private_network_ip}\n\n" \
"To customize, set the host called '#{config.vm.hostname}'\n" \
"to the desired IP address in your /etc/hosts and run \n" \
"'vagrant reload'!\n"

config.vm.provider :virtualbox do |vb|
vb.name = "dev-agoric-vb"
end

config.vm.provider :docker do |docker, override|
override.vm.box = nil
docker.build_dir = "docker"
docker.build_args = ['-t', 'agoric/devtools:local']
docker.name = "dev-agoric-docker"
docker.ports = [
'127.0.0.1:8000:8000',
'127.0.0.1:9229:9229',
]
docker.remains_running = true
docker.has_ssh = true
docker.create_args = ['--tmpfs', '/tmp:exec', '--tmpfs', '/run',
'-v', '/sys/fs/cgroup:/sys/fs/cgroup:ro',
# '--volume=ag-solo-state:/vagrant/cosmic-swingset/solo',
# '--volume=ag-setup-cosmos-chains:/vagrant/cosmic-swingset/chains',
# '--volume=ag-cosmos-helper-state:/root/.ag-cosmos-helper',
'--privileged=true',
# '-v', '/var/run/docker.sock:/var/run/docker.sock',
]
end
end
28 changes: 28 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM debian:stretch
# MAINTAINER Tasos Latsas "tlatsas@kodama.gr"
LABEL maintainer="mfig@agoric.com"

RUN apt-get update \
&& apt-get install -y init openssh-server sudo curl python python3-venv python3-dev \
&& apt-get clean

RUN useradd --create-home --shell /bin/bash vagrant
RUN echo root:vagrant | chpasswd
RUN echo vagrant:vagrant | chpasswd

RUN mkdir -m 0700 /home/vagrant/.ssh
RUN curl https://github.com/raw/hashicorp/vagrant/master/keys/vagrant.pub \
> /home/vagrant/.ssh/authorized_keys
RUN chown -R vagrant:vagrant /home/vagrant/.ssh
RUN chmod 0600 /home/vagrant/.ssh/authorized_keys

RUN sed --regexp-extended --in-place \
's/^session\s+required\s+pam_loginuid.so$/session optional pam_loginuid.so/' \
/etc/pam.d/sshd

RUN echo 'vagrant ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/01_vagrant
RUN chmod 0400 /etc/sudoers.d/01_vagrant

RUN ln -sf /vagrant/cosmic-swingset /usr/src/app

CMD ["/sbin/init"]

0 comments on commit 7e509c0

Please sign in to comment.