app

Contains methods and events related to app actions.

Since: 3.0.0
Example

// Start an app
return lando.app.start(app);

// Stop an app
return lando.app.stop(app);

// Destroy an app
return lando.app.destroy(app);

// Get the app called myapp
return lando.app.get('myapp')
.then(function(app) {
  console.log(app);
});

// Get a list of all the apps
return lando.app.list()
.then(function(apps) {
  console.log(apps);
});

app.list([opts]) ⇒ Promise

Lists all the Lando apps from the app registry.

Kind: static method of app
Returns: Promise - Returns a Promise with an array of apps from the registry
Since: 3.0.0

Param Type Default Description
[opts] Object Options to determine how list is run
[opts.useCache] Boolean true Use the app cache

Example

// List all the apps
return lando.app.list()

// Pretty print each app to the console.
.map(function(app) {
  console.log(JSON.stringify(app, null, 2));
});

app.get([appName]) ⇒ Promise

Gets a fully instantiated app object.

If you do not pass in an appName Lando will attempt to find an app in your current working directory.

Lando will also scan parent directories if no app is found.

Kind: static method of app
Returns: Promise - Returns a Pronise with an instantiated app object or nothing.
Since: 3.0.0

Param Type Description
[appName] String The name of the app to get.

Example

// Get an app named myapp and start it
return lando.app.get('myapp')

// Start the app
.then(function(app) {
  lando.app.start(app);
});

app.isRunning(app, checkall) ⇒ Promise

Determines whether an app is running or not. By defualt it only requires that a single service for that be running to return true but see opts below.

You can pass in an entire app object here but it really just needs an object with the app name eg {name: 'myapp'}

Kind: static method of app
Returns: Promise - Returns a Promise with a boolean of whether the app is running or not.
Since: 3.0.0

Param Type Description
app Object An app object.
app.name String The name of the app
checkall Boolean Make sure ALL the apps containers are running

Example

// Let's check to see if the app has been started
return lando.app.isRunning(app)

// Start the app if its not running already
.then(function(isRunning) {
  if (!isRunning) {
    return lando.app.start(app);
  }
});

app.exists(appName) ⇒ Promise

Checks to see if the app exists or not.

Kind: static method of app
Returns: Promise - A promise with a boolean of whether the app exists or not.
Since: 3.0.0

Param Type Description
appName String The name of the app to get.

Example

// Get an app named myapp and start it
return lando.app.exists('myapp')

// Theorize if app exists
.then(function(exists) {
  if (exists) {
    console.log('I think, therefore I am.')
  }
});

app.info(app) ⇒ Promise

Prints useful information about the app's services.

This should return information about the services the app is running, URLs the app can be accessed at, relevant connection information like database credentials and any other information that is added by other plugins.

Kind: static method of app
Returns: Promise - A Promise with an object of information about the app keyed by its services
Emits: event:pre-info
Since: 3.0.0

Param Type Description
app Object A fully instantiated app object

Example

// Return the app info
return lando.app.info(app)

// And print out any services with urls
.each(function(service) {
  if (_.has(service, 'urls')) {
    console.log(service.urls);
  }
});

app.uninstall(app) ⇒ Promise

Soft removes the apps services but maintains persistent data like app volumes.

This differs from destroy in that destroy will hard remove all app services, volumes, networks, etc as well as remove the app from the appRegistry.

Kind: static method of app
Returns: Promise - A Promise.
Emits: event:pre-uninstall, event:post-uninstall
Since: 3.0.0

Param Type Description
app Object A fully instantiated app object

Example

// Uninstall the app
return lando.app.uninstall(app)

// Catch any errors
catch(function(err) {
  lando.log.error(err);
});

app.cleanup(app) ⇒ Promise

Does some helpful cleanup before running an app operation.

This command helps clean up apps in an inconsistent state and any orphaned containers they may have.

Kind: static method of app
Returns: Promise - A Promise.
Since: 3.0.0
Todo

  • [ ] Should this be an internal method? Or can we deprecate at some point?
Param Type Description
app Object A fully instantiated app object

Example

// Do the app cleanup
return lando.app.cleanup(app)

app.start(app) ⇒ Promise

Starts an app.

This will start up all services/containers that have been defined for this app.

Kind: static method of app
Returns: Promise - A Promise.
Emits: event:pre-start, event:post-start
Since: 3.0.0

