shannonfromomaha / 02-29-pair-project

0 stars 0 forks source link

Deploy! #15

Closed sumeetjain closed 8 years ago

sumeetjain commented 8 years ago

Once you're at a reasonable break-point with your work so far. I'd like this done by 5pm at the latest.


Deploying means publishing. You've been hosting locally up until now. Deploying means publishing your code somewhere that is not local, so that the world can access it.

What's not local can be considered remote. So GitHub, for example, is a remote storage of your repo. To push to a remote using Git, you type git push [name of remote] [name of branch–like git push origin master (Because GitHub is called "origin", and you're pushing your master branch). Or git push origin 4-my-new-feature, if you're pushing some feature branch.

To deploy your code, you'll be pushing to a new remote, called Heroku. Like GitHub, Heroku is a remote storage of your repo, but it also publishes that code by running rackup for you and allocating a URL like http://elegant-bobcat-23483.herokuapp.com for your project alone. Since it does that, it doesn't do other things, like allow for conversations or otherwise facilitate collaboration.


Set Up Heroku

Create the Heroku Remote

One person should do the following:

The output will be something like:

Creating app... done, stack is cedar-14
https://sleepy-ocean-52379.herokuapp.com/ | https://git.heroku.com/sleepy-ocean-52379.git

The first URL there is your project's dedicated URL! The second one (ending in .git is the location of the Heroku remote repo storage).

Setting Up the Heroku "Remote"

Running heroku create automatically added that repo storage to your computer as a "remote". So now, just like you can do git push origin master to push to GitHub, you can also do git push heroku master to push to Heroku. GitHub and Heroku are not connected in any way–you have to push to each manually.

Your computer has the Heroku remote, but your partner's does not. Your partner doesn't need to create a new Heroku app, though. They just need to add a connection to the Heroku remote:

Now your partner will be able to git push heroku master from their computer also.

Permissions

You need to give your partner, Alex, and Sumeet permission to access the Heroku remote. Otherwise, even though we can add the remote to our computers, we'll get rejected if we try to push to it.

The person who created the remote in the first place should do the following:

Now everyone can deploy, if needed.

Database

When you deploy, your code is pushed but not your database. That's a good thing–it means you can add silly information for testing your project that no one else will see. But we do need to create a fresh database on Heroku for our deployed application to use.

One person in the pair should do this in iTerm, from the project folder:

The output should be something like this:

Creating postgresql-opaque-94052... done, (free)
Adding postgresql-opaque-94052 to sleepy-ocean-52379... done
Setting DATABASE_URL and restarting sleepy-ocean-52379... done, v3
Database has been created and is available
 ! This database is empty. If upgrading, you can transfer
 ! data from another database with pg:copy
Use `heroku addons:docs heroku-postgresql` to view documentation.

Now everyone can deploy, and the Heroku remote has a database for the application to use.

Before you deploy, there are some things to do.


You will only ever deploy the 'master' branch.

Let's deploy your 'master' branch, as it is currently–it's okay if there's not much/anything on it yet. You can continue working on your feature branch after you've deployed 'master'. (Then when it's ready, you can merge it into 'master' and re-deploy!)

One person should do the following:

Now you have to fix a bug that Sumeet accidentally introduced in the project's starter code. :sob:

You can make this change directly on the 'master' branch–it's okay this one time.

Open the file in your project called Gemfile and make this change:


Now you're ready to deploy.

Whoever fixed Sumeet's bug should do this from the 'master' branch:

Watch as Heroku detects the Ruby app in your code, does its own bin/setup stuff, and eventually says "Launched".

Go to the URL of your website to see it in action! (It's okay if you haven't built much functionality yet, but whatever you have built should work.)

Future Deploys

When deploying in the future, just make sure you're on the 'master' branch and git push heroku master.

You'll never deploy anything but the 'master' branch, and you'll never git pull from Heroku. You'll only ever push 'master'.