TIBET Logo

TIBET Deployment

Deployment

wins

  • Manifest-driven application packaging requires no additional tooling.
  • Built-in command line deployments via tibet build and tibet deploy.
  • Pre-configured support for running shipit-based deployments.
  • Fully extensible via tibet deploy command plugins or tibet make.
  • Integrated test, build, deploy support directly from TIBET Sherpa™.

contents

concepts

cookbook

code


concepts

Building

TIBET projects support building (packaging and minification) out of the box using TIBET-specific tooling optimized for creating deployable TIBET applications that conform to your requirements.

Unlike systems which rely on source code analysis TIBET leverages the same application package files it uses to define your application for loading, testing, and other tasks. By using a common package description format TIBET lets you define exactly how you want your application be configured in a single, consistent fashion regardless of the task at hand.

When you launch a TIBET application the TIBET Loader will automatically attempt to load a "built" project configuration. In other words, launching via a URL such as http://127.0.0.1:1407 will try to find and load a built package. When you first create a new project this package won't exist until the first time you execute tibet build for that project.

Once you've built your project at least once TIBET will load the last built package for your project unless you provide it with boot parameters to target a more dynamic development configuration. This is, in fact, why development with TIBET usually happens from a URL of the form: http://127.0.0.1:1407#?boot.profile=development.

Below is the output of tibet build after working through the TIBET Quickstart and TIBET Essentials guides:

$ tibet build
Delegating to 'tibet make build'
building app...
removing build artifacts...
processing resources...
generating resources
executing /Users/ss/dev/TPI/TIBET/bin/tibet resource --build --package '~app_cfg/main.xml' --config base --no-silent
Loading TIBET at 2019-06-23T01:51:49.440Z
TIBET loaded and active in 7116ms
Filtering 8 computed and 8 specified resources...
Building 15 concrete resources...
~app_tags/APP.hello.app/APP.hello.app.xhtml
~app_tags/APP.hello.app/APP.hello.app.css
~app_tags/APP.hello.world/APP.hello.world.xhtml
~app_tags/APP.hello.world/APP.hello.world.css
~app_tags/APP.hello.now/APP.hello.now.css
~app_tags/APP.hello.data/APP.hello.data.xhtml
~app_tags/APP.hello.data/APP.hello.data.css
~app_styles/app.css
~app_tags/APP.hello.app/APP.hello.app.xhtml
~app_tags/APP.hello.app/APP.hello.app.css
~app_tags/APP.hello.world/APP.hello.world.xhtml
~app_tags/APP.hello.world/APP.hello.world.css
~app_tags/APP.hello.now/APP.hello.now.css
~app_tags/APP.hello.data/APP.hello.data.xhtml
~app_tags/APP.hello.data/APP.hello.data.css
Writing package resource entries...
<script src="~app_build/app_tags-APP.hello.app-APP.hello.app.xhtml.js"/> (added)
<script src="~app_build/app_tags-APP.hello.app-APP.hello.app.css.js"/> (added)
<script src="~app_build/app_tags-APP.hello.world-APP.hello.world.xhtml.js"/> (added)
<script src="~app_build/app_tags-APP.hello.world-APP.hello.world.css.js"/> (added)
<script src="~app_build/app_tags-APP.hello.now-APP.hello.now.css.js"/> (added)
<script src="~app_build/app_tags-APP.hello.data-APP.hello.data.xhtml.js"/> (added)
<script src="~app_build/app_tags-APP.hello.data-APP.hello.data.css.js"/> (added)
<script src="~app_build/app_styles-app.css.js"/> (added)
New configuration entries created. Review/Rebuild as needed.
rolling up assets...
rolling up app_base
executing /Users/ss/dev/TPI/TIBET/bin/tibet rollup --package '~app_cfg/main.xml' --config base --phase two --no-silent
writing 11067 chars to: /Users/ss/temporary/hello/public/build/app_base.js
creating zipped output in /Users/ss/temporary/hello/public/build/app_base.js.gz
gzip compressed to: 2313 bytes
rolling up app_base
executing /Users/ss/dev/TPI/TIBET/bin/tibet rollup --package '~app_cfg/main.xml' --config base --phase two --no-silent --minify
writing 7734 chars to: /Users/ss/temporary/hello/public/build/app_base.min.js
creating zipped output in /Users/ss/temporary/hello/public/build/app_base.min.js.gz
gzip compressed to: 1598 bytes
linking build targets...
skipping link for missing file '~lib_build/tibet_base.min.js.br'
skipping link for missing file '~app_build/app_base.min.js.br'
build assets linked successfully.
Task complete: 10815ms.

