Skip to content
Snippets Groups Projects
Commit 2694ed7b authored by Stewart Williams's avatar Stewart Williams
Browse files

Initial commit.

parents
Branches
Tags
No related merge requests found
.env 0 → 100644
MY_IP=172.16.13.28
# TANGO Docker containers
This repository defines a set of Docker images and Docker compose files that
are useful for TANGO control system development.
## Building the Docker images
It is recommended that you use the Docker compose files located in the root of
this repository to create a set of tagged docker images. The images created
by the Docker compose files comprise:
Docker image | Description
-----------------------|------------
ska/tango-dependencies | A base image containing TANGO's preferred version of ZeroMQ plus the preferred, patched version of OmniORB.
ska/tangodb | A MariaDB image with TANGO database schema defined. Data is stored separately in a volume
ska/tango | Core C++ TANGO libraries and applications.
ska/tango-java | As per ska/tango, plus Java applications and bindings
ska/tango-python | As per ska/tango, plus pytango Python bindings and itango for interactive TANGO sessions.
To build the images, from the root of this repository execute:
# build the TANGO dependency and core C++ images
docker-compose -f dependencies.yml -f tango.yml build
# build Docker images for Java and Python
docker-compose -f tango.yml -f tangotest.yml -f itango.yml build
Alternatively, images can be created by following the standard Docker image
build procedure using the Dockerfile definitions located in the `tango` directory.
## Launching a TANGO system
The Docker compose files define a set of containers for a TANGO system. In
addition to the processes to be launched, the files define the connections and
dependencies between containers, plus the order in which they must be started.
A minimal TANGO system consisting of a MariaDB database plus TANGO database
server can be started and stopped with:
# start a minimal TANGO system with database and TANGO database server
# Note: omit '-d' if you want the system to launch in the foreground
docker-compose -f tango.yml up -d
# stop the system
docker-compose -f tango.yml down
Additional Docker compose files can be added to the composition to add new
new functions. For instance, to start the TANGO test Java server in addition
to the base system, execute:
docker-compose -f tango.yml -f tangotest.yml up -d
## Interacting with TANGO devices
### Command line interactions
``itango`` can be used for command line interactions with the system. To make
itango available, add it to the system composition, e.g.,
docker-compose -f tango.yml -f tangotest.yml -f itango.yml up -d
An example session that attaches the shell to itango and interacts with the
Java test device server follows:
docker attach itango
In [1]: dev = DeviceProxy('sys/tg_test/1')
In [2]: dev.string_scalar
Out[2]: 'Default string'
...
To detach from the session without quitting the itango session, press the key
combination <CTRL+P><CTRL+Q>.
### GUI interactions
Graphical applications such as Jive can be launched using docker-compose too.
The Jive container sends X11 traffic to the address defined by the ``MY_IP``
variable, which must be defined before the system composition is started.
Thereafter, Jive can be launched by adding jive.yml to the system composition,
e.g.,
export MY_IP=172.16.10.120
docker-compose -f tango.yml -f tangotest.yml -f jive.yml up -d
The IP address information can be persisted by adding it to the .env file in
this directory.
#
# Docker compose file that builds an image containing the TANGO dependencies.
#
version: '2'
services:
dependencies:
build:
context: tango
dockerfile: Dockerfile.dependencies
image: ska/tango-dependencies:9.2.5a
container_name: dependencies
#
# Docker compose file that launches an interactive iTango session.
#
# Connect to the interactive session with 'docker attach itango'.
# Disconnect with the Docker deattach sequence: <CTRL>+<P> <CTRL>+<Q>
#
# Defines:
# - itango: iTango interactive session
#
# Requires:
# - tango.yml
#
version: '2'
services:
itango:
build:
context: tango
dockerfile: Dockerfile.python
image: ska/tango-python:9.2.5a
container_name: itango
depends_on:
- databaseds
environment:
- TANGO_HOST=databaseds:10000
stdin_open: true
tty: true
entrypoint:
- /usr/local/bin/wait-for-it.sh
- databaseds:10000
- --timeout=30
- --strict
- --
- /usr/local/bin/itango
jive.yml 0 → 100644
#
# Docker compose file that launches Jive, sending output to a remote X11
# display.
#
# Defines:
# - jive: container running Jive
#
# Requires:
# - tango.yml
#
version: '2'
services:
jive:
build:
context: tango
dockerfile: Dockerfile.java
image: ska/tango-java:9.2.5a
container_name: jive
depends_on:
- databaseds
volumes:
- $HOME:/hosthome:ro
environment:
- XAUTHORITY=/hosthome/.Xauthority
- DISPLAY=${MY_IP}:0
- TANGO_HOST=databaseds:10000
entrypoint:
- /usr/local/bin/wait-for-it.sh
- databaseds:10000
- --timeout=30
- --strict
- --
- /usr/local/bin/jive
#
# Docker compose file for TANGO database and database device server
#
# Defines:
# - tangodb: MariaDB database with TANGO schema
# - databaseds: TANGO database device server
#
# Requires:
# - None
#
version: '2'
volumes:
tangodb: {}
services:
tangodb:
build:
context: tango
dockerfile: Dockerfile.db
image: ska/tangodb:9.2.5a
container_name: tangodb
environment:
- MYSQL_ROOT_PASSWORD=secret
- MYSQL_DATABASE=tango
- MYSQL_USER=tango
- MYSQL_PASSWORD=tango
volumes:
- tangodb:/var/lib/mysql
databaseds:
build:
context: tango
dockerfile: Dockerfile.base
image: ska/tango-base:9.2.5a
container_name: databaseds
hostname: databaseds
depends_on:
- tangodb
environment:
- MYSQL_HOST=tangodb:3306
- MYSQL_DATABASE=tango
- MYSQL_USER=tango
- MYSQL_PASSWORD=tango
- TANGO_HOST=databaseds:10000
entrypoint:
- /usr/local/bin/wait-for-it.sh
- tangodb:3306
- --timeout=30
- --strict
- --
- /usr/local/bin/DataBaseds
- "2"
- -ORBendPoint
- giop:tcp::10000
FROM ska/tango-dependencies:9.2.5a
RUN TANGO_VERSION=9.2.5a \
&& TANGO_DOWNLOAD_URL=https://netcologne.dl.sourceforge.net/project/tango-cs/tango-$TANGO_VERSION.tar.gz \
&& buildDeps='build-essential ca-certificates curl file libmariadbclient-dev libmariadbclient-dev-compat pkg-config python' \
&& DEBIAN_FRONTEND=noninteractive apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends $buildDeps \
&& rm -rf /var/lib/apt/lists/* \
&& mkdir -p /usr/src/tango \
&& cd /usr/src/tango \
&& curl -fsSL "$TANGO_DOWNLOAD_URL" -o tango.tar.gz \
&& tar xf tango.tar.gz -C /usr/src/tango --strip-components=1 \
&& ./configure --with-zmq=/usr/local --with-omni=/usr/local --with-mysqlclient-prefix=/usr --enable-static=no \
&& make -C /usr/src/tango -j$(nproc) \
&& make -C /usr/src/tango install \
&& ldconfig \
&& apt-get purge -y --auto-remove $buildDeps \
&& rm -r /usr/src/tango
ENV HOME /home/tango
RUN useradd --create-home --home-dir $HOME tango \
&& chown -R tango:tango $HOME
WORKDIR $HOME
USER tango
FROM mariadb:10
ENV TANGO_VERSION=9.2.5a
ENV TANGO_DOWNLOAD_URL=https://netcologne.dl.sourceforge.net/project/tango-cs/tango-$TANGO_VERSION.tar.gz
RUN buildDeps='curl' \
&& DEBIAN_FRONTEND=noninteractive apt-get update \
&& apt-get -y install --no-install-recommends $buildDeps \
&& rm -rf /var/lib/apt/lists/* \
&& mkdir -p /usr/src/tango \
&& cd /usr/src/tango \
&& curl -fsSL "$TANGO_DOWNLOAD_URL" -o tango.tar.gz \
&& tar xf tango.tar.gz -C /usr/src/tango --strip-components=1 \
&& mkdir -p dbinit/include \
&& cp cppserver/database/create_db.sql.in dbinit/create_db.sql \
&& cp cppserver/database/create_db_tables.sql.in dbinit/include/create_db_tables.sql \
&& cp cppserver/database/stored_proc.sql.in dbinit/include/stored_proc.sql \
&& sed -i "s|@TANGO_DB_NAME@|tango|g" dbinit/create_db.sql \
&& sed -i "s|@TANGO_DB_NAME@|tango|g" dbinit/include/create_db_tables.sql \
&& sed -i "s|@TANGO_DB_NAME@|tango|g" dbinit/include/stored_proc.sql \
&& sed -i "s|^source create_db_tables.sql$|source /docker-entrypoint-initdb.d/include/create_db_tables.sql|g" dbinit/create_db.sql \
&& sed -i "s|^source stored_proc.sql$|source /docker-entrypoint-initdb.d/include/stored_proc.sql|g" dbinit/create_db.sql \
&& sed -i "/CREATE DATABASE tango;/d" dbinit/create_db.sql \
&& cp -r dbinit/* /docker-entrypoint-initdb.d \
&& apt-get purge -y --auto-remove $buildDeps \
&& rm -r /usr/src/tango
COPY sql_mode.cnf /etc/mysql/conf.d
FROM debian:stretch
RUN runtimeDeps='libmariadbclient18 doxygen' \
&& DEBIAN_FRONTEND=noninteractive apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends $runtimeDeps \
&& rm -rf /var/lib/apt/lists/*
RUN ZEROMQ_VERSION=4.0.5 \
&& ZEROMQ_DOWNLOAD_URL=https://archive.org/download/zeromq_$ZEROMQ_VERSION/zeromq-$ZEROMQ_VERSION.tar.gz \
&& buildDeps='autoconf automake build-essential ca-certificates curl libkrb5-dev libtool pkg-config unzip' \
&& DEBIAN_FRONTEND=noninteractive apt-get update \
&& apt-get -y install $buildDeps --no-install-recommends \
&& rm -rf /var/lib/apt/lists/* \
&& mkdir /usr/src/zeromq \
&& cd /usr/src/zeromq \
&& curl -fsSL "$ZEROMQ_DOWNLOAD_URL" -o zeromq.tar.gz \
&& tar xf zeromq.tar.gz -C /usr/src/zeromq --strip-components=1 \
&& ./configure --enable-static=no \
&& make -C /usr/src/zeromq -j$(nproc) \
&& make -C /usr/src/zeromq install \
&& apt-get purge -y --auto-remove $buildDeps \
&& rm -r /usr/src/zeromq
RUN OMNIORB_DOWNLOAD_URL=https://svwh.dl.sourceforge.net/project/omniorb/omniORB/omniORB-4.2.1/omniORB-4.2.1-2.tar.bz2 \
&& OMNIORB_PATCH_URL=http://ftp.esrf.fr/pub/cs/tango/Patches/dii_race.patch \
&& buildDeps='build-essential ca-certificates curl python-dev' \
&& DEBIAN_FRONTEND=noninteractive apt-get update \
&& apt-get -y install --no-install-recommends $buildDeps \
&& rm -rf /var/lib/apt/lists/* \
&& mkdir -p /usr/src/omniorb \
&& cd /usr/src/omniorb \
&& curl -fsSL "$OMNIORB_DOWNLOAD_URL" -o omniorb.tar.bz2 \
&& curl -fsSL "$OMNIORB_PATCH_URL" -o dii_race.patch \
&& tar xf omniorb.tar.bz2 -C /usr/src/omniorb --strip-components=1 \
&& patch -p0 < dii_race.patch \
&& ./configure --enable-static=no \
&& make -C /usr/src/omniorb -j$(nproc) \
&& make -C /usr/src/omniorb install \
&& apt-get purge -y --auto-remove $buildDeps \
&& rm -r /usr/src/omniorb
COPY wait-for-it.sh /usr/local/bin/wait-for-it.sh
FROM ska/tango-dependencies:9.2.5a
RUN runtimeDeps='default-jre' \
&& DEBIAN_FRONTEND=noninteractive apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends $runtimeDeps \
&& rm -rf /var/lib/apt/lists/*
RUN TANGO_VERSION=9.2.5a \
&& TANGO_DOWNLOAD_URL=https://netcologne.dl.sourceforge.net/project/tango-cs/tango-$TANGO_VERSION.tar.gz \
&& buildDeps='build-essential curl file libmariadbclient-dev libmariadbclient-dev-compat default-jdk pkg-config python' \
&& DEBIAN_FRONTEND=noninteractive apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends $buildDeps \
&& rm -rf /var/lib/apt/lists/* \
&& mkdir -p /usr/src/tango \
&& cd /usr/src/tango \
&& curl -fsSL "$TANGO_DOWNLOAD_URL" -o tango.tar.gz \
&& tar xf tango.tar.gz -C /usr/src/tango --strip-components=1 \
&& ./configure --with-zmq=/usr/local --with-omni=/usr/local --with-mysqlclient-prefix=/usr --enable-static=no \
&& make -C /usr/src/tango -j$(nproc) \
&& make -C /usr/src/tango install \
&& ldconfig \
&& apt-get purge -y --auto-remove $buildDeps \
&& rm -r /usr/src/tango
ENV HOME /home/tango
RUN useradd --create-home --home-dir $HOME tango \
&& chown -R tango:tango $HOME
WORKDIR $HOME
USER tango
FROM ska/tango-base:9.2.5a
USER root
RUN runtimeDeps='ipython libboost-python1.62.0 python-concurrent.futures python-gevent python-numpy python-six python-zmq python-pkgconfig python-pkg-resources python3 python3-gevent python3-numpy python3-six python3-pkgconfig python3-pkg-resources' \
&& DEBIAN_FRONTEND=noninteractive apt-get update \
&& apt-get -y install --no-install-recommends $runtimeDeps \
&& rm -rf /var/lib/apt/lists/*
RUN PYTANGO_TAG=v9.2.2 \
&& PYTANGO_URL=https://github.com/tango-cs/pytango.git \
&& buildDeps='build-essential ca-certificates git libboost-python-dev python-dev python-setuptools python3-dev python3-setuptools' \
&& DEBIAN_FRONTEND=noninteractive apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends $buildDeps \
&& rm -rf /var/lib/apt/lists/* \
&& mkdir -p /usr/src/pytango \
&& cd /usr/src/pytango \
&& git clone $PYTANGO_URL \
&& cd pytango \
&& git checkout tags/$PYTANGO_TAG \
&& python setup.py build \
&& python setup.py install \
&& python3 setup.py clean \
&& python3 setup.py build \
&& python3 setup.py install \
&& cd .. \
&& apt-get purge -y --auto-remove $buildDeps \
&& rm -r /usr/src/pytango
# itango is a separate project from Pytango v9.2.0 on
RUN buildDeps='python-dev python-pip python-setuptools python3-dev python3-pip python3-setuptools' \
&& DEBIAN_FRONTEND=noninteractive apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends $buildDeps \
&& rm -rf /var/lib/apt/lists/* \
&& pip install itango \
&& pip3 install itango \
&& apt-get purge -y --auto-remove $buildDeps
USER tango
RUN mkdir ~/.ipython
CMD ["itango"]
[mysqld]
sql-mode=""
#!/usr/bin/env bash
# Use this script to test if a given TCP host/port are available
cmdname=$(basename $0)
echoerr() { if [[ $QUIET -ne 1 ]]; then echo "$@" 1>&2; fi }
usage()
{
cat << USAGE >&2
Usage:
$cmdname host:port [-s] [-t timeout] [-- command args]
-h HOST | --host=HOST Host or IP under test
-p PORT | --port=PORT TCP port under test
Alternatively, you specify the host and port as host:port
-s | --strict Only execute subcommand if the test succeeds
-q | --quiet Don't output any status messages
-t TIMEOUT | --timeout=TIMEOUT
Timeout in seconds, zero for no timeout
-- COMMAND ARGS Execute command with args after the test finishes
USAGE
exit 1
}
wait_for()
{
if [[ $TIMEOUT -gt 0 ]]; then
echoerr "$cmdname: waiting $TIMEOUT seconds for $HOST:$PORT"
else
echoerr "$cmdname: waiting for $HOST:$PORT without a timeout"
fi
start_ts=$(date +%s)
while :
do
(echo > /dev/tcp/$HOST/$PORT) >/dev/null 2>&1
result=$?
if [[ $result -eq 0 ]]; then
end_ts=$(date +%s)
echoerr "$cmdname: $HOST:$PORT is available after $((end_ts - start_ts)) seconds"
break
fi
sleep 1
done
return $result
}
wait_for_wrapper()
{
# In order to support SIGINT during timeout: http://unix.stackexchange.com/a/57692
if [[ $QUIET -eq 1 ]]; then
timeout $TIMEOUT $0 --quiet --child --host=$HOST --port=$PORT --timeout=$TIMEOUT &
else
timeout $TIMEOUT $0 --child --host=$HOST --port=$PORT --timeout=$TIMEOUT &
fi
PID=$!
trap "kill -INT -$PID" INT
wait $PID
RESULT=$?
if [[ $RESULT -ne 0 ]]; then
echoerr "$cmdname: timeout occurred after waiting $TIMEOUT seconds for $HOST:$PORT"
fi
return $RESULT
}
# process arguments
while [[ $# -gt 0 ]]
do
case "$1" in
*:* )
hostport=(${1//:/ })
HOST=${hostport[0]}
PORT=${hostport[1]}
shift 1
;;
--child)
CHILD=1
shift 1
;;
-q | --quiet)
QUIET=1
shift 1
;;
-s | --strict)
STRICT=1
shift 1
;;
-h)
HOST="$2"
if [[ $HOST == "" ]]; then break; fi
shift 2
;;
--host=*)
HOST="${1#*=}"
shift 1
;;
-p)
PORT="$2"
if [[ $PORT == "" ]]; then break; fi
shift 2
;;
--port=*)
PORT="${1#*=}"
shift 1
;;
-t)
TIMEOUT="$2"
if [[ $TIMEOUT == "" ]]; then break; fi
shift 2
;;
--timeout=*)
TIMEOUT="${1#*=}"
shift 1
;;
--)
shift
CLI="$@"
break
;;
--help)
usage
;;
*)
echoerr "Unknown argument: $1"
usage
;;
esac
done
if [[ "$HOST" == "" || "$PORT" == "" ]]; then
echoerr "Error: you need to provide a host and port to test."
usage
fi
TIMEOUT=${TIMEOUT:-15}
STRICT=${STRICT:-0}
CHILD=${CHILD:-0}
QUIET=${QUIET:-0}
if [[ $CHILD -gt 0 ]]; then
wait_for
RESULT=$?
exit $RESULT
else
if [[ $TIMEOUT -gt 0 ]]; then
wait_for_wrapper
RESULT=$?
else
wait_for
RESULT=$?
fi
fi
if [[ $CLI != "" ]]; then
if [[ $RESULT -ne 0 && $STRICT -eq 1 ]]; then
echoerr "$cmdname: strict mode, refusing to execute subprocess"
exit $RESULT
fi
exec $CLI
else
exit $RESULT
fi
#
# Docker compose file for TANGO test device server.
#
# Defines:
# - tangotest: TANGO test device server
#
# Requires:
# - tango.yml
#
version: '2'
services:
tangotest:
build:
context: tango
dockerfile: Dockerfile.java
image: ska/tango-java:9.2.5a
container_name: tangotest
depends_on:
- databaseds
environment:
- TANGO_HOST=databaseds:10000
entrypoint:
- /usr/local/bin/wait-for-it.sh
- databaseds:10000
- --timeout=30
- --strict
- --
- /usr/local/bin/TangoTest
- test
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment