Skip to content

Commit

Permalink
Merge pull request #186 from DjangoGirls/restore-git-push
Browse files Browse the repository at this point in the history
Restore git push
  • Loading branch information
olasitarska committed Nov 15, 2014
2 parents ddc7f53 + 539448d commit d11a843
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 42 deletions.
57 changes: 33 additions & 24 deletions deploy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ Then authenticate your Heroku account on your computer by running this command:

In case you don't have an SSH key this command will automatically create one. SSH keys are required to push code to the Heroku.

## Ignore some files
## Git

We don't want to send all of our project files to Heroku. Some of them, like `local_settings.py` or our database, need to stay only on our local computer. In order to tell Heroku which files should it ignore, we need to create a `.gitignore` file in our project main directory.
Heroku uses a git repository to manage your project files, so we need to use it too.

Create `.gitignore` file with the following content:

Expand All @@ -129,34 +129,41 @@ Create `.gitignore` file with the following content:
local_settings.py
db.sqlite3

and save it. The dot on the beginning of the file name is important!
and save it. The dot on the beginning of the file name is important! As you can see, we're now telling Heroku to ignore `local_settings.py` and don't download it, so it's only available on your computer (locally).

> __Note:__ Remember to replace `myvenv` with the name you gave your `virtualenv`!
__NOTE:__ Remember to replace `myvenv` with the name you gave your `virtualenv`!

Next, we’ll create a new git repository and save our changes. Go to your console and run these commands:

$ git init
Initialized empty Git repository in ~/djangogirls/.git/
$ git add .
$ git commit -m "My Django Girls app"
[master (root-commit) 2943412] My Django Girls
7 files changed, 230 insertions(+)
create mode 100644 .gitignore
create mode 100644 Procfile
create mode 100644 mysite/__init__.py
create mode 100644 mysite/settings.py
create mode 100644 mysite/urls.py
create mode 100644 mysite/wsgi.py
create mode 100644 manage.py
create mode 100644 requirements.txt
create mode 100644 runtime.txt

## Deploy to Heroku!

It was a lot of configuration and installing, right? But you only need to do that once! Now you can deploy:
It was a lot of configuration and installing, right? But you need to do that once! Now you can deploy!

It's as simple as running this command, replacing `djangogirlsblog` with your own application name:

$ heroku create djangogirlsblog

Because our application needs a database, let's create a free [PostgreSQL](http://www.postgresql.org) instance on Heroku. It's as simple as running this command:

$ heroku addons:add heroku-postgresql --app djangogirlsblog

> In addition to creating a database for us, this command will also configure our application with the information on how to connect to the database. This information will be read and used by `dj_database_url.config()` in our `mysite/settings.py file`.
One more thing: let's install [heroku-push plugin](https://github.com/ddollar/heroku-push) by running this command:

$ heroku plugins:install https://github.com/ddollar/heroku-push
> __Note__: Remember to replace `djangogirlsblog` with the name of your application on Heroku.
Now we can do a simple push to deploy our application:

$ git init
$ heroku push --app djangogirlsblog
This automatically added the Heroku remote for our app to our repository. Now we can do a simple git push to deploy our application:

> __Note__: Remember to replace `djangogirlsblog` with the name of your application on Heroku.
$ git push heroku master

## Visit your application

Expand All @@ -165,22 +172,24 @@ We can now tell Heroku to start this `web process`.

To do that, run the following command:

$ heroku ps:scale web=1 --app djangogirlsblog
$ heroku ps:scale web=1

This tells Heroku to run just one instance of our `web` process. Since our blog application is quite simple, we don't need too much power and so it's fine to run just one process. It's possible to ask Heroku to run more processes (by the way, Heroku calls these processes "Dynos" so don't be surprised if you see this term) but it will no longer be free.

We can now visit the app in our browser with `heroku open`.

$ heroku open --app djangogirlsblog
$ heroku open

