Skip to content

Instantly share code, notes, and snippets.

@mattdell
Created March 13, 2017 11:31
Show Gist options
  • Save mattdell/91ae28bfc293a204919d6f5d4c2a96af to your computer and use it in GitHub Desktop.
Save mattdell/91ae28bfc293a204919d6f5d4c2a96af to your computer and use it in GitHub Desktop.
Deploy to Heroku using Drone CI
# This script is designed to work with Drone IO for Continuous Integration
#
# Drone secret requirements
# HEROKU_API_KEY - Your Heroku API key
# HEROKU_LOGIN - Your Heroku login, probably your email address
# HEROKU_GIT_URL - Your Heroku git url (e.g. - https://git.heroku.com/{your-app-name}.git)
#
# Add a drone secret with the Drone CLI
# drone secret add --image=<image> <org/repo> <secret> <value>
#!/bin/bash
set -e
echo "Installing Heroku Toolbelt..."
wget -q https://cli-assets.heroku.com/branches/stable/heroku-linux-386.tar.gz -O heroku.tar.gz
mkdir -p /usr/local/lib
tar -xzf heroku.tar.gz -C /usr/local/lib
rm heroku.tar.gz
/usr/local/lib/heroku/install
echo "Adding heroku as git remote"
git remote add heroku ${HEROKU_GIT_URL} || echo "Failed to add remote"
# This is how we authenticate with Heroku without having to run `heroku login`
echo "Writing .netrc file"
cat >~/.netrc <<EOF
machine api.heroku.com
login ${HEROKU_LOGIN}
password ${HEROKU_API_KEY}
machine git.heroku.com
login ${HEROKU_LOGIN}
password ${HEROKU_API_KEY}
EOF
echo "Deploying site to Heroku"
git push heroku master
git remote remove heroku
exit 0
@denzuko
Copy link

denzuko commented Sep 23, 2021

FYI: netrc files is a very bad practice that died in the 90's. Using a secure git credential helper is largely the path one would use:
https://git-scm.com/docs/gitcredentials

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment