HUB
Sign inSign up
skopos-discover logo

opsani/skopos-discover

By opsani

•Updated about 9 years ago

Containerized utility which scans docker/swarm and produces Skopos model/env files for running apps.

Image
1

4.0K

opsani/skopos-discover repository overview

⁠skopos-discover

Copyright (c) 2016-2017 Opsani All Rights Reserved. Skopos(tm) is a trademark of Opsani

⁠What is skopos-discover?

skopos-discover is a utility which examines either a docker host or a docker swarm cluster and produces one or more skopos model and environment file pairs which represent the discovered application(s) running on the examined environment. skopos-discover is intended to provide a starting point for creating a skopos model and environment file which represent an application created without using skopos, and which is already running under docker or docker-swarm.

skopos-discover is packaged as a docker container, and it's transient execution is performed with docker run. It must be run from a docker host, or a manager node of a swarm cluster. The current skopos edge release also uses skopos-discover to perform application discovery initiated through the skopos UI.

⁠How skopos-discover Works
⁠Basic Operation

skopos-discover creates, and after use destroys, a skopos-discover-eye container/task on each examined host/swarm-node. The discover eye uses the docker API to collect data about running services and instances, and to execute ss or netstat on these instances in order to determine network dependencies. skopos-discover aggregates and merges these results so that they may be processed to create the skopos application output files.

⁠Output

By default, skopos-discover creates as output a single model and environment file pair representing all of the discovered containerized infrastructure. The command line option --discriminate-apps may cause multiple such pairs to be created, in which case:

  • each swarm stack is represented by a single app
  • each docker compose project is represented by a single app
  • remaining instances are grouped into apps by network commonality
  • the default app containing all discovered instances is also produced

The created model and environment pairs are output by default to the directory /skopos/output in the filesystem of the container, or optionally as YAML to stdout (in which case status information is output to stderr). The output directory is typically bind-mounted to provide access to the output files.

Applications discovered from swarm stacks and docker compose projects may be loaded as-is into skopos and used to provide continuous deployment. The output files for these applications are in the form:

  • discover.stack.<stack_name>.model.yaml and discover.stack.<stack_name>.env.yaml
  • discover.project.<project_name>.model.yaml and discover.stack.<project_name>.env.yaml

