#!/usr/bin/env bash
set -eou pipefail

# Define variables
image_name="teleop.docker.zooxlabs.com/rti_base:5.3.1"
rti_name="rti_connext_dds-5.3.1"
rti_archive_name="$rti_name.tar.gz"

# Build image in a temp dir because we need to copy files into the
# dockerfile scope
tmpdir=$(mktemp -d)

# RTI DDS isn't included in the bazel runfiles yet
# RTI downloads are stored in /var/temp via ansible
cp /var/tmp/$rti_archive_name $tmpdir/$rti_archive_name

# Move into our temp dir where all of the needed resources are
cd $tmpdir

# Create the Dockerfile
/bin/cat <<EOM >Dockerfile
FROM teleop.docker.zooxlabs.com/dds_base:1

ADD $rti_archive_name /

ENV NDDSHOME /$rti_name
ENV PATH \$NDDSHOME/bin:\$PATH
EOM

# Build the docker image
docker build -t $image_name .

# Cleanup tmp files
rm -rf $tmpdir