As you can see, tibet build invokes the TIBET Loader to load your application in a headless context, reflect on it for resource utilization information, and then use that information to not only bundle your source code but also any styles, images, and other resources it can detect.

Experimental features of this load/reflect process include running your tests while maintaining a list of all functions invoked, allowing future `tibet build` procesing to optionally strip your application package to the minimum size possible...only the code you actually invoke.

The output of the build process is a set of files specific to your application code. This is the "app" portion of TIBET's "app vs. lib" separation. There's nothing special to do to get TIBET to factor out lib from application code.

Building A Non-Default Target

Sometimes you need to build a package@config combination that's not the default (main@base). In that case you can use --profile= to provide both or you can use --package and/or --config to define what you need.

In the example below we tell tibet build we want to use the baseui target so we can pull the xctrls namespace files into our built package:

$ tibet build --config=baseui
Delegating to 'tibet make build'
building app...
removing build artifacts...
building project documentation...
processing resources...
generating resources
executing /Users/ss/dev/TPI/TIBET/bin/tibet resource --build --package '~app_cfg/main.xml' --config baseui --no-silent
# Loading TIBET platform at 2019-07-22T19:08:01.977Z
# TIBET reflection suite loaded and active in 6508ms
Filtering 2 computed and 5 specified resources...
Building 7 concrete resources...
~app_tags/APP.hello.app/APP.hello.app.xhtml
~app_tags/APP.hello.app/APP.hello.app.css
~app_styles/app.css
~app_dat/keyrings.xml
~app_dat/vcards.xml
~app_tags/APP.hello.app/APP.hello.app.xhtml
~app_tags/APP.hello.app/APP.hello.app.css
Writing package resource entries...
rolling up assets...
rolling up app_baseui
executing /Users/ss/dev/TPI/TIBET/bin/tibet rollup --package '~app_cfg/main.xml' --config baseui --phase two --no-silent
writing 6429 chars to: /Users/ss/temporary/hello/public/build/app_baseui.js
creating zipped output in /Users/ss/temporary/hello/public/build/app_baseui.js.gz
gzip compressed to: 1792 bytes
rolling up app_baseui
executing /Users/ss/dev/TPI/TIBET/bin/tibet rollup --package '~app_cfg/main.xml' --config baseui --phase two --no-silent --minify
writing 4708 chars to: /Users/ss/temporary/hello/public/build/app_baseui.min.js
creating zipped output in /Users/ss/temporary/hello/public/build/app_baseui.min.js.gz
gzip compressed to: 1307 bytes
linking build targets...
skipping link for missing file '~lib_build/tibet_baseui.min.js.br'
skipping link for missing file '~app_build/app_baseui.min.js.br'
build assets linked successfully.
Task complete: 9316ms.

Deploying

In TIBET the process of deployment is triggered by invoking the tibet deploy command from either the CLI or the TIBET Sherpa.

TIBET's deployment process does not do a build first, it simply invokes whatever deployment helper you target. TIBET supports shipit out of the box. Other deployment helpers for aws, azure, and other targets are under development.

To trigger deployment from the command line use something like:

# tibet deploy {helper} [options]
tibet deploy shipit development

In the prior command line we're asking tibet deploy to leverage the shipit deployment helper and to provide it with the development environment target. The result in that specific case is invocation of the following command line to activate shipit (provided it's installed):

shipit deploy development