To load such a discovered application so that it is transformable by skopos, use the -project option to set the project name equal to the stack name or compose project name (as indicated in the output file(s).

Applications whose discovery is not based on a swarm stack or compose project (e.g., those whose componentes are grouped by network commonality, or the default app containing all discovered instances) are not transformable by skopos as-is. These discovered applications are provided as a reference so that the user may review all running instances on the host/swarm regardless of their provenance. Please see the section on Limitations for detailed information about discovered apps.

⁠Scan Duration

By default, skopos-discover scans just until each eye reports a successful scan of its host/swarm-node. The option --scan-duration may be used to specify a prolonged scan duration in minutes. In this case, each eye iterates its scan periodically until the duration expires. This is useful for collecting network activity over a longer period in order to enrich component connection/dependency data.

⁠Example Usage

The following examples were executed on a manager node of a three node swarm cluster running a scalable version of the standard docker example-voting-app⁠.

⁠Example #1

This example uses the skopos-discover utility to discover a single aggregate application. The application files model.yaml and env.yaml are output to the current directory on the swarm manager node (where this command is run from).

docker run --rm -i \
-v $PWD:/skopos/output \
-v /var/run/docker.sock:/var/run/docker.sock \
opsani/skopos-discover

  The interactive status output of this command is shown below to provide context for its operation:

Info:  creating global eye service:  skopos-discover-eye-80ac96b5a17a72d6
Info:  eye task scan period in minutes:  0.25
Info:  waiting for eye tasks to transition to running state
Info:  ===> start scan
Info:      retrieving discovery data from each eye task:
Info:          task 56808yvcdv92p18q9xuscqa5o has completed 1 scan iteration
Info:          task al8g5qbaad9dhue2kadzcwf0y has completed 1 scan iteration
Info:          task v64euqyfqvcqgenkop5545u3o has completed 1 scan iteration
Info:  <=== end scan
Info:  processing service data
Info:  processing instance data
Info:  grouping instances into components by app
Info:  determining component dependencies
Info:  creating skopos model and env for each app
Info:  assigning model component and gateway visual positions
Info:  creating app model file:  /skopos/output/model.yaml
Info:  creating app env file:  /skopos/output/env.yaml
Info:  discovery completed

  The resulting env.yaml and model.yaml when loaded into skopos yield the model view below. Note:

  • There is no connection between the vote component and the redis component: this is because the application is cold - there has been no recent network traffic between these two components.
  • The components (swarm services) indicate their proper image semantic versions where available, or otherwise the dynamic verstion latest.
  • The input gateways hp-10000 and hp-10001 represent that the connected components expose these ports to be load-balanced by the swarm routing mesh.

example-voting-app discovery 1

⁠Example #2

In this second example example the discovery scan is given an explicit duration of two mintutes. During these two minutes, a human accessed the example-voting-app vote component web UI to cast a vote (for cats :). This causes the vote component to communicate with the redis component, and so the resulting discovery includes this connection.

docker run --rm -i \
-v $PWD:/skopos/output \
-v /var/run/docker.sock:/var/run/docker.sock \
opsani/skopos-discover --scan-duration 2.0

  When loaded into Skopos, the discovered application produces the following model view:

example-voting-app discovery 2

Notably in this second example command:

  • -v $PWD:/skopos/output: mount the current directory so that the model and env output files will be written there
  • -v /var/run/docker.sock:/var/run/docker.sock: mount the docker socket so that skopos-discover can access the docker API
  • opsani/skopos-discover: the skopos-discover image
  • --scan-duration 2.0: argument to the skopos-discover utility - scan for 2.0 minutes. During this time skopos-discover will iteratively scan the docker host/swarm-cluster and aggregate/merge discovered instance and network data.
⁠Command Line Options

The following optional command line arguments may be provided to skopos-discover:

  • -h, --help: show help message and exit
  • --discriminate-apps: discriminate instances into applications by stack or network, and create a model and env pair for each application
  • --debug: output raw data as JSON file debug.json
  • --scan-duration SCAN_DURATION: duration in minutes of scan. Default: 0.0 which implies scan once
  • --stdout: output model(s) and environment(s) as a YAML data structure on stdout; suppress output file creation. Incompatible with the --load option.
⁠Limitations

General limitations of discovered applications include:

  • Applications discovered from docker compose projects (not swarm stacks) presume that all components use the default project network, and only this network is supported in discovery.
  • Only applications discovered from compose projects or swarm stacks are transformable as-is by skopos.
  • Discovery is limited to the objects and attributes described below for each of the model and environment.

Discovered skopos models include the following objects and attributes:

  • components:
    • image: the discovered image includes an explicit tag where available; otherwise, the latest tag is used
    • uses: includes strict start order dependencies on other components determined from the ss/netstat results from the discovery scan
    • provides: includes provided ports, excluding any ports provided on the image specification, and including any ports targeted by a gateway
    • visual: components are positioned in respect of their start order dependencies
    • replicas: the number of component replicas (service tasks, or replicated container instances)
    • singleton: a component is attributed as a singleton if its replicas count is 1 and either it has a read-write mount, or it is port-mapped to the single host under docker (not docker-swarm)
    • labels: includes discovered labels except those beginning with com.docker.
    • volumes:
      • discovery includes volume and bind mounts, not tmpfs
      • volume keys are volume logical names whose from attribute is set in the environment file, and whose path and readonly attributes are set in the model
      • no other volume attributes are discovered (e.g., bind options, driver options, labels, etc.)
    • plugin: configuration specific to the core plugin specified in the environment file. Limited to:
      • docker-swarm:
        • command and args: as discovered from the service task template container specification
        • default_network: boolean indicating whether or not the component is attached to the application default network
        • networks: list of component non-default target networks and their aliases
        • raw: discovered raw attributes include placement contraints and global mode for global services
      • docker:
        • cmd: where non-identical to the image cmd specification
    • env: any environment variables not set on the image specification
    • gateways: discovered gateways for component exposed ports are described here according to the core plugin, docker or docker-swarm:
      • docker-swarm:
        • a host_port gateway is included for any ingress to a service, typically provided through the swarm routing mesh
        • a gateway may also include docker-swarm specific plugin configuration for publish_mode=host
      • docker:
        • a host_port gateway is included for any port binding with a published port
        • a load_balancer gateway is included for any port binding that does not include a published port. This gateway uses the load_balancer_plugin defined in the environment file which will required specific attribution before the application is transformable.

Discovered skopos environments include the following objects and attributes:

  • core_plugin: docker-swarm or docker
  • load_balancer_plugin: same as the core plugin except wher the core plugin is docker and a load_balancer gateway is used, in which case docker-elb is used for the load balancer plugin
  • service_discovery_plugin: same as the core plugin
  • service_discovery_auto: always set to true
  • plugin_config: the plugin config includes the volume map, keyed by logical volume name, for any discovered volumes

Tag summary

Content type

Image

Digest

Size

34.6 MB

Last updated

about 9 years ago

docker pull opsani/skopos-discover