This project is Chef-Solo, this help to setup development base on Nodejs and Mysql
This also includes a demo about Simple API which using Express and Mysql
What was including
- Using Chef-solo for cooking
- Using Knife-solo for initialazing, adding, editing
cookbooks,roles,environment - Using librarian-chef for managing
cookbooks
Installing
- Installing
librarian-chefandknife-solo initialazing librarian, this would create new forder with named
cookbooksand aCheffilelibrarian-chef initAdding
nvmandmsqlcookbook toCheffilecookbook 'mysql', '~> 5.5.2' cookbook 'nvm', '~> 0.1.0'Initialazing
knife-solo, this would create the folder structureknife-solo initInstalling cookbooks from
Cheffilelibratian-chef installCreating an encryption key
openssl rand -base64 512 | tr -d 'rn' > ~/.chef/encrypted_data_bag_secret chmod 600 ~/.chef/encrypted_data_bag_secretAdding the path of encryption key to
.chef/knife.rbknife[:secret_file] = ".chef/encrypted_data_bag_secret"Creating a data bag, this stores the security inforamtion (ex database’s password)
knife solo data bag create secrets myapp
Enter something
{
"id": "myapp",
"aws_config": {
"AWSAccessKeyId": "xxx",
"AWSSecretKey": "xxx"
},
"db_config": {
"dev": [
{
"name": "default",
"mysql_root_password": "abc@123",
"hostname": "localhost",
"username": "root",
"password": "abc@123",
"database": "myqpp"
}
]
}
}
The encrypted data bag will be stored into
data-bag/secrets/myapp.js{ "id": "myapp", "aws_config": { "encrypted_data": "RjARHBKLm0DTbHDeIB5XjTjdWovyvv5T3V9T79UyEOq4/5Km6LaZ4y7leP7/\nNLCNQaJsUZQASaAII3bzkmwamecn03q5XUp4yDzeYcCqyRhP18BnyCxYDcOm\nc0HD1xEVuOanTt5R7ppJMj3kzN02YESN4CA/+70f0Qkp6yexhVo=\n", "iv": "Yr9pDrhjZjhLRxHEBna0nw==\n", "version": 1, "cipher": "aes-256-cbc" }, "db_config": { "encrypted_data": "F6iPNUMY+dzao52SpQqHEWlFbGWUBMWSBAy4FinaCQ0Tbh06nDPgSdNI7qoJ\n3DjfrLBZOV1/8xD9t+SkJI3BEvW+yxCnnDPEz+iiZ8/jYJaypy/Bhrn42EC4\ni2VPb66HnVYD4Uq0pObVWzhLATXfqNZ/79I/bTdHTuhGcynDNzRNjyYEDfIF\nG9SuooNjUAduwmLotW//XxMM4uFNZ04hww==\n", "iv": "DbN/KOPibOqNtAkLbdBr0w==\n", "version": 1, "cipher": "aes-256-cbc" } }Creating a owner cookbook (I created
myappcookbook), this should create atsite-cookbookfolderknife cookbook create myappConfigurating the default root password for mysql::server add
site-cookbooks/myapp/attributes/default.rb(create one if this file is not existed)secrets = Chef::EncryptedDataBagItem.load("secrets", "myapp") default['mysql']['server_root_password'] = secrets["db_config"][node.chef_environment][0]["mysql_root_password"] default['mysql']['server_debian_password'] = secrets["db_config"][node.chef_environment][0]["mysql_root_password"] default['mysql']['server_repl_password'] = secrets["db_config"][node.chef_environment][0]["mysql_root_password"]Installing
mysqlandnvmandnode 0.10.33insite-cookbooks/myapp/attributes/recipes/default.rbinclude_recipe "mysql::client" include_recipe "mysql::server" include_recipe 'nvm' # install node.js v0.10.5 nvm_install 'v0.10.33' do from_source true alias_as_default true action :create endCreating
deploy recipe, this recipe would help to deploy latest code fromgithubto server andstart/restart serverCreating the
enviroments(devfor Vagrant andprodfor real server)kinfe evironment create dev
Enter something
{
"name": "dev",
"description": "",
"cookbook_versions": {
},
"json_class": "Chef::Environment",
"chef_type": "environment",
"default_attributes": {
"myapp": {
"root_path": "/vagrant"
}
},
"override_attributes": {
}
}
Creating the
rolesknife role create myapp
Enter something
{
"name": "myapp",
"description": "",
"json_class": "Chef::Role",
"default_attributes": {
},
"override_attributes": {
},
"chef_type": "role",
"run_list": [
],
"env_run_lists": {
"dev": [
"recipe[myapp]",
"recipe[myapp::deploy]"
]
}
}
- Creating
Vagrantfilewhich would usechef-soloas provision
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |
Usage
Develop Environment using Vagrant
Notes:
- You must install Vagrant first
Install
vagrant-omnibuspluginvagrant plugin install vagrant-omnibus
Vagrant up
vagrant up
You see something like that
Running handlers:
[2014-11-02T07:16:20+00:00] INFO: Running report handlers
Running handlers complete
[2014-11-02T07:16:20+00:00] INFO: Report handlers complete
Chef Client finished, 30/36 resources updated in 756.082469267 seconds
Congratulation!!! You are Chef now :)
1
| |
License
Written by code-for-food
Copyright © 2014 Code-For-Food.
Welcome any comments, please contact me via
- Email: code.for.food.14@gmail.com