You can also leverage tibet make by invoking tibet deploy make assuming you've updated your project's _deploy.js make target. See the discussion on deploying via tibet make for more information.

For specific deployment commands see the cookbook entries which follow.


cookbook

Installing Shipit For Your Project

TIBET projects don't include shipit functionality by default. You can fix this quickly by adding shipit-cli and shipit-deploy to your project via npm.

$ npm install --save-dev shipit-cli
...

$ npm install --save-dev shipit-deploy
...

Once you have installed the shipit-cli and shipit-deploy modules you need to add a shipitfile.js file to your project.

Here's a sample shipitfile.js for "deploying" to local machine's /tmp directory:

module.exports = function(shipit) {
    require('shipit-deploy')(shipit);

    shipit.initConfig({
        default: {
            workspace: '/tmp/tibet',
            deployTo: '/tmp/deployed-tibet',
            repositoryUrl: 'https://github.com/TechnicalPursuit/TIBET.git',
            ignores: ['.git', 'node_modules'],
            rsync: ['--del'],
            keepReleases: 3,
            key: '~/.ssh/id_rsa',
            shallowClone: true
        }
        development: {
            servers: 'ss@localhost'
        }
    });
};

You'll want to review the shipit documentation for details on how to configure your specific environments and targets for shipit.

Deploying via shipit

TIBET includes built-in support for invoking targets in a project's shipitfile.js file provided such a file exists (and you have installed shipit for your project.

All you need to do is invoke tibet deploy and provide it with shipit as the deployment helper along with any parameters you want to pass to shipit itself.

If you've configured the sample file we provided in the previous "installing shipit" cookbook entry you can try the following:

$ tibet deploy shipit development

As you create specific targets (environments) for shipit you can deploy to them quickly and easily from the tibet command line.

Deploying via tibet make

TIBET's tibet make command will invoke any exported function you create and place in the ~app_cmd/make directory. As part of its default configuration all TIBET projects include a _deploy.js file in this directory you can use as a starting point for writing you own custom deployment logic.

Sample _deploy.js from a default TIBET project:

(function() {
    'use strict';

    module.exports = function(make, resolve, reject) {

        make.log('deploying application...');

        //  ---

        //  TODO:   replace this with your concrete deployment logic.
        make.warn('No concrete deployment logic.');

        //  ---

        resolve();
    };

}());

Obviously the previous file doesn't actually deploy, but you can invoke it via tibet make deploy or tibet deploy make (either will work). Adjust the logic to suit your needs and you can leverage tibet make to help you with your deployments.

Extending tibet deploy

The tibet deploy command supports extension by creating custom "plugins" and placing them in the ~app_cmd directory (typically the cmd directory at the root of your TIBET project) in a deploy subdirectory.

The files in question should be named to match your subcommand name. For our example here we use this as our hypothetical deploy helper so we would create a file this.js in our project's cmd/deploy directory.

Plugins for tibet deploy must be loadable via require and return a function which, when invoked, will patch the deploy command prototype with the desired implementation. The method should be named executeSomething where 'Something' is replaced with the target name.

/**
 * A sample 'tibet deploy' command. This one is built to handle invocations of
 * the TIBET CLI with a command line of 'tibet deploy this'.
 */

(function() {
    'use strict';

    module.exports = function(cmdType) {

        //  NOTE: we patch the prototype since invocation is instance-level.
        cmdType.prototype.executeThis = function() {
            console.log('deploying this...');
        };
    };

}(this));

Additional pre-built logic for common deployment targets is under development.


code

TIBET's build and deployment infrastructure is based on a combination of TIBET CLI commands and tibet make targets.

Code for tibet make targets is found in ~app/cmd/make. In particular, the build make target which invokes clean, build_resources, _rollup, and _linkup as part of its processing.

Code for the CLI is contained in ~lib/src/tibet/cli. The package, resource, and rollup commands do most of the work. Logic in ~lib/etc/common/tibet_package.js is used by a number of these commands to assist them in processing TIBET's manifest files.