From 59cf3182f81dfe022816f2648f7e8c791013c314 Mon Sep 17 00:00:00 2001 From: u2takey Date: Fri, 27 Apr 2018 21:43:34 +0800 Subject: [PATCH] add vagrant environment for development --- .gitignore | 1 + hack/vagrant/README.md | 29 +++++++++++++++++++++ hack/vagrant/Vagrantfile | 22 ++++++++++++++++ hack/vagrant/bootstrap.sh | 54 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 106 insertions(+) create mode 100644 hack/vagrant/README.md create mode 100644 hack/vagrant/Vagrantfile create mode 100644 hack/vagrant/bootstrap.sh diff --git a/.gitignore b/.gitignore index 05296e484d..7b2cca081a 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ coverage.txt .*.swp .editorconfig .bashrc +.vagrant diff --git a/hack/vagrant/README.md b/hack/vagrant/README.md new file mode 100644 index 0000000000..fd047db776 --- /dev/null +++ b/hack/vagrant/README.md @@ -0,0 +1,29 @@ +# Vagrant Setup to Test the Pouch + +This documentation highlights how to use [Vagrant](https://www.vagrantup.com/) to setup node to test pouch. + +## Pre-requisites + +This was tested on: + +- Vagrant 1.9.5 +- VirtualBox 5.1.26 + +## Getting Started + +Clone this repo, change to the `hack/vagrant` directory and let Vagrant do the work. + + $ vagrant up + $ vagrant status + Current machine states: + + pouch-dev-node running (virtualbox) + +You are now ready to SSH to `pouch-dev-node`, source code of pouch is mounted to /go/src/github.com/alibaba/pouch on `pouch-dev-node`. + + $ vagrant ssh pouch-dev-node + vagrant@pouch-dev-node:~$ sudo su + root@pouch-dev-node:/home/vagrant# cd /go/src/github.com/alibaba/pouch/ + root@pouch-dev-node:/go/src/github.com/alibaba/pouch# make && make test + ...... + diff --git a/hack/vagrant/Vagrantfile b/hack/vagrant/Vagrantfile new file mode 100644 index 0000000000..209b10e986 --- /dev/null +++ b/hack/vagrant/Vagrantfile @@ -0,0 +1,22 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + + +# refer: https://github.com/hashicorp/vagrant/issues/9442 +Vagrant::DEFAULT_SERVER_URL.replace('https://vagrantcloud.com') + +Vagrant.configure("2") do |config| + config.vm.boot_timeout=600 + # ubuntu/xenial64 is from official ubuntu 16.04 LTS (Xenial Xerus) daily build, which is + # based on the long-term supported Linux release series 4.4, refer: https://app.vagrantup.com/ubuntu + config.vm.box = "ubuntu/xenial64" + config.vm.provision :shell, path: "bootstrap.sh" + config.vm.synced_folder "../../", "/go/src/github.com/alibaba/pouch" + + config.vm.define "pouch-dev-node" do |node| + node.vm.network "private_network", ip: "172.30.30.10" + node.vm.hostname = "pouch-dev-node" + end + + config.vm.box_check_update = false +end diff --git a/hack/vagrant/bootstrap.sh b/hack/vagrant/bootstrap.sh new file mode 100644 index 0000000000..3bee68463d --- /dev/null +++ b/hack/vagrant/bootstrap.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env bash + +set -euo pipefail + +GOVERSION="${GOVERSION:-1.9.1}" +SOURCEPATH="${SOURCEPATH:-/go/src/github.com/alibaba/pouch}" + + +# install_pkgs install pkgs such as git/libncurses5-dev/... +# which is useful for pouch development environment +install_pkgs(){ + apt-get update + apt-get install -y git \ + libncurses5-dev \ + libslang2-dev \ + gettext \ + zlib1g-dev \ + libselinux1-dev \ + debhelper \ + lsb-release \ + pkg-config \ + po-debconf \ + autoconf \ + automake \ + autopoint \ + libtool +} + +# install_go install go with version $GOVERSION with goenv +install_go(){ + git clone --depth=1 https://github.com/syndbg/goenv.git ~/.goenv + + PROFILE="$HOME/.bashrc" + echo 'export GOENV_ROOT="$HOME/.goenv"' >> $PROFILE + echo 'export PATH="$GOENV_ROOT/bin:$PATH"' >> $PROFILE + echo 'eval "$(goenv init -)"' >> $PROFILE + echo 'export GOPATH="/go"' >> $PROFILE + + $HOME/.goenv/bin/goenv install $GOVERSION + $HOME/.goenv/bin/goenv global $GOVERSION +} + +# install_docker install docker with get.docker.com's shell script +install_docker(){ + curl -fsSL get.docker.com -o get-docker.sh + sh get-docker.sh +} +main() { + install_pkgs + install_go + install_docker +} + +main