Param Type Description
app Object A fully instantiated app object

Example

// Start the app
return lando.app.start(app)

// Catch any errors
catch(function(err) {
  lando.log.error(err);
});

app.stop(app) ⇒ Promise

Stops an app.

This will stop all services/containers that have been defined for this app.

Kind: static method of app
Returns: Promise - A Promise.
Emits: event:pre-stop, event:post-stop
Since: 3.0.0

Param Type Description
app Object A fully instantiated app object

Example

// Stop the app
return lando.app.stop(app)

// Catch any errors
catch(function(err) {
  lando.log.error(err);
});

app.restart(app) ⇒ Promise

Stops and then starts an app.

This just runs app.stop and app.start in succession.

Kind: static method of app
Returns: Promise - A Promise.
Emits: event:pre-stop, event:stop-stop, event:pre-start, event:post-start
Since: 3.0.0

Param Type Description
app Object A fully instantiated app object

Example

// Restart the app
return lando.app.restart(app)

// Catch any errors
catch(function(err) {
  lando.log.error(err);
});

app.destroy(app) ⇒ Promise

Hard removes all app services, olumes, networks, etc as well as removes the app from the appRegistry.

This differs from uninstall in that uninstall will only soft remove all app services, while maintaining things like volumes, networks, etc as well as an entry in the appRegistry.

That said this DOES call both stop and uninstall.

Kind: static method of app
Returns: Promise - A Promise.
Emits: event:pre-destroy, event:pre-stop, event:post-stop, event:pre-uninstall, event:post-uninstall, event:post-destroy
Since: 3.0.0

Param Type Description
app Object A fully instantiated app object

Example

// Destroy the app
return lando.app.destroy(app)

// Catch any errors
catch(function(err) {
  lando.log.error(err);
});

app.rebuild(app) ⇒ Promise

Rebuilds an app.

This will stop an app, soft remove its services, rebuild those services and then, finally, start the app back up again. This is useful for developers who might want to tweak Dockerfiles or compose yamls.

Kind: static method of app
Returns: Promise - A Promise.
Emits: event:pre-stop, event:post-stop, event:pre-uninstall, event:post-uninstall, event:pre-start, event:post-start
Since: 3.0.0

Param Type Description
app Object A fully instantiated app object

Example

// Destroy the app
return lando.app.destroy(app)

// Catch any errors
catch(function(err) {
  lando.log.error(err);
});

"event:pre-instantiate-app"

Event that allows altering of the config before it is used to instantiate an app object.

Note that this is a global event so it is invoked with lando.events.on not app.events.on See example below:

Kind: event emitted by app
Since: 3.0.0
Properties

Name Type Description
config Object The config from the app's .lando.yml

Example

// Add in some extra default config to our app, set it to run first
lando.events.on('pre-instantiate-app', 1, function(config) {

  // Add a process env object, this is to inject ENV into the process
  // running the app task so we cna use $ENVARS in our docker compose
  // files
  config.dialedToInfinity = true;

});

"event:post-instantiate-app"

Event that allows altering of the app object right after it is instantiated.

Note that this is a global event so it is invoked with lando.events.on not app.events.on See example below:

Kind: event emitted by app
Since: 3.0.0
Properties

Name Type Description
config object The user's app config.

Example

// Add some extra app properties to all apps
lando.events.on('post-instantiate-app', 1, function(app) {

  // Add in some global container envvars
  app.env.LANDO = 'ON';
  app.env.LANDO_HOST_OS = lando.config.os.platform;
  app.env.LANDO_HOST_UID = lando.config.engineId;
  app.env.LANDO_HOST_GID = lando.config.engineGid;

});

"event:app-ready"

Event that allows altering of the app object right after it has been full instantiated and all its plugins have been loaded.

The difference between this event and post-instantiate-app is that at this point the event has been handed off from the global lando.events.on context to the app.events.on context. This means that post-instantiate-app will run for ALL apps that need to be instantiated while app-ready will run on an app to app basis.

Kind: event emitted by app
Since: 3.0.0
Example

// Add logging to report on our apps properties after its full dialed
app.events.on('app-ready', function() {

  // Log
  lando.log.verbose('App %s has global env.', app.name, app.env);
  lando.log.verbose('App %s has global labels.', app.name, app.labels);
  lando.log.verbose('App %s adds process env.', app.name, app.processEnv);

});

