How to deploy your hubot to Heroku and why your bot is not working after deploying

After completing the development of my Hubot, I decided to deploy it to Heroku.

I followed the tutorial on Github’s Hubot guideline as here.

For, short:

$ cd [path-to-your-hubot-folder]
$ heroku login

# Setup git (if not yet).
$ git init
$ git add .
$ git commit -m "Initial commit"

# Create a new heroku application.
$ heroku create

# Push to heroku master.
$ git push heroku master

# Set Slack token for heroku (Can be found at
# https://[your-slack-channel].slack.com/home 
# and under your Hubot app config).
$ heroku config:set HUBOT_SLACK_TOKEN=[xoxb-YOUR-TOKEN]

# Set heroku keep alive url (To keep your bot active).
$ heroku config:set HUBOT_HEROKU_KEEPALIVE_URL=$(heroku apps:info -s  | grep web-url | cut -d= -f2)

But my bot is not working at all, it keeps sleeping on the new Heroku’s bed and not responded to any of my commands.

I checked the build log on Heroku dashboard, it shows a lot of node modules are lack.

I viewed the .git_ignore file and its content:

node_modules
.DS_Store*
.hubot_history

So entire node_modules is ignored during commit and pushing to Heroku. So I think that it’s the reason why my bot is not working after deploying.

I forced to add the folder with -f parameter in git add command (or you can just remove the line in .git_ignore folder), then commit and push again to Heroku.

And finally… the monster awakens.

zsh cannot execute global npm packages

Today, I installed a npm package globally, no problem here.

Screen Shot 2017-03-11 at 2.01.37 PM.png

But, when I execute the package, there comes an error:

~  yo
zsh: command not found: yo

So, it means that the system doesn’t reallize the path to my package. I confirm by using:

~/W/C/htnmaruko  echo $PATH
/Users/duchoang/.rbenv/shims:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin

So that, we need to export the path to where my package is lying in.

Because I installed by -g parameter, so it is lying in global npm. In my case it is being in ~/.npm-global.

Steps:

1. Export your path in ~/.zshrc (in case of using zsh, otherwise using ~/.bashrc) by  print it to your ~/.zshrc or ~/.bashrc file:

~/.n/bin  printf "\nexport PATH=\"\$PATH\":%s\n" ~/.npm-global/bin >> ~/.zshrc

Or just editing with nano:

~  nano /Users/duchoang/.zshrc

2. Now, fire up the changes:

~  . ~/.zshrc

3. And finally, the problem gets solved, the result we have:

Screen Shot 2017-03-11 at 2.03.28 PM

Now we can get back to our work.

The git error: “gpg failed to sign the data”

Today, I need to commit some pieces of stuff to my GitHub repository, but somehow this error comes I don’t know.

It’s really painful.

error: gpg failed to sign the data
fatal: failed to write commit object

