Example - testing a change to core/scaffolding-node
If I want to test a change to the node scaffolding, I would do this:
(build a new version of the core/scaffolding-node package) $ git clone https://github.com/habitat-sh/sample-node-app $ cd sample-node-app $ cp path/to/new/core/scaffolding-node.hart .
Open up the habitat/plan.sh file. Change this line
Write and close the file.
$ hab studio enter (studio) $ hab install <new-core-scaffolding-node.hart> (studio) $ build (studio) $ hab pkg export docker ./results/<newly-build-hart.hart> (studio) $ exit
Now that you are out of the studio, start a docker container with the new build of the sample-node-app (which using the new build of scaffolding-node).
$ docker run -it -p 8000:8000 your_origin/sample-node-app
Example: testing a change to core/scaffolding-ruby
(build a new version of the core/scaffolding-ruby package)
Create an ultra-simple Rails application
$ rails new widget_world --database=postgresql $ cd widget_world $ cp path/to/new/core/scaffolding-ruby.hart . $ vim Gemfile
Navigate to this line in the Gemfile
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
And change it to this line:
Save and close the file, then regenerate the Gemfile.lock file (otherwise bundle install will fail with an error), and create a scaffold for a Widget table.
$ rm Gemfile.lock $ bundle install $ rails generate scaffold Widget name:string
Now let’s Habitize this application!
$ hab plan init -s ruby $ vim habitat/plan.sh
Add this line to habitat/plan.sh
pkg_binds_optional=( [database]="port" )
There’s one more thing we need to do to use the new build of scaffolding-ruby.
Change this line:
Save and close habitat/plan.sh
Now, we need to generate a secret key for the rails application. Luckily for us, Rails makes this super easy. Run:
$ rails secret
Now, we need to provide that value to our package. Open up the habitat/default.toml file:
$ vim habitat/default.toml
And add in this content:
secret_key_base = "secret_key_you_just_generated" rails_env = 'production' [db] user = "admin" password = "admin"
Next, let’s enter the Habitat studio, install the new scaffolding-ruby package, and then build this application’s package:
$ hab studio enter (studio) $ build (studio) $ hab pkg export docker ./results/<your-new hart-package.hart> (studio) $ hab pkg export docker core/postgresql (studio) $ exit
Because we need to use two containers that need to take to eachother, create a docker-compose.yml file and include this content:
version: '3' services: db: image: core/postgresql volumes: - "./habitat/default.toml:/default.toml" railsapp: image: your_origin/widget_world ports: - 8000:8000 links: - db command: --peer db --bind database:postgresql.default
Save and close that file, now let’s bring up those containers!
$ docker-compose up
Currently, the ruby scaffolding does not automatically set up the database for you, this still needs to be done manually.
$ docker-compose exec railsapp hab pkg exec your-origin/widget_world widget_world-rake db:setup
And now we have a running Rails app and database running in Docker containers! Head on over to https://localhost:8000/widgets to check it out! If this is working properly, chances are the new core-ruby package works as well!