Skip to content

Commit

Permalink
add docs and dev-env
Browse files Browse the repository at this point in the history
  • Loading branch information
binhn committed Apr 3, 2016
1 parent ab19b1c commit 871095d
Show file tree
Hide file tree
Showing 107 changed files with 8,144 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@
*.yaml text eol=lf
*.yml text eol=lf
*.md text eol=lf
*.json text eol=lf
*.proto text eol=lf
*.py text eol=lf
*.js text eol=lf
*.txt text eol=lf
LICENSE text eol=lf
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ node-cli/node-cli
.DS_Store
tags
.tags
/obcca/.obcca
/obcca/.obcca
.vagrant/
26 changes: 26 additions & 0 deletions devenv/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## openchain-dev-env

If you're looking for instructions on how to setup the Openchain development environment, see
the [obc-docs project](https://github.com/openblockchain/obc-docs/blob/master/dev-setup/devenv.md).

This is the openchain development environment project which is used for bootstrapping the openchain development environment.

Below is a deployment diagram of the current develpment environment. Note that version numbers may be out of date.
![Development Environment Deployment Diagram](./images/openchain-dev-env-deployment-diagram.png)

# Storage Backends

You may optionally choose a docker storage backend other than the default.

For a comparison of the assorted storage backends refer to [select a storage driver](https://docs.docker.com/engine/userguide/storagedriver/selectadriver/)

Presently, the default is set to AUFS, but this may change in the future.

To select a different storage backend (btrfs in this example), simply execute

```
vagrant destroy
DOCKER_STORAGE_BACKEND=btrfs vagrant up
```

Currently supported backends are btfs, and aufs, with more to be added in the future.
92 changes: 92 additions & 0 deletions devenv/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

# This vagrantfile creates a VM with the development environment
# configured and ready to go.
#
# The setup script (env var $script) in this file installs docker.
# This is not in the setup.sh file because the docker install needs
# to be secure when running on a real linux machine.
# The docker environment that is installed by this script is not secure,
# it depends on the host being secure.
#
# At the end of the setup script in this file, a call is made
# to run setup.sh to create the developer environment.

# This is the mount point for the sync_folders of the source
SRCMOUNT = "/openchain"

if not ENV.has_key?('GOPATH')
abort("GOPATH is not set")
end

HOST_GOPATH = ENV['GOPATH']
HOST_OBC_PEER_DIR = HOST_GOPATH + "/src/github.com/openblockchain/obc-peer"

if not Dir.exists?(HOST_OBC_PEER_DIR)
abort("obc-peer directory '" + HOST_OBC_PEER_DIR + "' does not exist")
end

$script = <<SCRIPT
set -x
export DOCKER_STORAGE_BACKEND="#{ENV['DOCKER_STORAGE_BACKEND']}"
cd #{SRCMOUNT}/obc-dev-env
./setup.sh
SCRIPT

Vagrant.configure('2') do |config|
config.vm.box = "obc/baseimage"
config.vm.box_version = ENV['USE_LOCAL_OBC_BASEIMAGE'] ? "0":"0.0.9" # Vagrant does not support versioning local images, the local version is always implicitly version 0

config.vm.network :forwarded_port, guest: 5000, host: 3000 # Openchain REST services
config.vm.network :forwarded_port, guest: 30303, host: 30303 # Openchain gRPC services

config.vm.synced_folder "..", "#{SRCMOUNT}"
config.vm.synced_folder "#{HOST_OBC_PEER_DIR}", "/opt/gopath/src/github.com/openblockchain/obc-peer"

config.vm.provider :virtualbox do |vb|
vb.name = "openchain"
vb.customize ['modifyvm', :id, '--memory', '4096']
vb.cpus = 2

storage_backend = ENV['DOCKER_STORAGE_BACKEND']
case storage_backend
when nil,"","aufs","AUFS"
# No extra work to be done
when "btrfs","BTRFS"
# Add a second disk for the btrfs volume
IO.popen("VBoxManage list systemproperties") { |f|

success = false
while line = f.gets do
# Find the directory where the machine images are stored
machine_folder = line.sub(/^Default machine folder:\s*/,"")

if line != machine_folder
btrfs_disk = File.join(machine_folder, vb.name, 'btrfs.vdi')

unless File.exist?(btrfs_disk)
# Create the disk if it doesn't already exist
vb.customize ['createhd', '--filename', btrfs_disk, '--format', 'VDI', '--size', 20 * 1024]
end

# Add the disk to the VM
vb.customize ['storageattach', :id, '--storagectl', 'SATAController', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', btrfs_disk]
success = true

break
end
end
raise Vagrant::Errors::VagrantError.new, "Could not provision btrfs disk" if !success
}
else
raise Vagrant::Errors::VagrantError.new, "Unknown storage backend type: #{storage_backend}"
end

end

config.vm.provision :shell, inline: $script
end
29 changes: 29 additions & 0 deletions devenv/baseimage/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
NAME="obc/baseimage"
VAGRANTIMAGE=packer_virtualbox-iso_virtualbox.box

# strips off the post-processors that try to upload artifacts to the cloud
packer-local.json: packer.json
jq 'del(."post-processors"[0][1]) | del(."post-processors"[1][1])' packer.json > $@

all:
packer build packer.json

$(VAGRANTIMAGE): packer-local.json
packer build -only virtualbox-iso packer-local.json

docker: packer-local.json
packer build -only docker packer-local.json

vagrant: $(VAGRANTIMAGE) remove
vagrant box add -name $(NAME) $(VAGRANTIMAGE)

push:
@echo "You will need your ATLAS_TOKEN set for this to succeed"
packer push -name $(NAME) packer.json

remove:
-vagrant box remove --box-version 0 $(NAME)

clean: remove
-rm $(VAGRANTIMAGE)
packer-local.json
53 changes: 53 additions & 0 deletions devenv/baseimage/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Baseimage Introduction
This directory contains the infrastructure for creating a new baseimage used as the basis for various functions within the openblockchain workflow such as our Vagrant based development environment, chaincode compilation/execution, unit-testing, and even cluster simulation. It is based on ubuntu-14.04 with various opensource projects added such as golang, rocksdb, grpc, and node.js. The actual openblockchain code is injected just-in-time before deployment. The resulting images are published to public repositories such as [atlas.hashicorp.com](https://atlas.hashicorp.com/obc/boxes/baseimage) for consumption by Vagrant/developers and [hub.docker.com](https://hub.docker.com/r/openblockchain/baseimage/) for consumption by docker-based workflows.

![Baseimage Architectural Overview](./images/packer-overview.png)

The purpose of this baseimage is to act as a bridge between a raw ubuntu/trusty64 configuration and the customizations required for supporting an openchain environment. Some of the FOSS components that need to be added to Ubuntu do not have convenient native packages. Therefore, they are built from source. However, the build process is generally expensive (often taking in excess of 30 minutes) so it is fairly inefficient to JIT assemble these components on demand.

Therefore, the expensive FOSS components are built into this baseimage once and subsequently cached on the public repositories so that workflows may simply consume the objects without requiring a local build cycle.

# Intended Audience
This is only intended for release managers curating the base images on atlas and docker-hub. Typical developers may safely ignore this directory completely.

Anyone wishing to customize their image is encouraged to do so via downstream means, such as the vagrant infrastructure in the root directory of this project or the Dockerfile.

## Exceptions

If a component is found to be both broadly applicable and expensive to build JIT, it may be a candidate for inclusion in a future baseimage.

# Usage

## Usage Pattern 1 - Local baseimage builds for testing a proposed change

* "make vagrant" will build just the vagrant image and install it into the local environment as "obc/baseimage:v0", making it suitable to local testing.
* To utilize the new base image in your local tests, run `vagrant destroy` then `USE_LOCAL_OBC_BASEIMAGE=true vagrant up`, also preface `vagrant ssh` as `USE_LOCAL_OBC_BASEIMAGE=true vagrant ssh` or simply export that variable, or Vagrant will fail to find the ssh key.
* "make docker" will build just the docker image and commit it to your local environment as "openblockchain/baseimage"

## Usage Pattern 2 - Release manager promoting a new base image to the public repositories

- Step 1: Decide on the version number to be used and update the packer.json template variables:release
- Step 2: Initiate a build

Note: You will need credentials to the public repositories, as discussed in Uploading Permissions below. If you do not have these credentials, you are probably not an image release manager. Otherwise, discuss it on the OBC slack to see if you should be added.

### Hosted Build Method

"make push" will push the build configuration to atlas for cloud-hosted building of the images. You only need to have the ATLAS_TOKEN defined for this to succeed, as the atlas build server will push the artifacts out to the respective hosts once the build completes. Therefore, the repository credentials are already cached on the build server and you only need credentials for the build-server itself. You can check the status of the build [here](https://atlas.hashicorp.com/obc/build-configurations/baseimage/)

### Local Build Method

"make [all]" will generate both a vagrant and docker image and push them out to the cloud. This method requires both ATLAS and DOCKERHUB credentials since the artifacts are pushed directly to the hosting providers from your build machine.

## Uploading Permissions

The system relies on several environment variables to establish credentials with the hosting repositories:

* ATLAS_TOKEN - used to push both vagrant images and packer templates to atlas.hashicorp.com
* DOCKERHUB_[EMAIL|USERNAME|PASSWORD] - used to push docker images to hub.docker.com

Note that if you only plan on pushing the build to the atlas packer build service, you only need the ATLAS_TOKEN set as the dockerhub interaction will occur from the atlas side of the process where the docker credentials are presumably already configured.

## Versioning

Vagrant boxes are only versioned when they are submitted to a repository. Vagrant does not support applying a version to a vagrant box via the `vagrant box add` command. Adding the box gives it an implicit version of 0. Setting `USE_LOCAL_OBC_BASEIMAGE=true` in the `vagrant up` command causes the Vagrant file in the the parent directory to pick version 0, instead of the default.
34 changes: 34 additions & 0 deletions devenv/baseimage/http/preseed.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
debconf debconf/frontend select Noninteractive
choose-mirror-bin mirror/http/proxy string
d-i clock-setup/utc boolean true
d-i clock-setup/utc-auto boolean true
d-i finish-install/reboot_in_progress note
d-i grub-installer/only_debian boolean true
d-i grub-installer/with_other_os boolean true
d-i partman-auto/choose_recipe select atomic
d-i partman-auto/method string regular
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true
d-i partman/confirm_write_new_label boolean true

# Set the kernel
d-i base-installer/kernel/override-image string linux-virtual

# Default user
d-i passwd/user-fullname string vagrant
d-i passwd/username string vagrant
d-i passwd/user-password password vagrant
d-i passwd/user-password-again password vagrant
d-i passwd/username string vagrant

# Minimum packages (see postinstall.sh)
d-i pkgsel/include string openssh-server
d-i pkgsel/install-language-support boolean false
d-i pkgsel/update-policy select none
d-i pkgsel/upgrade select none

d-i time/zone string UTC
d-i user-setup/allow-password-weak boolean true
d-i user-setup/encrypt-home boolean false
tasksel tasksel/first multiselect standard, server
Loading

0 comments on commit 871095d

Please sign in to comment.