After some researches on Google, I know that Github has implemented something called GPG to sign and verify work from trusted collaborators, using public-secret key mechanism. (refer: https://help.github.com/articles/signing-commits-with-gpg/)

My below guide is used on MacOS. For other platforms, please refer this link for Windows and this link for Linux.

So, to solve the problem, I have to config gpg to be able to sign commits. Note that from now, I will use brew to manage my installations. To know more about brew, you could find so much information on Google or its homepage: https://brew.sh

1. We need pinentry to read passphrases and PIN numbers in a secure manner. (For more information: https://www.gnupg.org/related_software/pinentry/index.en.html)

~/W/G/TalentHub-solutions brew install pinentry-mac

2. We need gpg of course, I use gpg2

~/W/G/TalentHub-solutions ❯ brew install gpg2

3. Now we are ready to generate our secret key, I chose all by default.

~/W/G/TalentHub-solutions  gpg2 --gen-key

Screen Shot 2017-03-10 at 10.35.20 PM

4. Once you have a private key to sign with, you can configure Git to use it for signing things by setting the user.signingkey config setting.

4.1. Get your secret key:

~/W/G/TalentHub-solutions  gpg2 --list-secret-keys

You will see something like:

Screen Shot 2017-03-10 at 10.40.35 PM

Then, B069A034 is your secret key.

4.2. Config your signing key:

~/W/G/TalentHub-solutions  git config --global user.signingkey B069A034
~/W/G/TalentHub-solutions  git config --global gpg.program $(which gpg2)
~/W/G/TalentHub-solutions  git config --global commit.gpgsign true
~/W/G/TalentHub-solutions ❯❯❯ echo "no-tty" >> ~/.gnupg/gpg.conf

5. Point out the pinentry program to gpg-agent.conf:

~/W/G/TalentHub-solutions  touch  ~/.gnupg/gpg-agent.conf
~/W/G/TalentHub-solutions  echo "pinentry-program /usr/local/bin/pinentry-mac" >> ~/.gnupg/gpg-agent.conf

Now you will be able to commit to your git repository.

How to connect to localhost using Postgres Admin (pgadmin) in CentOS

First of all, a recall how to install Postgres and pgAdmin3 in CentOS (CentOS 6.8, Postgres 9.5 in my case):

Postgres:

[ducfilan@localhost]# su

[root@localhost]# wget https://download.postgresql.org/pub/repos/yum/9.5/redhat/rhel-6-x86_64/pgdg-centos95-9.5-3.noarch.rpm

[root@localhost]# rpm -ivh pgdg-centos95-9.5-3.noarch.rpm

[root@localhost]# yum install postgresql95-server postgresql95-devel postgresql95-contrib

[root@localhost]# service postgresql-9.5 initdb

[root@localhost]# service postgresql-9.5 start

[root@localhost]# chkconfig postgresql-9.5 on

And pgAdmin:

yum install pgadmin3_95

To start Postgres Admin:

[root@localhost]# pgadmin3

When you add a server to connect to localhost database, the error message appears:

postgresql The server doesn't accept the current user: The server report
Ident authentication failed
The server doesn't accept the current user: The server reports 

FATAL: Ident authentication failed for user "pgadmin" 
If this message appears, the pg_hba.conf entry found for your 
client / user / database combination is set to "ident" authentication.  
Some distributions, e.g. Debian, have this by default. To perform ident  
based authentication successfully, you need additional setup; see the  
PostgreSQL help for this. For a beginner, it might be more appropriate  
to use a different authentication method; MD5 encrypted passwords are  
a good choice, which can be configured by an entry in pg_hba.conf like  
this: 

host all all 192.168.0.0/24 md5 

This example grants MD5 encrypted password access to all databases to  
all users on the private network 192.168.0.0/24. 
You can use the pg_hba.conf editor that is built into pgAdmin III to  
edit the pg_hba.conf configuration file. After changing pg_hba.conf,  
you need to trigger a server configuration reload using pg_ctl or by  
stopping and restarting the server process. 

Look at the message, it means that ident authentication is not usable here.
We have to edit the pg_hba.conf file. After several researches, I knew the location of pg_hba.conf file, open it up:

[root@localhost]# nano /var/lib/pgsql/9.5/data/pg_hba.conf

You will find some ident here, change it to md5 (username – password authentication)
But…
Dont forget to restart the postgres service:

<[root@localhost]# service postgresql-9.5 restart

Try again, the sky will be brighter.

What to do if your Rails application cannot connect to Mysql?

When I use my Mac to continue developing my Rails application using Mysql as the database system. It first initialized and developed in Ubuntu.

After bundling tasks, I move to rake db:create to initialize my databases for development and test environment. But the problem comes out:

Mysql2::Error: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'

Ok, cd to the

/var/run/mysqld/

Oh, there’s no mysqld.sock there. Ok so there must be error as above error message.

So, I was wondering where is mysqld.sock in my computer? I was installed Mysql through brew and able to connect to Mysql by Mysql Workbench with no problem. So let’s see some variables. Enter to the terminal:

mysqladmin -p variables | grep socket

Provide password, and then you will see something like:

screen-shot-2016-09-24-at-10-16-58-pm

| performance_schema_max_socket_classes                    | 10

| performance_schema_max_socket_instances                  | -1

| socket                                                   | /tmp/mysql.sock|

Wow, there comes in the socket line the mysql.sock file location

We have to connect through it.

After some research, I know that Rails settings the socket in database.yml file.

So, it’s ez now, just replace the new found path.

It’s ok now. I can continue my work.