Using Templates

This tutorial demonstrates how to use runtime templates in an application manifest file.

You use a manifest file in place of some or all of the flags you would otherwise specify on the command line when you create or deploy an app. You can reference a template file in your manifest file to populate your app with runtime environment variables.


Complete the steps that follow.

1) Change to directory /sample-apps/example-ruby-manifest.

2) Open the continuum.conf file.

This is the manifest file for the app. As you can see, it specifies a number of configuration parameters for the Ruby app.

At the bottom you will see the following block:

templates: [
    path: "app.rb"

The block represents the set of template files to evaluate. The options available are:

  • path: The path to the template
  • left_delimiter: string to use for left delimiter (default is left brace)
  • right_delimiter: string to use for right delimiter (default is right brace)

3) Open the app.rb file and review its content.

The template file includes a number of parameters:

  get "/template" do
    "scalars:<br />
uuid: {{uuid}}<br />
name: {{name}}<br />
num_instances: {{num_instances}}<br />
cpu: {{cpu}}<br />
memory: {{memory}}<br />
disk: {{disk}}<br />
<br />
tags:<br />
{{range tags}}
  {{.Name}}: {{.Value}}<br />
<br />
routes:<br />
{{range routes}}
  URL: {{.URL}}<br />
{{if .Public}}
  Port: {{.ListenPort}}<br />
  UpdatePort: {{.ListenPort}}<br />
<br />
bindings:<br />
{{range bindings}}
  Name: {{.Name}}<br />
  Provider: {{.Provider}}<br />
  Service: {{.Service}}<br />
  URI: {{.URI}}<br />
    scheme={{.URI.Scheme}}<br />
    user={{.URI.User}}<br />
    password={{.URI.Password}}<br />
    host={{.URI.Host}}<br />
    port={{.URI.Port}}<br />
    path={{.URI.Path}}<br />
    raw_query={{.URI.RawQuery}}<br />

4) Update the manifest file.

The manifest for the example-ruby-manifest app sepcifies the “/dev/test” namespace. Update this value to be your default namespace.

5) Create the app.

apc app create

6) Create a clone of your app.

The command apc app console creates a cloned instance of your app and connects you to it via SSH. The clone is an exact copy of your app that runs in a capsule (container instance). The clone includes app service bindings, environment variables, etc. In addition, all packages are mounted, so you can explore the app filesystem.

apc app console example-ruby-manifest

Single-binary apps, such as Apcera-provided apps or some Docker images, may not be consoled to as they do not mount an operating system.

7) Once you are inside the container, change directory to /app.


cd /app

8) Open the app.rb file.

cat app.rb

Verify that the parameter values are replaced by the actual values. For example:

Creating a capsule for "job::/sandbox/lparis::example-ruby-manifest"... done
Starting the capsule... done
Waiting for the capsule to start...
Start Command: bundle exec rackup -p $PORT
root@ip-169-254-0-15:/# ls
app  bin  dev  etc  lib  lib64  logs  opt  proc  run  sbin  selinux  srv  sys  tmp  usr  var  volume
root@ip-169-254-0-15:/# cd app
root@ip-169-254-0-15:/app# ls
Gemfile      app.rb     continuum copy.conf-orig  services.conf  views
Gemfile.lock  _set_stdout_sync.rb  continuum.conf    vendor
root@ip-169-254-0-15:/app# cat app.rb
require "sinatra"
require "cgi"
require "erb"

class App < Sinatra::Base
  get "/" do
    erb :index

  get "/db" do
    erb :db

  get "/status/heartbeat" do

  get "/template" do
    "scalars:<br />
uuid: 83e3ea02-b5a1-4b57-9485-2da6183fb9f9<br />
name: job::/sandbox/lparis::example-ruby-manifest-console-1445701839<br />
num_instances: 1<br />
cpu: 0<br />
memory: 268435456<br />
disk: 805306368<br />
<br />
tags:<br />

  allow_running_updates: true<br />

  heavy: example-ruby-manifest-console-1445701839<br />

<br />
routes:<br />

<br />
bindings:<br />

9) Exit the SSH session and tear down the app console.

root@ip-169-254-0-15:/app# exit
Stopping the capsule... done
Deleting the capsule... done