- Install plugin -
heroku plugins:install heroku-docker
- Clone this repository -
git clone https://gist.github.com/6aca9b2668b8b5af0208.git
- Init -
heroku docker:init
- Build containers -
docker-compose build
- Run containers -
docker-compose run web
- Test at localhost -
curl "http://$(docker-machine ip dev):8080"
- Create heroku app -
heroku create
- Create heroku slug and upload to heroku -
heroku docker:release
- Open app at heroku -
heroku open
Last active
October 4, 2015 18:07
-
-
Save abtris/6aca9b2668b8b5af0208 to your computer and use it in GitHub Desktop.
Example Simple NodeJS Application for Docker demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"image": "heroku/nodejs" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Hapi = require('hapi'); | |
var server = new Hapi.Server(); | |
var port = process.env.PORT || 3001; | |
server.connection({port: port}); | |
// Polls API Root | |
// Retrieve the Entry Point | |
server.route({ | |
method: 'GET', | |
path:'/', | |
handler: function(request, reply) { | |
reply({"questions_url": "/questions"}); | |
} | |
} | |
); | |
// Group Question | |
// Question | |
// View a Questions Detail | |
server.route({ | |
method: 'GET', | |
path: '/questions/{question_id}', | |
handler: function(request, reply) { | |
reply({"question":"Favourite programming language?", "published_at":"2014-11-11T08:40:51.620Z", "url":"/questions/1", "choices":[{"choice":"Swift", "url":"/questions/1/choices/1", "votes":2048}, {"choice":"Python", "url":"/questions/1/choices/2", "votes":1024}, {"choice":"Objective-C", "url":"/questions/1/choices/3", "votes":512}, {"choice":"Ruby", "url":"/questions/1/choices/4", "votes":256}]}); | |
} | |
}); | |
// Choice | |
// Vote on a Choice | |
server.route({ | |
method: 'POST', | |
path: '/questions/{question_id}/choices/{choice_id}', | |
handler: function(request, reply) { | |
reply().code(201).header('Location', '/questions/' + request.params.question_id); | |
} | |
}); | |
// Questions Collection | |
// List All Questions | |
server.route({ | |
method: 'GET', | |
path: '/questions', | |
handler: function(request, reply) { | |
reply([{"question":"Favourite programming language?", "published_at":"2014-11-11T08:40:51.620Z", "url":"/questions/1", "choices":[{"choice":"Swift", "url":"/questions/1/choices/1", "votes":2048}, {"choice":"Python", "url":"/questions/1/choices/2", "votes":1024}, {"choice":"Objective-C", "url":"/questions/1/choices/3", "votes":512}, {"choice":"Ruby", "url":"/questions/1/choices/4", "votes":256}]}]) | |
.header('Link', '</questions?page=' + (parseInt(request.params.page, 10) + 1) + '>; rel="next"'); | |
} | |
}); | |
// Create a New Question | |
server.route({ | |
method: 'POST', | |
path: '/questions', | |
handler: function(request, reply) { | |
reply({"question":"Favourite programming language?", "published_at":"2014-11-11T08:40:51.620Z", "url":"/questions/2", "choices":[{"choice":"Swift", "url":"/questions/2/choices/1", "votes":0}, {"choice":"Python", "url":"/questions/2/choices/2", "votes":0}, {"choice":"Objective-C", "url":"/questions/2/choices/3", "votes":0}, {"choice":"Ruby", "url":"/questions/2/choices/4", "votes":0}]}) | |
.code(201) | |
.header('Location', '/questions/2'); | |
} | |
}); | |
// Start the server | |
server.start(function() { | |
console.log('Server running at:', server.info.uri); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "hapi", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"dependencies": { | |
"hapi": "^8.4.0" | |
}, | |
"devDependencies": {}, | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "MIT" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
web: node index.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment