Skip to content

Cloud Deployment

voyz edited this page Feb 16, 2024 · 5 revisions

One of the most common usages of IBeam would be to deploy it as a Docker container on a remote server, using cloud providers such as AWS, GCP or DigitalOcean.

The following is a simple guide that should help you get started with the remote deployment.

Note: some users got in touch with me to help them get IBeam deployed on the cloud, which I now do for a fee. If you'd rather have me set this all up for you, get in touch at hello@voyzan.com. Naturally, if you don't want to hire me and would like to do this yourself, I'm still happy to answer your questions in the Issues.

Digital Ocean

Server Creation

Initiate a DigitalOcean droplet employing the specifications below.

  1. Region: New York (alternatively, select the most appropriate region for your needs)
  2. Choose an Image -> Marketplace: Docker
  3. Droplet Type: Basic
  4. CPU Options: Regular, 2GB RAM (additional specifications are of less importance)
  5. Choose Authentication Method: Password (Attempts to use SSH keys were unsuccessful. Password setup using 'root' is sufficiently straightforward).
  6. Hostname: Enter a descriptive name, such as 'ibeam01'

Note: Employing 'root' access for server setup is generally not advisable. This guideline is intended as a preliminary setup reference, aiming to prompt users towards enhancing security measures.

Server Configuration

Access the server using SSH.

If private SSH keys were successful, proceed accordingly; if not, utilize 'Access Console -> Launch Droplet Console'.

Execute the following commands as root:

  1. nano setup.sh
  2. Insert the setup.sh script content from Appendix A at the end of this document.
  3. To save, press CTRL+X, confirm with ‘Y’, and press ENTER.
  4. . setup.sh [YOUR IBKR ACCOUNT NAME] [YOUR IBKR ACCOUNT PASSWORD]

This will result in the directory structure as follows:

root
└───ibeam_files
    ├───inputs_directory
    │   └───conf.yaml
    ├───outputs
    └───env.list

Review the configuration files thoroughly:

  1. /root/ibeam_files/env.list - Validate against the current IBeam version for necessary variable settings. Ensure your credentials are accurately entered.
  2. /root/ibeam_files/inputs_directory/conf.yaml - Verify the IPs under 'allow' match those you will be requesting from.

IBeam Initiation

Ensure the preceding IBeam configuration is complete and all files are located in /root/ibeam_files.

Utilising starter.sh

The setup.sh script generates a starter.sh script, simplifying the IBeam start process with correct configuration.

Execute it as follows (observe the leading dot):

. starter.sh

starter.sh supports several parameters (with default values indicated):

  • -e –env (env.list): file containing environment variables
  • -t –tag (latest): IBeam image version to use
  • -i –ibeam_files (/root/ibeam_files): IBeam file directory
  • -n –name (ibeam): IBeam container identifier

For instance:

. starter.sh -t 0.4.4 -e env_secondary.list

This command launches IBeam with the ‘0.4.4’ tag and uses the ‘env_secondary.list’ for environmental settings.

Manual Launch

Alternatively, IBeam can be directly initiated with the following Docker command:

docker run -d --env-file /root/ibeam_files/env.list --name ibeam -p 5000:5000 -v /root/ibeam_files/inputs_directory/:/srv/inputs -v /root/ibeam_files/outputs:/srv/outputs:rw voyz/ibeam:latest

Log Monitoring

To view IBeam logs, open a new Terminal and execute:

docker logs -f ibeam

Connection Verification

To confirm IBeam login success, execute:

curl -X GET "https://localhost:5000/v1/api/tickle" -k

The output should display authenticated:true to indicate success. If it shows false, or if authentication status is missing, or the command fails, login was not successful.

IBeam and Server Restart Procedures

To restart IBeam (excluding the server), perform:

docker stop ibeam
docker start ibeam

To reboot the DigitalOcean server, use:

reboot

Confirming IBeam Launch:

docker ps

Check for ‘Up X minutes’ in the STATUS column.

Wait a few moments and re-execute the connection verification step to ensure a successful connection.

curl -X GET "https://localhost:5000/v1/api/tickle" -k

Updating IBeam Version

Halt IBeam:

docker stop ibeam

Execute the starter script specifying the new version tag: . starter.sh -t [NEW_VERSION_TAG_HERE]

For example, to update to version -t 0.5.0.

Following the update and restart, confirm IBeam's operation with:

docker ps

Examine IBeam's logs to ensure it has successfully authenticated.

Virtual Display Configuration

For the option of remote server access via RDP, perform the following steps:

  1. Update package lists: sudo apt-get update
  2. Install xrdp: sudo apt-get install -y xrdp
  3. Allow RDP traffic through the firewall: sudo ufw allow 3389/tcp
  4. Install XFCE4 desktop environment: sudo apt-get install -y xfce4
  5. Configure XFCE4 as the default session for xrdp: echo xfce4-session > ~/.xsession
  6. Enable and start xrdp service: sudo systemctl enable xrdp sudo systemctl start xrdp

