Tuan Anh

container nerd. k8s || GTFO

Step by step how to install Deis on AWS

Deis (pronounced DAY-iss) is an open source PaaS that makes it easy to deploy and manage applications on your own servers. Deis builds upon Docker and CoreOS to provide a lightweight PaaS with a Heroku-inspired workflow.

I struggled installing Deis and it took me several times to get it right. Deis’s documentation is correct but not very straight forward so I decided to write this to help others that struggle like me. This steps works for me as of version 1.12.2

Preparation

  • Install deisctl. This is needed for provision script.
$ cd ~/bin
$ curl -sSL http://deis.io/deisctl/install.sh | sh -s <latest-version-here>
$ # on CoreOS, add "sudo" to install to /opt/bin/deisctl
$ curl -sSL http://deis.io/deisctl/install.sh | sudo sh -s <latest-version-here>
  • Install AWS Command line interface and configure it
$ pip install awscli
$ pip install pyyaml
$ aws configure
AWS Access Key ID [None]: ***************
AWS Secret Access Key [None]: ************************
Default region name [None]: us-west-1
Default output format [None]:
  • Generate and upload keys to AWS. Also add it to ssh-agent so that it can use during provisioning the cluster.
$ ssh-keygen -q -t rsa -f ~/.ssh/deis -N '' -C deis
$ aws ec2 import-key-pair --key-name deis --public-key-material file://~/.ssh/deis.pub
$ eval `ssh-agent -s`
$ ssh-add ~/.ssh/deis
  • If you want to use more than 3 instances (default), just export DEIS_NUM_INSTANCES
$ export DEIS_NUM_INSTANCES=5

Provision the cluster

  • Clone the repo, git checkout the latest tag. At repo root, run this command below to create discovery url. Forget to do this will result in etcd not configured properly.
$ make discovery-url
  • Next, go to folder contrib/aws/ in deis repo, create a file name cloudformation.json in order to override default values. You can take a look at the template file deis.template.json.

  • Run the provision script

$ cd contrib/aws
$ ./provision-aws-cluster.sh
Creating CloudFormation stack deis
{
    "StackId": "arn:aws:cloudformation:us-east-1:69326027886:stack/deis/1e9916b0-d7ea-11e4-a0be-50d2020578e0"
}
Waiting for instances to be created...
Waiting for instances to be created... CREATE_IN_PROGRESS
Waiting for instances to pass initial health checks...
Waiting for instances to pass initial health checks...
Waiting for instances to pass initial health checks...
Instances are available:
i-5c3c91aa  203.0.113.91    m3.large        us-east-1a      running
i-403c91b6  203.0.113.20    m3.large        us-east-1a      running
i-e36fc6ee  203.0.113.31    m3.large        us-east-1b      running
Using ELB deis-DeisWebE-17PGCR3KPJC54 at deis-DeisWebE-17PGCR3KPJC54-1499385382.us-east-1.elb.amazonaws.com
Your Deis cluster has been successfully deployed to AWS CloudFormation and is started.
Please continue to follow the instructions in the documentation.

Install platform

$ export DEISCTL_TUNNEL=<ip-address-of-any-of-the-cluster-node>
$ deisctl config platform set sshPrivateKey=~/.ssh/deis
$ deisctl config platform set domain=deis.example.com # create a CNAME point this to the load balancer
$ deisctl install platform
$ deisctl start platform

After this, you should have a proper configured Deis cluster. Just install the client, register an account and you should be ready to deploy your very first application on Deis.


Metalsmith - a static site generator written in Node.js

An extremely simple, pluggable static site generator.

Metalsmith works in three simple steps:

  • Read all the files in a source directory.

  • Invoke a series of plugins that manipulate the files.

  • Write the results to a destination directory!

Very simple yet powerful. Metalsmith is like gulp but made for static website/content.

link bài gốc

Snapp

Drag a window up to the menubar to maximize it, or drag a window to the side to resize it to the corresponding screen half.

Demo

link bài gốc

Possibly the easiest way to setup rtorrent/rutorrent

Installation script which is cumbersome, not very easy to use and sometimes goes unmaintained but you don’t know about that yet and ended messing up your VPS file system.

In this post, I will show you how to setup rtorrent/rutorrent with Docker. It’s rather easy and requires minimal knowledge about Linux in general.

Grab a KVM VPS from RamNode

I’m going with RamNode here but you can use any VPS provider you want. Be sure to select KVM because Docker is going to require a rather new kernel so OpenVZ won’t work. I select Ubuntu 14.04 in this tutorial. To make it easy to follow, you can do the same.

After finishing the payment, you will get an email containing your VPS information. You can perform some simple initial server setup to secure your VPS after this.

Install Docker

sudo apt-key adv --keyserver hkp://pgp.mit.edu:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D

sudo touch /etc/apt/sources.list.d/docker.list

sudo echo "deb https://apt.dockerproject.org/repo ubuntu-trusty main" > /etc/apt/sources.list.d/docker.list

sudo apt-get update

sudo apt-get install docker-engine

mkdir ~/rtorrent # folder for rtorrent docker

sudo usermod -aG docker <your-username> # use docker without sudo, if your user is in sudo group

Setup rtorrent/rutorrent

You will need to secure your rutorrent installation so that noone else except you can access it.

cd ~/rtorrent
printf "<username>:$(openssl passwd -apr1 "<your-passsword>")\n" > .htpasswd

