Versions Compared

Key

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

...

  • Python® is a frequently used scripting language available for Linux, MacOS, Windows and other platforms.
  • Docker® offers a Python® SDK to manage containers, see https://docs.docker.com/engine/api/sdk/
  • This article explains how to use the Python® SDK for Docker® with JS7 job 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 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 one a Job Resource per container.
    • This allows to specify any properties of a container such as image name, host name, container name, mounts etc. from variables of a Job Resource.

...

Download (upload .json): agent-2-0-standalone.jobresource.json

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

  • The Arguments sub-view that allows to specify specifying variables holding 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 that allows to specify specifying environment variables from pairs of names and values that are forwarded to shell jobs.
    • Environment Variables can be used of for parameterization of shell jobs.
  • The below names and values are an example examples for 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 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 use variables from both JVM jobs and shell jobs.
    • As an alternative it is possible to directly assign strings to values of environment variables and not to use the Arguments sub-view.

...


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

...

Explanation:

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

...