How to setup local container running Robocorp App

Robocorp Cloud allows you to manage, orchestrate, and schedule the execution of your software robots in a central place. Robocorp Cloud has Processes, which contain steps that Runtime Environments execute.

We instruct how to set up a local Docker container for running Robocorp App. This enables isolating the Robocorp App into ephemeral instances that can be easily managed.

Prerequisites

  • Docker build Environments
  • Robocorp App agent and Robocorp command-line tools (rcc)

Limitations

A Docker container does not have UI access to applications. This means you can run so-called headless operations and access the container's resources but cannot, for example, take screenshots of Windows application UI's.

Container setup

Static container

Static container refers to a container linked to Robocorp Cloud at build time and will be seen in Robocorp Cloud as a single environment every time it is started.

Insert the Robocorp Cloud environment link token and name at build time with the --build-arg argument, and then build and run the image as a container, and the environment will be visible in the cloud.

Dockerfile

# Select the base image
FROM ubuntu:18.04

ARG NAME
ARG LINK_TOKEN

# Set all variables that affect programs to follow the same encoding
ENV LANG=C.UTF-8 LANGUAGE=C.UTF-8 LC_ALL=C.UTF-8

# Install here all the software your process needs in order to execute
RUN apt-get update --fix-missing && \
    apt-get install -y wget bzip2 ca-certificates curl bash build-essential && \
    apt-get install -y fonts-indic fonts-noto fonts-noto-cjk && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

# Running as non-sudo user 'worker'
RUN useradd --no-log-init --system --create-home --shell /bin/bash worker
USER worker
WORKDIR /home/worker

# Create the agent inside the image
RUN mkdir -p /home/worker/bin && mkdir -p /home/worker/instance
RUN curl --silent --show-error --fail -o /home/worker/bin/robocloud-worker https://downloads.cloud.robocorp.com/runtime/latest/linux64/robocloud-worker
RUN chmod +x /home/worker/bin/robocloud-worker

# Create the rcc inside the image
RUN mkdir -p /home/worker/bin/rcc/linux64
RUN curl --silent --show-error --fail -o /home/worker/bin/rcc/linux64/rcc https://downloads.code.robocorp.com/rcc/latest/linux64/rcc
RUN chmod +x /home/worker/bin/rcc/linux64/rcc

# Setup Miniconda using rcc in one layer
RUN /home/worker/bin/rcc/linux64/rcc conda check -i
ENV PATH /home/worker/.robocorp/miniconda3/bin:$PATH

# Setup the run environment(s)
# Here you can give conda.yaml instructions to pre setup any kind of environment
# that will be run in the container
# RUN bin/rcc/linux64/rcc env new path/to/my/conda.yaml

# Link the App to Robocorp Cloud
RUN /home/worker/bin/robocloud-worker link "$LINK_TOKEN" --name "$NAME" --instance-path /home/worker/instance

ENTRYPOINT [ "/home/worker/bin/robocloud-worker", "start", "--instance-path", "/home/worker/instance" ]

Commands

Build:

docker image build --tag robocorpapp_static_container:1.0 --build-arg NAME=<insert name> --build-arg LINK_TOKEN=<insert link token> path/to/Dockerfile

Run:

docker run -dit robocorpapp_static_container:1.0

Dynamic container

Dynamic container refers to a container that is linked at run time. This means that a new environment is visible at Robocorp Cloud every time the container is run.

All workforce processes need to be set to use this environment each time a new environment is created.

Build the image from Dockerfile and then insert the Robocorp Cloud token and name at run time as an environment variable to the run command with the -e run argument to make the environment visible in Robocorp Cloud.

Dockerfile

# Select the base image
FROM ubuntu:18.04

# Set all variables that affect programs to follow the same encoding
ENV LANG=C.UTF-8 LANGUAGE=C.UTF-8 LC_ALL=C.UTF-8

