Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

Introduction

The JS7 can be used to execute any scripts, executables and programs including Python® scripts.

...

  • Install the Python® SDK as available from https://github.com/docker/docker-py

    Code Block
    languagebash
    titleInstall docker-py plugin
    pip install docker


    • Explanation:
      • Python® has to be available on the machine that the JS7 Agent is operated for. This includes Agents operated on premises and with Docker® containers.
      • This is just an example, there are more ways how to install of installing the Python® SDK for Docker®.

  • Create a workflow with a shell job that imports the Python® SDK like this:

    Code Block
    languagebash
    titleImport docker-py plugin with Agents operated for Unix
    #!/usr/bin/python
    
    import docker
    
    client = docker.from_env()
    ...
    Code Block
    languagebash
    titleImport docker-py plugin with Agents operated for Windows
    @@findstr/v "^@@f.*&" "%~f0"|python.exe -&goto:eof
    
    import docker
    
    client = docker.from_env()
    ...


    Explanation
    :

  • Create JS7 - Job Resources for your containers.
    • Best practice is to use a Job Resource per container.
    • This allows to specify specification of any properties of a container such as image name, host name, container name, mounts etc. from variables of a Job Resource.

Examples

Examples The examples make use of a Job Resource and a number of Workflows that are managed with the Configuration view like this:

...

When managing a Job Resource this view offers two sub-views:

  • The Arguments sub-view allows specifying variables which hold pairs of variable names and values.
    • Arguments can be used for parameterization of JVM jobs and they can be used in workflow instructions such as the JS7 - If Instruction.
  • The Environment Variables sub-view allows specifying environment variables from pairs of names and values that are forwarded to shell jobs.
    • Environment Variables can be used for parameterization of shell jobs.
  • The below following names and values are examples for of frequently used parameters when setting up containers, for example with the docker run command:
    • repository_name: Identifier of the repository
    • image_name: Identifier of the image that is used to instantiate the container.
    • container_name: Name assigned the container.
    • host_name:  Hostname (FQDN) assigned the container.
    • etc.


Consider the below following example of the Environment Variables sub-view:

  • Names of environment variables can be freely chosen within the limits of the operating system. Names are stored with uppercase letters.
  • The values of environment variables reference variables previously configured with the Arguments sub-view.
    • This allows to the use of variables from both JVM jobs and shell jobs.
    • As an alternative it is possible to directly assign strings to the values of environment variables and not to use the Arguments sub-view.

...

Workflow to start a Container

The example makes use of uses a single job that runs on an Agent with access to the Docker® daemon.

...

  • The job script uses a number of parameters as it maps all options used to run a JS7 Agent from a Docker® container as explained with in the JS7 - Agent Installation for Docker Containersarticle. 
  • The relevant part is the client.containers.run() function that which is parameterized with frequently used options to specify for specifying the image name, the hostname, network name etc.
  • Environment variables are available from the assigned Job Resource.
  • The optional part includes displaying log output created on start-up of the container using the container.logs() function.

Workflow to stop a Container

The example makes use of uses a single job that which runs on an Agent with access to the Docker® daemon.


The job script of the single job in this workflow looks like this:

...

  • Download (upload .json): pdExecContainer.workflow.json
  • The job is assigned the agent-2-0-standalone Job Resource that holds the parameters that which identify the container to be stopped.
  • Consider the command workflow variable that which holds the command to be executed in the container. Adding a variable from a workflow offers the increases flexibility that by allowing such variables can to be updated for use with different values from each order that executes the workflow.

...