Reviewing Core Plans example - scaffoldings

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
$ cd sample-node-app
$ cp path/to/new/core/scaffolding-node.hart .

Open up the habitat/ file. Change this line




Write and close the file.

Now run:

$ 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:

gem 'tzinfo-data'

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/

Add this line to habitat/

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/

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'
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 talke to each other, we’ll use docker-compose. Create a docker-compose.yml file and include this content:

version: '3'
      - HAB_LICENSE=accept-no-persist
    image: core/postgresql
      - "./habitat/default.toml:/default.toml"
      - HAB_LICENSE=accept-no-persist
    image: your_origin/widget_world
      - 8000:8000
    - 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

to create the database

docker-compose exec railsapp hab pkg exec your-origin/widget_world widget_world-rake db:migrate

to setup the database schema

And now we have a running Rails app and database running in Docker containers! Head on over to http://localhost:8000/widgets to check it out! If this is working properly, chances are the new core-ruby package works as well!

Hi there

I noticed today working through this example that the build fails with a rake aborted! due to missing ‘secret_key_base’ for ‘production’ environment (rails/5.2.3 ruby/2.6.3)

widget_world: Detected and running Rake ‘assets:precompile’
rake aborted!
ArgumentError: Missing secret_key_base for ‘production’ environment, set this string with rails credentials:edit

Should these be read from the default.toml and set as environment var’s or should the instructions be updated to create a secrets yml file? not sure what’s best?