# Install all the software your process needs in order to execute
RUN apt-get update --fix-missing && \
    apt-get install -y wget bzip2 ca-certificates curl bash build-essential && \
    apt-get install -y fonts-indic fonts-noto fonts-noto-cjk && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

# Running as non-sudo user 'worker'
RUN useradd --no-log-init --system --create-home --shell /bin/bash worker
USER worker
WORKDIR /home/worker

# Create the agent inside the image
RUN mkdir -p /home/worker/bin && mkdir -p /home/worker/instance
RUN curl --silent --show-error --fail -o /home/worker/bin/robocloud-worker https://downloads.cloud.robocorp.com/runtime/latest/linux64/robocloud-worker
RUN chmod +x /home/worker/bin/robocloud-worker

# Create rcc inside the image
RUN mkdir -p /home/worker/bin/rcc/linux64
RUN curl --silent --show-error --fail -o /home/worker/bin/rcc/linux64/rcc https://downloads.code.robocorp.com/rcc/latest/linux64/rcc
RUN chmod +x /home/worker/bin/rcc/linux64/rcc

# Set the local scripts in place
COPY ./start.sh start.sh

# Setup Miniconda using rcc in one layer
RUN /home/worker/bin/rcc/linux64/rcc conda check -i
ENV PATH /home/worker/.robocorp/miniconda3/bin:$PATH

# Setup the run environment(s)
# Here you can give conda.yaml instructions to pre setup any kind of environment
# that will be run in the container
# RUN bin/rcc/linux64/rcc env new path/to/my/conda.yaml

ENTRYPOINT [ "./start.sh" ]

Start script

#!/bin/sh

echo "Linking the runtime with name $NAME and token $LINK_TOKEN"
./bin/robocloud-worker link $LINK_TOKEN --name $NAME --instance-path /home/worker/instance
echo "Linking succeeded"

echo "Starting the runtime..."
./bin/robocloud-worker start --instance-path /home/worker/instance

Make sure the start script is executable by running:

chmod +x /path/to/start.sh

Commands

Build:

docker image build --tag robocorpapp_dynamic_container:1.0 path/to/Dockerfile

Run:

docker run -dit -e NAME=<insert name> -e LINK_TOKEN=<insert link token> robocorpapp_dynamic_container:1.0

Runtime configuration

The runtime configuration can be modified to set what commands are allowed to run by default in the instance.

If you want to modify the runtime configuration, create a rtconfig.yml (example below) file and copy it to the Docker instance by adding copy command to Docker file: COPY path/to/rtconfig.yml instance/rtconfig.yml.

#
# Robocorp App configuration
#

run:
  #
  # Specify commands allowed to be executed.
  #
  # Incoming commands are matched against allowed commands list using micromatch:
  #  - micromatch.isMatch(requestedCommand, allowedCommandsArray)
  #  - See https://www.npmjs.com/package/micromatch#ismatch for reference
  #
  # Recommendation: Apply the principle of least privilege. Use exact match
  # with a single command when use case allows.
  #
  allowedCommands:
    # OpenRPA convention: task runner script in scripts/
    - entrypoints/(*.bat|*.sh|*.cmd)
    - scripts/(*.bat|*.sh|*.cmd)
    - (*.bat|*.sh|*.cmd)

    # Print current date/time example.
    # /T is needed on Windows to only output the current date/time.
    - time
    - time /T
    - date
    - date /T

    # Allow everything. Use with caution, e.g., only within the development
    # sandbox.
    - '**'

dataTransfer:
  # Specify what data is allowed to be sent to the cloud from the executed
  # process.
  #
  # When data transfer is enabled, the data including build artifacts, worker
  # console log, and console output are sent to the cloud.
  #
  # If disabled, only the operationally mandatory control messages between
  # cloud and worker are sent to the cloud, and will be printed in the cloud
  # run console output window. To disable data transfer set option
  # 'disable: true'.
  #
  disable: false

Common issues

  • Make sure the start.sh script uses Linux line endings (LF)