This will open a url like [https://djangogirlsblog.herokuapp.com/]() in your browser. Since we only created the admin view for the app so far, add `admin/` to the url (e.g. [https://djangogirlsblog.herokuapp.com/admin/]()) to see a working page of our web app.

We created a new database on Heroku, but we also need to sync it:

$ heroku run python manage.py migrate --app djangogirlsblog
$ heroku run python manage.py migrate

One final step; since the newly created database is empty, we need to create a new user so we can access the admin:
As you can see, there is an error. Heroku created a new database for us and it's empty. We also need to sync it:

$ heroku run python manage.py createsuperuser --app djangogirlsblog
$ heroku run python manage.py createsuperuser

You should now be able to see your website in a browser! Congrats :)!


15 changes: 10 additions & 5 deletions django_forms/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,15 @@ If you need more information about Django forms you should read the documentatio

## One more thing: deploy time!

It'd be good to see if your website will be still working on Heroku, right? Let's try deploying again. Open up your console and type this:

heroku push --app djangogirlsblog

> __Note__: Remember to replace `djangogirlsblog` with the name of your application on Heroku.
It'd be good to see if your website will still be working on Heroku, right? Let's try deploying again. If you forgot how to do it, check the end of chapter 15:

$ git status
...
$ git add -A .
$ git status
...
$ git commit -m "Added views to create/edit blog post inside the site."
...
$ git push heroku master

And that should be it! Congrats :)
15 changes: 10 additions & 5 deletions django_templates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,16 @@ Have you noticed that we used a slightly different notation this time `{{ post.t

## One more thing

It'd be good to see if your website will still be working on Heroku, right? Let's try deploying again. Open up your console and type this:

heroku push --app djangogirlsblog

> __Note__: Remember to replace `djangogirlsblog` with the name of your application on Heroku.
It'd be good to see if your website will still be working on Heroku, right? Let's try deploying again. If you forgot how to do it, check the end of chapter 15:

$ git status
...
$ git add -A .
$ git status
...
$ git commit -m "Used Django templates instead of static HTML."
...
$ git push heroku master

Congrats! Now go ahead and try adding a new post in your Django admin (remember to add published_date!), then refresh your page to see if the post appears there.

Expand Down
15 changes: 10 additions & 5 deletions extend_your_application/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,15 @@ Yay! It works!

## One more thing: deploy time!

It'd be good to see if your website will be still working on Heroku, right? Let's try deploying again. Open up your console and type this:

heroku push --app djangogirlsblog

> __Note__: Remember to replace `djangogirlsblog` with the name of your application on Heroku.
It'd be good to see if your website will still be working on Heroku, right? Let's try deploying again. If you forgot how to do it, check the end of chapter 15:

$ git status
...
$ git add -A .
$ git status
...
$ git commit -m "Added more views to the website."
...
$ git push heroku master

And that should be it! Congrats :)
26 changes: 23 additions & 3 deletions html/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,30 @@ What we want really want to do is display real posts added in our Django admin -

## One more thing

It'd be good to see if your website will be still working on Heroku, right? Let's try deploying again. Open up your console and type this:
It'd be good to see if your website will be still working on Heroku, right? Let's try deploying again.

heroku push --app djangogirlsblog
First off, let's see what files have changed since we last deployed:

> __Note__: Remember to replace `djangogirlsblog` with the name of your application on Heroku.
$ git status

Let's tell `git` to include all the changes from the current directory:

$ git add -A .

> __Note__ `-A` (short for "all") means that `git` will also recognize if you've deleted files (by default, it only recognizes new/modified files). Also remember (from chapter 3) that `.` means the current directory.
Before we upload all the files, let's check what `git` will be uploading (all the files that `git` will upload should now appear in green):

$ git status

We're almost there, now it's time to tell it to save this change in its history. We're going to give it a "commit message" where we describe what we've changed. You can type anything you'd like at this stage, but it's helpful to type something descriptive so that you can remember what you've done in the future.

$ git commit -m "Changed the HTML for the site."

> __Note__ Make sure you use double quotes around the commit message.
Once we've done that, we can finally upload (push) our changes to the website on heroku:

git push heroku master

And that should be it! Once Heroku is finished, you can go ahead and refresh your website in the browser. Changes should be visible!

0 comments on commit d11a843

Please sign in to comment.