
Photo credit: EdgeCase, LLC

Photo credit: EdgeCase, LLC

Photo credit: EdgeCase, LLC

Photo credit: EdgeCase, LLC

Photo credit: EdgeCase, LLC





git add . git commit -a -m 'A description of the change' git push cap production deployIt would be nice if I could do all of the above with just one command. So I created this shell script:
push() {
# Defaults
MINLEN=25
DIRTY=false
DEPLOY="production deploy"
REMOTE_REPO = "origin master"
# Check if we have any untracked files
if git status | grep -q "modified:"
then
DIRTY=true
fi
# Make sure there is a message with the commit
if [ -z "$1" ] && (test $DIRTY == true)
then
echo "You must specify a message with your commit"
return
elif [ ${#1} -lt $MINLEN ] && (test $DIRTY == true)
then
echo "Your message must have at least $MINLEN letters."
return
fi
# Commit all the changes by default
if (test $DIRTY == true)
then
echo "Adding new files to Git repository"
git add .
echo "Commiting to local Git repository"
git commit -a -m "$1"
# Push changes if a remote repository exists
if git remote | grep -q "origin"
then
echo "Pushing changes to remote repository"
git push $REMOTE_REPO
fi
fi
# Deploy changes via Capistrano
if ls | grep -q Capfile
then
cap $DEPLOY
fi
}
The 'push' function will first check to make sure you supplied a description if any recent changes were made. Second, it will commit all the code and push it to the remote repository (if one exists).
push "The description for the committed changes."That's it! All the code is added, commited, pushed, and deployed.
smtp.gmail.com example@yourdomain.com:yourpasswordThen tell Postfix about our google accounts information so it knows how and where to relay the email to. This can be done with the postmap command:
$ postmap /etc/postfix/relay_passwordSince Gmail requires a TLS (Transport Layer Security) connection for certificate-based authentication, we'll need to download a free root certificate from Verisign https://www.verisign.com/support/roots.html to authenticate our remote SMTP client.
$ mkdir /etc/postfix/certs $ cd /etc/postfix/certs $ sudo cp roots.zip /etc/postfix/certs $ sudo unzip -j roots.zip $ sudo openssl x509 -inform der -in ThawtePremiumServerCA.cer -out ThawtePremiumServerCA.pem $ sudo c_rehash /etc/postfix/certsNow we are ready to configure Postfix. Postfix needs to know what host to relay the email to, the username and password to authenticate the Gmail account, and the path to our certificates for the encrypted session. Add these lines to the bottom of /etc/postfix/main.cf
relayhost = smtp.gmail.com:587 # auth smtp_sasl_auth_enable = yes smtp_sasl_password_maps = hash:/etc/postfix/relay_password smtp_sasl_security_options = noanonymous # tls smtp_tls_security_level = may smtp_tls_CApath = /etc/postfix/certs smtp_tls_session_cache_database = btree:/etc/postfix/smtp_scache smtp_tls_session_cache_timeout = 3600s smtp_tls_loglevel = 1 tls_random_source = dev:/dev/urandomRestart (or start) Postfix to pick up our new changes.
$ sudo postfix stop $ sudo postfix startThat's it! Now we don't have to do any special installation or configuration to send email via Gmail for our Rails apps. We just need to set the delivery method to :smtp and we're ready to go.