From b989c1f3cf3a7a1294d86f73c70c59e5c887f00a Mon Sep 17 00:00:00 2001 From: Baptiste Mispelon Date: Sat, 15 Nov 2014 23:35:44 +0100 Subject: [PATCH] Revert "Fixed #41 -- Deploying to Heroku without git" This reverts commit 0d2bfa15d499e959a0bf93ffaa51af9422787a3a. Conflicts: deploy/README.md --- deploy/README.md | 49 ++++++++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/deploy/README.md b/deploy/README.md index 87af74707e9..8e0f4e358e9 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -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: @@ -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 @@ -179,8 +186,10 @@ We created a new database on Heroku, but we also need to sync it: $ heroku run python manage.py migrate --app djangogirlsblog -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 You should now be able to see your website in a browser! Congrats :)! + +