My personal portfolio and experiment playground
Checkout the code repo to your local development folder
$ git clone [email protected]:davidmoss/davidcmoss.git
To work locally you will want to ensure we work in an isolated environment where we control the packages and versions installed. Using a virtual environment will ensure this, there's also a helpful set of shortcuts to manage them aswell. Lets install them:
$ pip install virtualenv
$ pip install virtualenvwrapper
Now you will want to set it all up in your user profile ~/.profile
or ~/.bash_profile
based on your OS.
$ vim ~/.bash_profile
export WORKON_HOME=~/envs
source /usr/local/bin/virtualenvwrapper.sh
$ source ~/.bash_profile
$ mkdir -p $WORKON_HOME
There are also a set of useful Heroku tools to interact and deploy update. Install the toolbelt.
$ wget -qO- https://toolbelt.heroku.com/install.sh | sh
First create everything to run our application. First lets create the virtualenv.
$ mkvirtualenv davidcmoss
Now install the requirements for the application.
(davidcmoss)$ cd davidcmoss
(davidcmoss)$ pip install -r requirements.txt
Locally to compile and generate the CSS files you need to install and setup Grunt
You will need to install node
for this - please follow the instructions here http://nodejs.org/download/
From inside the code repo then install all the dependencies with the node package manager npm
(davidcmoss)$ npm install
+ [email protected]
+ [email protected]
+ [email protected]
This will also run the less compilation in the postinstall step to get you up and running.
To run the css build manually you can do
(davidcmoss)$ npm run postinstall
> [email protected] postinstall /Users/davidmoss/Code/davidcmoss
> ./node_modules/grunt-cli/bin/grunt
Running "less:production" (less) task
>> 1 stylesheet created.
Done.
audited 280 packages in 2.033s
found 0 vulnerabilities
You can now start the processes in your Procfile locally using
Alternatively you can use the standard django runserver
command:
(davidcmoss)$ ./manage.py runserver
Validating models...
0 errors found
May 31, 2014 - 09:12:37
Django version 1.6.4, using settings 'davidcmoss.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Now you can access the application at http://127.0.0.1:8000
Heroku were the first major player in the PaaS world with quick and ease of deployment on the cloud. They are a perfect platform to use to run small, light apps.
Ensure you have a Heroku user account. Signup is free and instant.
Once signed up login to heroku locally
$ heroku login
Enter your Heroku credentials.
Email: [email protected]
Password:
Could not find an existing public key.
Would you like to generate one? [Yn]
Generating new SSH public key.
Uploading ssh public key /Users/kenneth/.ssh/id_rsa.pub
Create a place to push to from Heroku
$ heroku create
Creating stark-window-524... done, stack is cedar
http://stark-window-524.herokuapp.com/ | [email protected]:stark-window-524.git
Git remote heroku added
This automatically added the Heroku remote for our app ([email protected]:stark-window-524.git
) to our repository.
As the application uses Grunt to build and compress the CSS files on deployment we need to define the buildpacks that heroku should use to build and deploy the application. We have to override the automatic detection Heroku uses to define what application you are deploying so we run the node build and python deployment.
$ heroku buildpacks:set heroku/python
$ heroku buildpacks:add --index 1 heroku/nodejs
$ heroku config:set NODE_ENV=production
Now do a simple git push
to deploy the application
$ git push -f heroku master
Fetching repository, done.
Counting objects: 9, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (6/6), 772 bytes | 0 bytes/s, done.
Total 6 (delta 3), reused 0 (delta 0)
-----> Fetching custom git buildpack... done
-----> Multipack app detected
=====> Downloading Buildpack: https://github.com/mbuchetics/heroku-buildpack-nodejs-grunt.git
=====> Detected Framework: Node.js
PRO TIP: Specify a node version in package.json
See https://devcenter.heroku.com/articles/nodejs-support
-----> Defaulting to latest stable node: 0.10.28
-----> Downloading and installing node
-----> Restoring node_modules directory from cache
-----> Pruning cached dependencies not specified in package.json
npm WARN package.json [email protected] No repository field.
-----> Writing a custom .npmrc to circumvent npm bugs
-----> Exporting config vars to environment
-----> Installing dependencies
npm WARN package.json [email protected] No repository field.
> [email protected] postinstall /tmp/build_34a3e3a3-371b-4a4c-9428-8ed522122e96
> ./node_modules/grunt-cli/bin/grunt
Running "less:production" (less) task
File ./davidcmoss/static/css/main.css created: 1.31 kB → 1.04 kB
Done, without errors.
-----> Caching node_modules directory for future builds
-----> Cleaning up node-gyp and npm artifacts
-----> Building runtime environment
-----> Exporting config vars to environment
npm WARN package.json [email protected] No repository field.
npm http GET https://registry.npmjs.org/grunt-cli
...
[email protected] node_modules/grunt-cli
├── [email protected]
├── [email protected] ([email protected])
└── [email protected] ([email protected], [email protected])
npm WARN package.json [email protected] No repository field.
npm http GET https://registry.npmjs.org/grunt
...
[email protected] node_modules/grunt
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
├── [email protected]
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected], [email protected])
└── [email protected] ([email protected], [email protected])
-----> Found Gruntfile, running grunt heroku:production task
Running "less:production" (less) task
File ./davidcmoss/static/css/main.css created: 1.31 kB → 1.04 kB
Done, without errors.
=====> Downloading Buildpack: https://github.com/heroku/heroku-buildpack-python.git
=====> Detected Framework: Python
-----> No runtime.txt provided; assuming python-2.7.6.
-----> Using Python runtime (python-2.7.6)
-----> Installing dependencies using Pip (1.5.6)
Cleaning up...
-----> Preparing static assets
Collectstatic configuration error. To debug, run:
$ heroku run python ./manage.py collectstatic --noinput
Using release configuration from last framework (Python).
-----> Discovering process types
Procfile declares types -> web
-----> Compressing... done, 48.0MB
-----> Launching... done, v16
-----> Deploy hooks scheduled, check output in your logs
http://quiet-falls-4610.herokuapp.com/ deployed to Heroku
To [email protected]:quiet-falls-4610.git
+ [new branch] master -> master
By default there are no web dynamos enabled, but you can easily scale this by executing:
$ heroku ps:scale web=1
and to confirm or check:
$ heroku ps
=== web: `gunicorn hellodjango.wsgi`
web.1: up for 10s
Note: Increasing the number above 1 will encure a cost
You can navigate and view the application in your browser of using the quick command:
$ heroku open
Opening simple-spring-9999.herokuapp.com... done
You can use the heroku command line tools to access and alter your deployment but a couple of useful and familiar comands are:
$ heroku logs
2012-04-06T19:38:25+00:00 heroku[web.1]: State changed from created to starting
2012-04-06T19:38:29+00:00 heroku[web.1]: Starting process with command `gunicorn hellodjango.wsgi`
2012-04-06T19:38:29+00:00 app[web.1]: Validating models...
2012-04-06T19:38:29+00:00 app[web.1]:
2012-04-06T19:38:29+00:00 app[web.1]: 0 errors found
2012-04-06T19:38:29+00:00 app[web.1]: Django version 1.5, using settings 'hellodjango.settings'
2012-04-06T19:38:29+00:00 app[web.1]: Development server is running at http://0.0.0.0:6566/
2012-04-06T19:38:29+00:00 app[web.1]: Quit the server with CONTROL-C.
2012-04-06T19:38:30+00:00 heroku[web.1]: State changed from starting to up
2012-04-06T19:38:32+00:00 heroku[slugc]: Slug compilation finished
$ heroku run python manage.py shell
Running python manage.py shell attached to terminal... up, run.1
Python 3.6.6 (default, Jan 16 2018, 02:39:37)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>>
- Virtualenvwrapper - http://virtualenvwrapper.readthedocs.org/en/latest/
- Grunt runner - https://github.com/mbuchetics/heroku-buildpack-nodejs-grunt
- Multi buildpack - https://github.com/ddollar/heroku-buildpack-multi
- Getting started with django - https://devcenter.heroku.com/articles/getting-started-with-django
- Getting started with python & Heroku - https://devcenter.heroku.com/articles/getting-started-with-python
- Markdown Cheatsheet - https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet