diff --git a/docker-compose/.env b/docker-compose/.env new file mode 100644 index 0000000000000000000000000000000000000000..bf415f70a3466cd1dcdf87437e8d4e97758f6087 --- /dev/null +++ b/docker-compose/.env @@ -0,0 +1,2 @@ +DOCKER_REGISTRY_HOST=nexus.engageska-portugal.pt +DOCKER_REGISTRY_USER=ska-docker diff --git a/docker-compose/Makefile b/docker-compose/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..9af37b2276ff462a44918beaa3410745379f45bc --- /dev/null +++ b/docker-compose/Makefile @@ -0,0 +1,126 @@ +# Set dir of Makefile to a variable to use later +MAKEPATH := $(abspath $(lastword $(MAKEFILE_LIST))) +BASEDIR := $(notdir $(patsubst %/,%,$(dir $(MAKEPATH)))) + +COMPOSE_FILES := $(wildcard *.yml) +COMPOSE_FILE_ARGS := $(foreach yml,$(COMPOSE_FILES),-f $(yml)) + +ATTACH_COMPOSE_FILE_ARGS := $(foreach yml,$(filter-out tango.yml,$(COMPOSE_FILES)),-f $(yml)) + +# If the first make argument is "start" or "stop"... +ifeq (start,$(firstword $(MAKECMDGOALS))) + SERVICE_TARGET = true +else ifeq (stop,$(firstword $(MAKECMDGOALS))) + SERVICE_TARGET = true +else ifeq (attach,$(firstword $(MAKECMDGOALS))) + SERVICE_TARGET = true +ifndef NETWORK_MODE +$(error NETWORK_MODE must specify the network to attach to, e.g., make NETWORK_MODE=tangonet-powersupply ...) +endif +ifndef TANGO_HOST +$(error TANGO_HOST must specify the Tango database device, e.g., make TANGO_HOST=powersupply-databaseds:100000 ...) +endif +endif +ifdef SERVICE_TARGET + # .. then use the rest as arguments for the make target + SERVICE := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)) + # ...and turn them into do-nothing targets + $(eval $(SERVICE):;@:) +endif + +# +# Never use the network=host mode when running CI jobs, and add extra +# distinguishing identifiers to the network name and container names to +# prevent collisions with jobs from the same project running at the same +# time. +# +ifneq ($(CI_JOB_ID),) +NETWORK_MODE := tangonet-$(CI_JOB_ID) +CONTAINER_NAME_PREFIX := $(CI_JOB_ID)- +else +CONTAINER_NAME_PREFIX := +$(info Network mode cannot be host for the archiver! It won't work unless you set the env var CI_JOB_ID=local) +endif + +ifeq ($(OS),Windows_NT) + $(error Sorry, Windows is not supported yet) +else + UNAME_S := $(shell uname -s) + ifeq ($(UNAME_S),Linux) + DISPLAY ?= :0.0 + NETWORK_MODE ?= host + XAUTHORITY_MOUNT := /tmp/.X11-unix:/tmp/.X11-unix + XAUTHORITY ?= /hosthome/.Xauthority + # /bin/sh (=dash) does not evaluate 'docker network' conditionals correctly + SHELL := /bin/bash + endif + ifeq ($(UNAME_S),Darwin) + IF_INTERFACE := $(shell scutil --nwi | grep 'Network interfaces:' | cut -d' ' -f3) + IP_ADDRESS := $(shell scutil --nwi | grep 'address' | cut -d':' -f2 | tr -d ' ' | head -n1) + DISPLAY := $(IP_ADDRESS):0 + # Make sure that Darwin, especially from macOS Catalina on, + # allows X access from our Docker containers. + ADD_TO_XHOST := $(shell xhost +$(IP_ADDRESS)) + # network_mode = host doesn't work on MacOS, so fix to the internal network + NETWORK_MODE ?= tangonet + XAUTHORITY_MOUNT := $(HOME)/.Xauthority:/hosthome/.Xauthority:ro + XAUTHORITY := /hosthome/.Xauthority + endif +endif + +# +# When running in network=host mode, point devices at a port on the host +# machine rather than at the container. +# +ifeq ($(NETWORK_MODE),host) + TANGO_HOST := $(shell hostname):10000 + MYSQL_HOST := $(shell hostname):3306 +else + TANGO_HOST := $(CONTAINER_NAME_PREFIX)databaseds:10000 + MYSQL_HOST := $(CONTAINER_NAME_PREFIX)tangodb:3306 +endif + +DOCKER_COMPOSE_ARGS := DISPLAY=$(DISPLAY) XAUTHORITY=$(XAUTHORITY) TANGO_HOST=$(TANGO_HOST) \ + NETWORK_MODE=$(NETWORK_MODE) XAUTHORITY_MOUNT=$(XAUTHORITY_MOUNT) TANGO_SKA_CONTAINER_MOUNT=$(TANGO_SKA_CONTAINER_MOUNT) TANGO_LOFAR_CONTAINER_MOUNT=$(TANGO_LOFAR_CONTAINER_MOUNT) MYSQL_HOST=$(MYSQL_HOST) \ + CONTAINER_NAME_PREFIX=$(CONTAINER_NAME_PREFIX) COMPOSE_IGNORE_ORPHANS=true + + +.PHONY: up down minimal start stop status clean pull help +.DEFAULT_GOAL := help + +pull: ## pull the images from the Docker hub + $(DOCKER_COMPOSE_ARGS) docker-compose $(COMPOSE_FILE_ARGS) pull + +up: minimal ## start the base TANGO system and prepare all services + $(DOCKER_COMPOSE_ARGS) docker-compose $(COMPOSE_FILE_ARGS) up --no-start + +down: ## stop all services and tear down the system + $(DOCKER_COMPOSE_ARGS) docker-compose $(COMPOSE_FILE_ARGS) down +ifneq ($(NETWORK_MODE),host) + docker network inspect $(NETWORK_MODE) &> /dev/null && ([ $$? -eq 0 ] && docker network rm $(NETWORK_MODE)) || true +endif + +minimal: ## start the base TANGO system +ifneq ($(NETWORK_MODE),host) + docker network inspect $(NETWORK_MODE) &> /dev/null || ([ $$? -ne 0 ] && docker network create $(NETWORK_MODE)) +endif + $(DOCKER_COMPOSE_ARGS) docker-compose -f tango.yml up -d + +start: up ## start a service (usage: make start <servicename>) + $(DOCKER_COMPOSE_ARGS) docker-compose $(COMPOSE_FILE_ARGS) start $(SERVICE) + +stop: ## stop a service (usage: make stop <servicename>) + $(DOCKER_COMPOSE_ARGS) docker-compose $(COMPOSE_FILE_ARGS) stop $(SERVICE) + +attach: ## attach a service to an existing Tango network + $(DOCKER_COMPOSE_ARGS) docker-compose $(ATTACH_COMPOSE_FILE_ARGS) up -d $(SERVICE) + +status: ## show the container status + $(DOCKER_COMPOSE_ARGS) docker-compose $(COMPOSE_FILE_ARGS) ps + +clean: down ## clear all TANGO database entries + docker volume rm $(BASEDIR)_tangodb + +help: ## show this help. + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' + diff --git a/docker-compose/archiver.yml b/docker-compose/archiver.yml new file mode 100644 index 0000000000000000000000000000000000000000..e423c79ead2b599338a89e16311a78c88e1c4d33 --- /dev/null +++ b/docker-compose/archiver.yml @@ -0,0 +1,70 @@ +version: '2' + +services: + maria-db: + image: ${DOCKER_REGISTRY_HOST}/${DOCKER_REGISTRY_USER}/mariadb_hdbpp:latest + container_name: archiver-maria-db + network_mode: ${NETWORK_MODE} + depends_on: + - databaseds + environment: + - MYSQL_ROOT_PASSWORD=secret + - MYSQL_DATABASE=hdbpp + - MYSQL_HOST=archiver-maria-db:3306 + - MYSQL_USER=tango + - MYSQL_PASSWORD=tango + - TANGO_HOST=${TANGO_HOST} + restart: on-failure + + hdbpp-es: + image: ${DOCKER_REGISTRY_HOST}/${DOCKER_REGISTRY_USER}/tango-archiver:latest + network_mode: ${NETWORK_MODE} + container_name: hdbpp-es + depends_on: + - databaseds + - dsconfig + - maria-db + environment: + - TANGO_HOST=${TANGO_HOST} + - HdbManager=archiving/hdbpp/confmanager01 + command: > + /bin/bash -c " + wait-for-it.sh archiver-maria-db:3306 --timeout=30 --strict -- + wait-for-it.sh ${TANGO_HOST} --timeout=30 --strict -- + hdbppes-srv 01" + + hdbpp-cm: + image: ${DOCKER_REGISTRY_HOST}/${DOCKER_REGISTRY_USER}/tango-archiver:latest + network_mode: ${NETWORK_MODE} + container_name: hdbpp-cm + depends_on: + - databaseds + - dsconfig + - maria-db + environment: + - TANGO_HOST=${TANGO_HOST} + - HdbManager=archiving/hdbpp/confmanager01 + command: > + /bin/bash -c " + wait-for-it.sh archiver-maria-db:3306 --timeout=30 --strict -- + wait-for-it.sh ${TANGO_HOST} --timeout=30 --strict -- + hdbppcm-srv 01" + + dsconfig: + image: ${DOCKER_REGISTRY_HOST}/${DOCKER_REGISTRY_USER}/tango-dsconfig:latest + container_name: dsconfig + network_mode: ${NETWORK_MODE} + depends_on: + - databaseds + environment: + - TANGO_HOST=${TANGO_HOST} + command: > + sh -c "wait-for-it.sh ${TANGO_HOST} --timeout=30 --strict -- + json2tango -w -a -u /tango-archiver/data/archiver-devices.json && + sleep infinity" + volumes: + - ${TANGO_SKA_CONTAINER_MOUNT} + - ${TANGO_LOFAR_CONTAINER_MOUNT} + - ${HOME}:/hosthome + - ../docker/tango/tango-archiver:/tango-archiver + diff --git a/docker-compose/astor.yml b/docker-compose/astor.yml new file mode 100644 index 0000000000000000000000000000000000000000..7911b66f9cda51aa6585fb37b18408eef6349754 --- /dev/null +++ b/docker-compose/astor.yml @@ -0,0 +1,50 @@ +# +# Docker compose file that launches Astor, sending the display to a remote X11 +# display. +# +# Defines: +# - astor: service that runs Astor in a container +# - container1: example container running Starter device +# +# Requires: +# - tango.yml +# +version: '2' + +services: + astor: + image: ${DOCKER_REGISTRY_HOST}/${DOCKER_REGISTRY_USER}/tango-java:latest + container_name: ${CONTAINER_NAME_PREFIX}astor + network_mode: ${NETWORK_MODE} + volumes: + - ${XAUTHORITY_MOUNT} + environment: + - XAUTHORITY=${XAUTHORITY} + - DISPLAY=${DISPLAY} + - TANGO_HOST=${TANGO_HOST} + entrypoint: + - /usr/local/bin/wait-for-it.sh + - ${TANGO_HOST} + - --timeout=30 + - --strict + - -- + - /usr/local/bin/astor + + starter-example: + image: ${DOCKER_REGISTRY_HOST}/${DOCKER_REGISTRY_USER}/tango-starter:latest + container_name: ${CONTAINER_NAME_PREFIX}starter-example + network_mode: ${NETWORK_MODE} + # set the hostname, otherwise duplicate device registrations result every + # time the hostname changes as the container is restarted. + hostname: starter-example + environment: + - TANGO_HOST=${TANGO_HOST} + entrypoint: + - /usr/local/bin/wait-for-it.sh + - ${TANGO_HOST} + - --timeout=30 + - --strict + - -- + - /usr/bin/supervisord + - --configuration + - /etc/supervisor/supervisord.conf diff --git a/docker-compose/hdbpp_viewer.yml b/docker-compose/hdbpp_viewer.yml new file mode 100644 index 0000000000000000000000000000000000000000..cf65548b25fca787e56a3ab03333daa09c12aa5b --- /dev/null +++ b/docker-compose/hdbpp_viewer.yml @@ -0,0 +1,40 @@ +# +# Docker compose file that launches HdbViewer, sending the display to a remote X11 +# display. +# +# +# Requires: +# - tango.yml +# +version: '2' + +services: + hdbpp-viewer: + image: ${DOCKER_REGISTRY_HOST}/${DOCKER_REGISTRY_USER}/hdbpp_viewer:latest + container_name: ${CONTAINER_NAME_PREFIX}hdbpp-viewer + network_mode: ${NETWORK_MODE} + depends_on: + - databaseds + - dsconfig + - maria-db + - hdbpp-es + - hdbpp-cm + volumes: + - ${XAUTHORITY_MOUNT} + environment: + - XAUTHORITY=${XAUTHORITY} + - DISPLAY=${DISPLAY} + - TANGO_HOST=${TANGO_HOST} + - HDB_TYPE=mysql + - HDB_MYSQL_HOST=archiver-maria-db + - HDB_MYSQL_PORT=3306 + - HDB_USER=tango + - HDB_PASSWORD=tango + - HDB_NAME=hdbpp + - CLASSPATH=JTango.jar:ATKCore.jar:ATKWidget.jar:jhdbviewer.jar:HDBPP.jar:jython.jar:jcalendar.jar + entrypoint: + - wait-for-it.sh + - ${TANGO_HOST} + - --strict + - -- + - ./hdbpp_viewer/hdbpp_viewer_script diff --git a/docker-compose/itango.yml b/docker-compose/itango.yml new file mode 100644 index 0000000000000000000000000000000000000000..c7006a60fc753562a35bc9cbd79ec83991affd0f --- /dev/null +++ b/docker-compose/itango.yml @@ -0,0 +1,34 @@ +# +# 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: + image: ${DOCKER_REGISTRY_HOST}/${DOCKER_REGISTRY_USER}/tango-itango:latest + container_name: ${CONTAINER_NAME_PREFIX}itango + network_mode: ${NETWORK_MODE} + volumes: + - ${TANGO_SKA_CONTAINER_MOUNT} + - ${TANGO_LOFAR_CONTAINER_MOUNT} + - ${HOME}:/hosthome + environment: + - TANGO_HOST=${TANGO_HOST} + stdin_open: true + tty: true + entrypoint: + - /usr/local/bin/wait-for-it.sh + - ${TANGO_HOST} + - --timeout=30 + - --strict + - -- + - /venv/bin/itango3 diff --git a/docker-compose/jive.yml b/docker-compose/jive.yml new file mode 100644 index 0000000000000000000000000000000000000000..1e8561d408b6aecf5d489c542bf123bf89b6121e --- /dev/null +++ b/docker-compose/jive.yml @@ -0,0 +1,33 @@ +# +# 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: + image: ${DOCKER_REGISTRY_HOST}/${DOCKER_REGISTRY_USER}/tango-java:latest + container_name: ${CONTAINER_NAME_PREFIX}jive + network_mode: ${NETWORK_MODE} + volumes: + - ${XAUTHORITY_MOUNT} + - ${TANGO_SKA_CONTAINER_MOUNT} + - ${TANGO_LOFAR_CONTAINER_MOUNT} + - ${HOME}:/hosthome + environment: + - XAUTHORITY=${XAUTHORITY} + - DISPLAY=${DISPLAY} + - TANGO_HOST=${TANGO_HOST} + entrypoint: + - /usr/local/bin/wait-for-it.sh + - ${TANGO_HOST} + - --timeout=30 + - --strict + - -- + - /usr/local/bin/jive diff --git a/docker-compose/logviewer.yml b/docker-compose/logviewer.yml new file mode 100644 index 0000000000000000000000000000000000000000..ad1d975ec4f611a393bbb12250e582b4ae33671a --- /dev/null +++ b/docker-compose/logviewer.yml @@ -0,0 +1,30 @@ +# +# Docker compose file that launches LogViewer, sending output to a remote X11 +# display. +# +# Defines: +# - logviewer: container running LogViewer +# +# Requires: +# - tango.yml +# +version: '2' + +services: + logviewer: + image: ${DOCKER_REGISTRY_HOST}/${DOCKER_REGISTRY_USER}/tango-java:latest + container_name: ${CONTAINER_NAME_PREFIX}logviewer + network_mode: ${NETWORK_MODE} + volumes: + - ${XAUTHORITY_MOUNT} + environment: + - XAUTHORITY=${XAUTHORITY} + - DISPLAY=${DISPLAY} + - TANGO_HOST=${TANGO_HOST} + entrypoint: + - /usr/local/bin/wait-for-it.sh + - ${TANGO_HOST} + - --timeout=30 + - --strict + - -- + - /usr/local/bin/logviewer diff --git a/docker-compose/pogo.yml b/docker-compose/pogo.yml new file mode 100644 index 0000000000000000000000000000000000000000..c9770ca7b355ea57a96e06b7d76a2d995c3e41a6 --- /dev/null +++ b/docker-compose/pogo.yml @@ -0,0 +1,34 @@ +# +# Docker compose file that launches Pogo, sending the display to a remote X11 +# display. Pogo output can be persisted by writing to either: +# 1. the /home/tango folder, which is a Docker volume persisted between +# container runs; +# 2. the /hosthome folder, which is a r/w mount of your home folder. +# +# Defines: +# - pogo (service): service running Pogo +# - pogo (volume): persistent volume for writing Pogo outut +# +# Requires: +# - N/A +# +version: '2' + +# Create a volume so that Pogo preferences and Pogo output can be persisted +volumes: + pogo: {} + +services: + pogo: + image: ${DOCKER_REGISTRY_HOST}/${DOCKER_REGISTRY_USER}/tango-pogo:latest + container_name: ${CONTAINER_NAME_PREFIX}pogo + network_mode: ${NETWORK_MODE} + volumes: + - pogo:/home/tango + - ${XAUTHORITY_MOUNT} + - ${TANGO_SKA_CONTAINER_MOUNT} + - ${TANGO_LOFAR_CONTAINER_MOUNT} + - ${HOME}:/hosthome:rw + environment: + - XAUTHORITY=${XAUTHORITY} + - DISPLAY=${DISPLAY} diff --git a/docker-compose/rest.yml b/docker-compose/rest.yml new file mode 100644 index 0000000000000000000000000000000000000000..dfbd154b270eb9b6f74ce6b769660e43ebd58b14 --- /dev/null +++ b/docker-compose/rest.yml @@ -0,0 +1,34 @@ +# +# Docker compose file that launches Astor, sending the display to a remote X11 +# display. +# +# Defines: +# - astor: service that runs Astor in a container +# - container1: example container running Starter device +# +# Requires: +# - tango.yml +# +version: '2' + +services: + rest: + image: ${DOCKER_REGISTRY_HOST}/${DOCKER_REGISTRY_USER}/tango-rest:latest + container_name: ${CONTAINER_NAME_PREFIX}tango-rest + network_mode: ${NETWORK_MODE} + # set the hostname, otherwise duplicate device registrations result every + # time the hostname changes as the container is restarted. + hostname: tango-rest + environment: + - TANGO_HOST=${TANGO_HOST} + ports: + - 8080:8080 + entrypoint: + - /usr/local/bin/wait-for-it.sh + - ${TANGO_HOST} + - --timeout=30 + - --strict + - -- + - /usr/bin/supervisord + - --configuration + - /etc/supervisor/supervisord.conf diff --git a/docker-compose/tango.yml b/docker-compose/tango.yml new file mode 100644 index 0000000000000000000000000000000000000000..2540cc35b1bf6faba7ad2c27a977b1d567e18a43 --- /dev/null +++ b/docker-compose/tango.yml @@ -0,0 +1,54 @@ +# +# 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: + image: ${DOCKER_REGISTRY_HOST}/${DOCKER_REGISTRY_USER}/tango-db:latest + container_name: ${CONTAINER_NAME_PREFIX}tangodb + network_mode: ${NETWORK_MODE} + environment: + - MYSQL_ROOT_PASSWORD=secret + - MYSQL_DATABASE=tango + - MYSQL_USER=tango + - MYSQL_PASSWORD=tango + volumes: + - tangodb:/var/lib/mysql + ports: + - "3306:3306" + restart: on-failure + + databaseds: + image: ${DOCKER_REGISTRY_HOST}/${DOCKER_REGISTRY_USER}/tango-cpp:latest + container_name: ${CONTAINER_NAME_PREFIX}databaseds + network_mode: ${NETWORK_MODE} + depends_on: + - tangodb + environment: + - MYSQL_HOST=${MYSQL_HOST} + - MYSQL_DATABASE=tango + - MYSQL_USER=tango + - MYSQL_PASSWORD=tango + - TANGO_HOST=${TANGO_HOST} + entrypoint: + - /usr/local/bin/wait-for-it.sh + - ${MYSQL_HOST} + - --timeout=30 + - --strict + - -- + - /usr/local/bin/DataBaseds + - "2" + - -ORBendPoint + - giop:tcp::10000 + restart: on-failure diff --git a/docker-compose/tangotest.yml b/docker-compose/tangotest.yml new file mode 100644 index 0000000000000000000000000000000000000000..c2be7247749990377932159692631fb79fbd4335 --- /dev/null +++ b/docker-compose/tangotest.yml @@ -0,0 +1,28 @@ +# +# Docker compose file for TANGO test device server. +# +# Defines: +# - tangotest: TANGO test device server +# +# Requires: +# - tango.yml +# +version: '2' + +services: + tangotest: + image: ${DOCKER_REGISTRY_HOST}/${DOCKER_REGISTRY_USER}/tango-java:latest + container_name: ${CONTAINER_NAME_PREFIX}tangotest + network_mode: ${NETWORK_MODE} + environment: + - TANGO_HOST=${TANGO_HOST} + entrypoint: + - /usr/local/bin/wait-for-it.sh + - ${TANGO_HOST} + - --timeout=30 + - --strict + - -- + - /usr/local/bin/TangoTest + - test + restart: on-failure +