Go to the AWS console, find the EC2 instance, and find the instance public ip address. It should look like this: ec2-54-161-201-224.compute-1.amazonaws.com. The rest of the instructions will refer to this as
ssh ec2-user@<instance public ip> (this should let you in without prompting you for a password. if not, you chose a key when you launched that you don’t have locally)
2015-11-03T19:37:05.384Z ==== Couchbase Sync Gateway/1.1.0(28;86f028c) ====
2015-11-03T19:37:05.384Z Opening db /sync_gateway as bucket "sync_gateway", pool "default", server <http://localhost:8091>
2015-11-03T19:37:05.384Z Opening Couchbase database sync_gateway on <http://localhost:8091>
2015/11/03 19:37:05 Trying with selected node 0
2015/11/03 19:37:05 Trying with selected node 0
2015-11-03T19:37:05.536Z Using default sync function 'channel(doc.channels)' for database "sync_gateway"
2015-11-03T19:37:05.536Z Reset guest user to config
2015-11-03T19:37:05.536Z Starting profile server on
2015-11-03T19:37:05.536Z Starting admin server on 127.0.0.1:4985
2015-11-03T19:37:05.550Z Starting server on localhost:4984 ...
Verify via curl
From your workstation:
1
$ curl http://<instance public ip>:4984/sync_gateway/
For more advanced Sync Gateway configuration, you will want to create a JSON config file on the EC2 instance itself and pass that to Sync Gateway when you launch it, or host your config JSON on the internet somewhere and pass Sync Gateway the URL to the file.
View Couchbase Server UI
In order to login to the Couchbase Server UI, go to :8091 and use:
Joyent has recently announced their new Triton Docker container hosting service. There are several advantages of running Docker containers on Triton over a more traditional cloud hosting platform:
Better performance since there is no hardware level virtualization overhead. Your containers run on bare-metal.
Simplified networking between containers. Each container gets its own private (and optionally public) ip address.
Hosts are abstracted away — you just deploy into the “container cloud”, and don’t care which host your container is running on.
$ cd sdc-docker
$ ./tools/sdc-docker-setup.sh -k 165.225.168.22 $ACCOUNT ~/.ssh/$PRIVATE_KEY_FILE
Replace values as follows:
$ACCOUNT: you can get this by logging into the Joyent web ui and going to the Account menu from the pulldown in the top-right corner. Find the Username field, and use that
$PRIVATE_KEY_FILE: the name of the file where your private key is stored, typically this will be id_rsa
Run the command and you should see the following output:
1234567891011121314151617181920
Setting up Docker client for SDC using:
CloudAPI: https://165.225.168.22
Account: <your username>
Key: /home/ubuntu/.ssh/id_rsa
[..snip..]
Wrote certificate files to /home/ubuntu/.sdc/docker/<username>
Docker service endpoint is: tcp://<generated ip>:2376
* * *
Success. Set your environment as follows:
export DOCKER_CERT_PATH=/home/ubuntu/.sdc/docker/<username>
export DOCKER_HOST=tcp://<generated-ip>:2376
alias docker="docker --tls"
Then you should be able to run 'docker info' and see your account
name 'SDCAccount: <username>' in the output.
Export environment variables
As the output above suggests, copy and paste the commands from the output. Here’s an example of what that will look like (but you should copy and paste from your command output, not the snippet below):
123
$ export DOCKER_CERT_PATH=/home/ubuntu/.sdc/docker/<username>
$ export DOCKER_HOST=tcp://<generated-ip>:2376
$ alias docker="docker --tls"
Docker Hello World
Let’s spin up an Ubuntu docker image that says hello world.
Remember you’re running the Docker client on your workstation, not in the cloud. Here’s an overview on what’s going to be happening:
To start the docker container::
1
$ docker run --rm ubuntu:14.04 echo "Hello Docker World, from Joyent"
You should see the following output:
1234
Unable to find image 'ubuntu:14.04' locally
Pulling repository library/ubuntu
...
Hello Docker World, from Joyent
Also, since the --rm flag was passed, the container will have been removed after exiting. You can verify this by running docker ps -a. This is important because stopped containers incur charges on Joyent.
Congratulations! You’ve gotten a “hello world” Docker container running on Joyent.
Run Couchbase Server containers
Now it’s time to run Couchbase Server.
To kick off three Couchbase Server containers, run:
1234
$ for i in `seq 1 3`; do \
echo "Starting container $i"; \
export container_$i=$(docker run --name couchbase-server-$i -d -P couchbase/server); \
done
To confirm the containers are up, run:
1
$ docker ps
and you should see:
1234
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5bea8901814c couchbase/server "couchbase-start" 3 minutes ago Up 2 minutes couchbase-server-1
bef1f2f32726 couchbase/server "couchbase-start" 2 minutes ago Up 2 minutes couchbase-server-2
6f4e2a1e8e63 couchbase/server "couchbase-start" 2 minutes ago Up About a minute couchbase-server-3
At this point you will have environment variables defined with the container ids of each container. You can check this by running:
Each container will have two IP addresses assigned:
A public IP, accessible from anywhere
A private IP, only accessible from containers/machines in your Joyent account
To get the public IP, we can use the Docker client. (to get the private IP, you need to use the Joyent SmartDataCenter tools, which is described below)
Open your browser to $container_1_ip:8091 and you should see:
At this point, it’s possible to setup the cluster by going to each Couchbase node’s Web UI and following the Setup Wizard. However, in case you want to automate this in the future, let’s do this over the command line instead.
Setup first Couchbase node
Let’s arbitrarily pick container_1 as the first node in the cluster. This node is special in the sense that other nodes will join it.
The following command will do the following:
Set the Administrator’s username and password to Administrator / password (you should change this)
Set the cluster RAM size to 600 MB
Note: the -u admin -p password should be left as-is, since that is just passing in the default admin name and password for auth purposes.
If you see SUCCESS, then it worked. (I’m not sure why the “close failed in file ..” error is happening, but so far it appears that it can be safely ignored.)
Login to Web UI
Open your browser to $container_1_ip:8091 and you should see:
Login with:
Username: Administrator
Password: password
And you should see:
Congratulations! You have a Couchbase Server cluster up and running on Joyent Triton.
Teardown
To stop and remove your Couchbase server containers, run:
To double check that you no longer have any containers running or in the stopped state, run docker ps -a and you should see an empty list.
Installing the SDC tools (optional)
Installing the Joyent Smart Data Center (SDC) tools will allow you to gain more visibility into your container cluster — for example being able to view the internal IP of each continer.
ACCOUNT: you can get this by logging into the Joyent web ui and going to the Account menu from the pulldown in the top-right corner. Find the Username field, and use that
List machines
Run sdc-listmachines to list all the containers running under your Joyent account. Your output should look something like this:
I got a new computer last week. It’s the latest macbook retina, and I needed to refresh because I wanted a bigger SSD drive (and after having an SSD drive, I’ll never go back)
Anyway, I’m trying to get my Octopress blog going again, and oh my God, what a nightmare. Octopress was working beautifully for me for years, and then all of the sudden I am at the edge of Ruby Dependency Hell staring at an Octopress giving me eight fingers.
With the help of Docker, I’ve managed to tame this eight legged beast, barely.
This blog post assumes you already have an Octopress git repo. If you are starting from scratch, then check out Octopress Setup Part I to become even more confused.
Install Octopress Docker image
1
$ docker run -ti tleyden5iwx/octopress /bin/bash
After this point, the rest of the instructions assume that you are executing commands from inside the Docker Container.
Delete Octopress dir + clone your Octopress repo
The Docker container will contain an Octopress directory, but it’s not needed.
From within the container:
1234
$ cd /root
$ rm -rf octopress/
$ git clone https://github.com/your-github-username/your-github-username.github.io.git octopress
$ cd octopress/
Now, switch to the source branch (which contains the content)
NOTE: I have no idea why bundle exec is required here, I just used this in response to a previous error message and it’s accompanying suggestion.
If this gives no errors, that’s a good sign.
Create a new blog post
1
$ bundle exec rake new_post["Setting up Octopress under Docker"]
It will tell you the path to the blog post. Now open the file in your favorite editor and add contect.
Push to Source branch
The source branch has the source markdown content. It’s actually the most important thing to preserve, because the HTML can always be regnerated from it.
This will walk you through setting up a test coverage report on coveralls.io which will be updated every time a new build happens on drone.io (a continuous integration server similar to TavisCI).
I’m going to use the couchbaselabs/sg-replicate repo as an example, since it currently does not have any test coverage statistics. The goal is to end up with a badge in the README that points to a test coverage report hosted on coveralls.io.
Clone the repo
12
$ git clone https://github.com/couchbaselabs/sg-replicate.git
$ cd sg-replicate
Test coverage command line stats
123
$ go test -cover
go tool: no such tool "cover"; to install:
go get golang.org/x/tools/cmd/cover
Try again:
1234
$ go get golang.org/x/tools/cmd/cover && go test -cover
PASS
coverage: 69.4% of statements
ok github.com/couchbaselabs/sg-replicate 0.156s
Ouch, 69.4% is barely a C-. (if you round up!)
Coverage breakdown
Text report:
123456
$ go test -coverprofile=coverage.out
$ go tool cover -func=coverage.out
github.com/couchbaselabs/sg-replicate/attachment.go:15: NewAttachment 84.6%
github.com/couchbaselabs/sg-replicate/changes_feed_parameters.go:20: NewChangesFeedParams 100.0%
github.com/couchbaselabs/sg-replicate/changes_feed_parameters.go:30: FeedType 100.0%
github.com/couchbaselabs/sg-replicate/changes_feed_parameters.go:34: Limit 100.0%
HTML report:
12
$ go test -coverprofile=coverage.out
$ go tool cover -html=coverage.out
This should open up the following report in your default browser:
Coveralls.io setup
Login to coveralls.io
Create a new repo
Get the repo token from the SET UP COVERALLS section
At this point, your empty coveralls repo will look something like this:
Configure Drone.io + Goveralls
If you have not already done so, setup a drone.io build for your repo.
On the drone.io Settings page, make the following changes:
Environment Variables
In the Environment Variables section of the web ui, add:
1
COVERALLS_TOKEN=<coveralls_repo_token>
Commands
In the commands section, you can replace your existing go test call with:
123
go get github.com/axw/gocov/gocov
go get github.com/mattn/goveralls
goveralls -service drone.io -repotoken $COVERALLS_TOKEN
Here’s what it should look like:
Kick off a build
Go to the drone.io project page for your repo, and hit Build Now
At the bottom of the build output, you should see:
12
Job #1.1
https://coveralls.io/jobs/5189501
If you follow the link, you should see something like:
Looks like we just went from a C- to a B! I have no idea why the coverage improved, but I’ll take it.
Add a badge, call it a day
On the coveralls.io project page for your repo, you should see a button near the top called Badge URLS. Click and copy/paste the markdown, which should look something like this:
KeyPair: the name of the AWS keypair you want to use. If you haven’t already, you’ll want to upload your local ssh key into AWS and create a named keypair.
Wait until instances are up
ssh into a CoreOS instance
Go to the AWS console under EC2 instances and find the public ip of one of your newly launched CoreOS instances.
Choose any one of them (it doesn’t matter which), and ssh into it as the core user with the cert provided in the previous step:
1
$ ssh -i aws.cer -A core@ec2-54-83-80-161.compute-1.amazonaws.com
Spin up Sync Gateway containers
12
$ etcdctl set /couchbase.com/enable-code-refresh true
$ sudo docker run --net=host tleyden5iwx/couchbase-cluster-go update-wrapper sync-gw-cluster launch-sgw --num-nodes=2 --config-url=http://git.io/hFwa --in-memory-db
Verify etcd entries
12345
$ etcdctl ls --recursive /
...
/couchbase.com/sync-gw-node-state
/couchbase.com/sync-gw-node-state/10.169.70.114
/couchbase.com/sync-gw-node-state/10.231.220.110
This will walk you through the basics of putting data into seriesly and visualizing it with cubism.
You will end up with this in your browser:
Install seriesly
1
go get -u -v -t github.com/dustin/seriesly
Run seriesly
1
seriesly -flushDelay=1s -root=/tmp/seriesly-data
and leave it running in the background.
Create a db
In another shell:
1
curl -X PUT http://localhost:3133/testdb
Write docs to db
This script will write json docs with random values for the purpose of visualization.
Copy the following to add_seriesly_docs.rb
123456789
#!/usr/bin/env ruby
6000.times do |count|
randomNumber = rand() # random number between 0 and 1
cmd = "curl -X POST -d '{\"index\":#{randomNumber}}' http://localhost:3133/testdb"
puts cmd
system(cmd)
system("sleep 1")
end
Follow the steps below to create a Sync Gateway instance running under AWS with the following architecture:
It will be using the Walrus in-memory database, and so it is only useful for light testing. Walrus does have the abiity to snapshot its memory contents to a file, so your data can persist across restarts.
Congratulations! You now have a Sync Gateway running.
It might feel underwhelming, because nothing appears to be happening, but sync gateway is actually running in the background. To verify that, run:
123
$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d22035060882 tleyden5iwx/sync-gateway-coreos:latest "sync-gw-start -c ma About a minute ago Up About a minute sync_gw
You can take this sample config and customize it to your needs, and then upload it somewhere on the web.
Make sure you keep the server field as "walrus:data", since that tells Sync Gateway to use walrus and to store the data in the /opt/sync_gateway/data directory.
This will walk you through the steps to install the TodoLite-Phonegap sample app that uses Couchbase Lite Android. After you’re finished, you’ll end up with this app.
Creating a new cordova project with name "TodoLite" and id "com.couchbase.TodoLite" at location "/Users/tleyden/Development/todo-lite"
Using custom www assets from https://github.com/phonegap/phonegap-app-hello-world/archive/master.tar.gz
Downloading com.phonegap.hello-world library for www...
Download complete
cd into the newly created directory:
1
$ cd todo-lite
Add the Couchbase Lite plugin
1
$ phonegap local plugin add https://github.com/couchbaselabs/Couchbase-Lite-PhoneGap-Plugin.git
You should see the following output:
[warning] The command `phonegap local <command>` has been DEPRECATED.
[warning] The command has been delegated to `phonegap <command>`.
[warning] The command `phonegap local <command>` will soon be removed.
Fetching plugin "https://github.com/couchbaselabs/Couchbase-Lite-PhoneGap-Plugin.git" via git clone
Add additional plugins required by TodoLite-Phonegap
123
$ phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-camera.git
$ phonegap local plugin add https://github.com/apache/cordova-plugin-inappbrowser.git
$ phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information.git
$ phonegap local plugin add Couchbase-Lite-PhoneGap-Plugin
You should see output:
[warning] The command phonegap local <command> has been DEPRECATED.
[warning] The command has been delegated to phonegap <command>.
[warning] The command phonegap local <command> will soon be removed.
I found the official docs on using Google Protocol Buffers from Go a bit confusing, and couldn’t find any other clearly written blog posts on the subject, so I figured I’d write my own.
This will walk you through the following:
Install golang/protobuf and required dependencies
Generating Go wrappers for a test protocol buffer definition
Using those Go wrappers to marshal and unmarshal an object
Install protoc binary
Since the protocol buffer compiler protoc is required later, we must install it.
Ubuntu 14.04
If you want to use an older version (v2.5), simply do:
1
$ apt-get install protobuf-compiler
Otherwise if you want the latest version (v2.6):
12345
$ apt-get install build-essential
$ wget https://protobuf.googlecode.com/svn/rc/protobuf-2.6.0.tar.gz
$ tar xvfz protobuf-2.6.0.tar.gz
$ cd protobuf-2.6.0
$ ./configure && make install
OSX
1
$ brew install protobuf
Install Go Protobuf library
This assumes you have Go 1.2+ or later already installed, and your $GOPATH variable set.
In order to generate Go wrappers, we need to install the following:
12
$ go get -u -v github.com/golang/protobuf/proto
$ go get -u -v github.com/golang/protobuf/protoc-gen-go
Download a test .proto file
In order to generate wrappers, we need a .proto file with object definitions.
This one is a slightly modified version of the one from the official docs.
package main
import (
"log"
"github.com/golang/protobuf/proto"
)
func main() {
test := &Test{
Label: proto.String("hello"),
Type: proto.Int32(17),
Optionalgroup: &Test_OptionalGroup{
RequiredField: proto.String("good bye"),
},
}
data, err := proto.Marshal(test)
if err != nil {
log.Fatal("marshaling error: ", err)
}
newTest := &Test{}
err = proto.Unmarshal(data, newTest)
if err != nil {
log.Fatal("unmarshaling error: ", err)
}
// Now test and newTest contain the same data.
if test.GetLabel() != newTest.GetLabel() {
log.Fatalf("data mismatch %q != %q", test.GetLabel(), newTest.GetLabel())
}
log.Printf("Unmarshalled to: %+v", newTest)
}
Explanation:
Lines 11-14: Create a new object suitable for protobuf marshalling and populate it’s fields. Note that using proto.String(..) / proto.Int32(..) isn’t strictly required, they are just convencience wrappers to get string / int pointers.
Line 18: Marshal to a byte array.
Line 22: Create a new empty object.
Line 23: Unmarshal previously marshalled byte array into new object
Line 28: Verify that the “label” field made the marshal/unmarshall round trip safely
Run it via:
1
$ go run main.go test.pb.go
and you should see the output:
1
Unmarshalled to: label:"hello" type:17 OptionalGroup{RequiredField:"good bye" }
Congratulations! You are now using protocol buffers from Go.