"event:pre-info"

Event that allows other things to add useful metadata to the apps services.

Its helpful to use this event to add in information for the end user such as how to access their services, where their code exsts or relevant credential info.

Kind: event emitted by app
Since: 3.0.0
Example

// Add urls to the app
app.events.on('pre-info', function() {
  return getUrls(app);
});

"event:pre-uninstall"

Event that runs before an app is uninstalled.

This is useful if you want to add or remove parts of the uninstall process. For example, it might be nice to persist a container whose data you do not want to replace in a rebuild and that cannot persist easily with a volume.

Kind: event emitted by app
Since: 3.0.0
Example

// Do not uninstall the solr service
app.events.on('pre-uninstall', function() {
  delete app.services.solr;
});

"event:post-uninstall"

Event that runs after an app is uninstalled.

This is useful if you want to do some additional cleanup steps after an app is uninstalled such as invalidating any cached data.

Kind: event emitted by app
Since: 3.0.0
Example

// Make sure we remove our build cache
app.events.on('post-uninstall', function() {
  lando.cache.remove(app.name + ':last_build');
});

"event:pre-start"

Event that runs before an app starts up.

This is useful if you want to start up any support services before an app stars.

Kind: event emitted by app
Since: 3.0.0
Example

// Start up a DNS server before our app starts
app.events.on('pre-start', function() {
  return lando.engine.start(dnsServer);
});

"event:post-start"

Event that runs after an app is started.

This is useful if you want to perform additional operations after an app starts such as running additional build commands.

Kind: event emitted by app
Since: 3.0.0
Example

// Go through each service and run additional build commands as needed
app.events.on('post-start', function() {

  // Start up a build collector
  var build = [];

  // Go through each service
  _.forEach(app.config.services, function(service, name) {

    // If the service has extras let's loop through and run some commands
    if (!_.isEmpty(service.extras)) {

      // Normalize data for loopage
      if (!_.isArray(service.extras)) {
        service.extras = [service.extras];
      }

      // Run each command
      _.forEach(service.extras, function(cmd) {

        // Build out the compose object
        var compose = {
          id: [app.dockerName, name, '1'].join('_'),
            cmd: cmd,
            opts: {
            mode: 'attach'
          }
        };

        // Push to the build
        build.push(compose);

      });

    }

  });

  // Only proceed if build is non-empty
  if (!_.isEmpty(build)) {

   // Get the last build cache key
   var key = app.name + ':last_build';

   // Compute the build hash
   var newHash = lando.node.hasher(app.config.services);

   // If our new hash is different then lets build
   if (lando.cache.get(key) !== newHash) {

     // Set the new hash
     lando.cache.set(key, newHash, {persist:true});

     // Run all our post build steps serially
     return lando.engine.run(build);

   }
  }
});

"event:pre-stop"

Event that runs before an app stops.

Kind: event emitted by app
Since: 3.0.0
Example

// Stop a DNS server before our app stops.
app.events.on('pre-stop', function() {
  return lando.engine.stop(dnsServer);
});

"event:post-stop"

Event that runs after an app stop.

Kind: event emitted by app
Since: 3.0.0
Example

// Stop a DNS server after our app stops.
app.events.on('post-stop', function() {
  return lando.engine.stop(dnsServer);
});

"event:pre-destroy"

Event that runs before an app is destroyed.

Kind: event emitted by app
Since: 3.0.0
Example

// Make sure the proxy is down before we destroy
app.events.on('pre-destroy', function() {
  if (fs.existsSync(proxyFile)) {
    return lando.engine.stop(getProxy(proxyFile));
  }
});

"event:post-destroy"

Event that runs after an app is destroyed.

Kind: event emitted by app
Since: 3.0.0
Example

// Make sure the proxy is up brought back up after we destroy
app.events.on('post-destroy', function() {
  return startProxy();
});

"event:pre-rebuild"

Event that runs before an app is rebuilt.

Kind: event emitted by app
Since: 3.0.0
Example

// Do something
app.events.on('post-rebuild', function() {
  // Do something
});

"event:post-rebuild"

Event that runs after an app is rebuilt.

Kind: event emitted by app
Since: 3.0.0
Example

// Do something
app.events.on('post-rebuild', function() {
  // Do something
});

results matching ""

    No results matching ""