Now we are going to use the Dockerfile made by diameter to simplify the whole process of setting up rtorrent/rutorrent/nginx. If you want to see the source code, you can check it out here on Docker Hub.

docker run -dt --name rtorrent-rutorrent -p 8080:80 -p 49160:49160/udp -p 49161:49161 -v ~/rtorrent:/downloads diameter/rtorrent-rutorrent:64

Let docker pull and build for awhile (1,2 mins at most) and you can navigate to http://<your-server-ip-address>:8080 to start using rutorrent.

rutorrent docker


Stuff you may not know about console

console.table()

var Person = function(name, age) {
    this.name = name
    this.age = age
}

var person_list = [
    new Person('wayne', 10),
    new Person('cristiano', 20),
    new Person('david', 30),
    new Person('bastian', 40)
]

console.table(person_list, ['name', 'age']) // filtering columns
console.table(person_list)

You’ll get a nice table like this

console.table

console.time()

console.time('Operation A')
var arr = []
for (var i =0; i < 100000; ++i) {
    arr.push(i)
}
console.timeEnd('Operation A')

> Operation A: 395.557ms

console.assert()

for (var i = 0; i < 100000; ++i) {
    console.assert(i % 1000, 'Iteration #%d', i)
}

This will only print when first arg (i % 1000) is false.

console.group()

Group so that you can collapse/expand messages within a group.

console.group('Group A')
console.log('First line')
console.log('Second line')
console.log('Third line')
console.groupEnd()


Node.js happy coding

I’ve been doing Node.js professionally for roughly 2 years. During that time, I’ve learnt a thing or two that keeps me away from troubles.


Use Promise instead of callback

ES6 gets native Promise already but if you prefer something more convenient that 3rd-party libraries offer, pick something like bluebird (it’s really really fast). Stay away from Q. I mean, just look at this.

Do not trust developer’s semver practice

use npm shrinkwrap instead

This command locks down the versions of a package's dependencies so that you can control exactly which versions of each dependency will be used when your package is installed.

Personally, i would prefer npm support something like --save-exact flag. That would be awesome.

Choosing the right dependency

You already have enough bug fixing jobs on your plate. Don’t import more from others’. There are several things that go into consideration when i need to install an extra package:

  • statistic on npm/github: popular is good

  • check if the project is active: last commit, etc..

  • check if the issues get resolved timely.

  • check unit testing is well covered?

  • check its dependencies: cover all things above. Personally, I wouldn’t want to use anything that depends on Q. It shows the author didn’t do the homework quite well, or at the very least, didn’t keep the package up to date with current situation in Node.js eco.

Use linter

Respect the code convention. The ultimate goal is having code written by different developers, looks as if they were written by the same person.


ES6 in Node.js

Get yourself ES6-ready in Node.js: arrow functions, map, generators, etc..

link bài gốc

Go Native - Calling C++ From NodeJS

I don’t usually have the need to do this but it would be fun practice to build a npm module by packaging some C++ libraries.

link bài gốc

Atom is slow but that's okay

I started using Atom from one of those early beta build. I wasn’t impressed. At that time, it was really slow (still is), taking several seconds just to load the app, freeze frequently when I tried to open log file (few MBs) and a bunch of other small bugs here and there. So I went back to Sublime and just keep an eye on Atom once in awhile (I left it in /Applications untouched)

Recently, a colleague of mine was trying to convince me to try Atom again. So I fire up terminal, rm -rf ~/.atom and update the app.

You should remove old Atom config since Atom is very actively developed and may have changed a lot since last you tried the app.

Atom feels much more polished this time. Despite the slow startup time still there, I feel very compelled to stick with Atom this time. I understand that Atom probably never going to achieve Sublime’s speed (due to its nature) but that’s ok. Here’s why:

Atom’s UI is closely resemble Sublime

The interface and everything is closely resemble Sublime so the learning curve is rather shallow. In fact, few people wouldn’t know they are looking at Atom or Sublime without glancing at the menubar.

Atom has done so many right things out of the box

Atom has done so many right things right out of the box. Stuff like keyboard shortcuts feel a lot more intuitive than Sublime.

I know, i know that we can re-map Sublime shortcuts as well. I did exactly that at first but working right out of the box still feels a lot nicer.

The older I get, the lazier I become when it comes to tinkering with settings to get it right. I remember my 18-yo self would plays with all kind of registry keys on Windows XP for the fun of it. I’m not like that anymore. I just want to forget about the editor and start coding.

Atom is very extensible

Most of the packages I used in Sublime is available on Atom as well; or at the very least, the equivalent exists.

I pretty much use vanilla Atom (default theme, default colorscheme) with a few packages installed: atom-alignment, atom-fuzzy-grep, auto-detect-indentation and highlight-selected. I highly recommend you to checkout atom-fuzzy-grep package. It allows you to use the_silver_searcher for fuzzy search your project. It’s freaking awesome and fast. Check it out.

Atom is actively developed by GitHub and community

It’s not that Sublime is abandoned but Atom development is much more active. It’s backed by GitHub and a huge open-source community vs few developers of Sublime. You know, the bus factors thing.


If you haven’t checked Atom in while (or at all), you should probably do. That’s my advice, coming from a hardcore Sublime fan.


Efficient branching workflow with git flow

Why aren’t you using git flow provides a nice overview on why you and your team should adapt using git flow in your workflow.

Keep this cheatsheet somewhere in case you need a quick reference.

link bài gốc