You can now connect remotely using the server's IP address and root credentials via Remote Desktop Connection.

System Resource Monitoring with Gnome System Monitor

  • Install Gnome System Monitor for resource tracking: sudo apt-get install gnome-system-monitor
  • It's advisable to keep the system monitor active to prevent memory overuse.

Web Browser Installation

  • For internet access, install a browser like Firefox: sudo apt install firefox

Appendix A

setup.sh:

#!/bin/bash

# Ensure exactly two arguments are provided
if [[ $# -ne 2 ]]; then
  echo "Proper usage: $0 <IBKR account name> <IBKR account password>"
  exit 1
fi

echo "Beginning setup..."

# Establish IBeam configuration directories
echo "Constructing IBeam configuration directories..."
mkdir -p /root/ibeam_files/outputs
chmod 777 /root/ibeam_files/outputs
mkdir /root/ibeam_files/inputs_directory

# Generate environment variable file
echo "Generating environment variables file at /root/ibeam_files/env.list..."
cat <<EOF > /root/ibeam_files/env.list
IBEAM_ACCOUNT=$1
IBEAM_PASSWORD=$2
IBEAM_OUTPUTS_DIR=/srv/outputs
EOF

# Generate conf.yaml for IBeam Gateway configuration
echo "Generating Gateway config file at /root/ibeam_files/inputs_directory/conf.yaml..."
cat <<EOF > /root/ibeam_files/inputs_directory/conf.yaml
ip2loc: "US"
proxyRemoteSsl: true
proxyRemoteHost: "https://api.ibkr.com"
listenPort: 5000
listenSsl: true
ccp: false
svcEnvironment: "v1"
sslCert: "vertx.jks"
sslPwd: "mywebapi"
authDelay: 3000
portalBaseURL: ""
serverOptions:
  blockedThreadCheckInterval: 1000000
  eventLoopPoolSize: 20
  workerPoolSize: 20
  maxWorkerExecuteTime: 100
  internalBlockingPoolSize: 20
cors:
  origin.allowed: "*"
  allowCredentials: false
webApps:
  - name: "demo"
    index: "index.html"
ips:
  allow:
    - 10.*
    - 192.*
    - 131.216.*
    - 127.0.0.1
    - 0.0.0.0
    - 172.17.0.*
  deny:
    - 212.90.324.10
EOF

# Set up IBeam autostart service
echo "Setting up autostart service at /etc/systemd/system/ibeam_autostart.service..."
cat <<EOF > /etc/systemd/system/ibeam_autostart.service
[Unit]
Description=IBeam container
Requires=docker.service
After=docker.service

[Service]
Restart=always
ExecStart=/usr/bin/docker start -a ibeam
ExecStop=/usr/bin/docker stop -t 2 ibeam

[Install]
WantedBy=default.target
EOF

sudo systemctl enable ibeam_autostart.service

# Create starter script
echo "Creating IBeam starter script at starter.sh..."
cat <<EOF > starter.sh
#!/bin/bash

# Default script parameters
ENV="env.list"
TAG="latest"
IBEAM_FILES="/root/ibeam_files"
CONTAINER_NAME="ibeam"

# Parse command-line arguments
while [[ \$# -gt 0 ]]; do
  key="\$1"
  case \$key in
    -e|--env)
      ENV="\$2"
      shift # past argument
      shift # past value
      ;;
    -t|--tag)
      TAG="\$2"
      shift # past argument
      shift # past value
      ;;
    -i|--ibeam_files)
      IBEAM_FILES="\$2"
      shift # past argument
      shift # past value
      ;;
    -n|--name)
      CONTAINER_NAME="\$2"
      shift # past argument
      shift # past value
      ;;
    *)
      echo "Unrecognized option: \$1"
      shift # past argument
      ;;
  esac
done

echo "Environment variables file: \$ENV"
echo "IBeam Docker image tag: \$TAG"
echo "Container name: \$CONTAINER_NAME"
echo "Directory for IBeam files: \$IBEAM_FILES"

echo "Removing any existing IBeam container..."
docker rm -f ibeam

echo "Launching IBeam..."
docker run -d --env-file "\$IBEAM_FILES/\$ENV" --name "\$CONTAINER_NAME" -p 5000:5000 -v "\$IBEAM_FILES/inputs_directory/:/srv/inputs" -v "\$IBEAM_FILES/outputs:/srv/outputs:rw" voyz/ibeam:\$TAG
EOF

# Fetch and display server's IP address
MY_IP=$(ip -o route get to 8.8.8.8 | sed -n 's/.*src \([0-9.]\+\).*/\1/p')
cat << EOF



Setup completed!

Next steps:
1. Remotely connect to this server using its IP address: $MY_IP
2. Verify the configuration files in '/root/ibeam_files' directory
3. Start IBeam using the 'starter.sh' file
EOF

Next

Learn about Inputs And Outputs and IBeam Configuration