From e800e508646c99958ea7c7e17a90bccc34578ef2 Mon Sep 17 00:00:00 2001
From: Jan David Mol <mol@astron.nl>
Date: Tue, 23 Mar 2021 09:49:36 +0100
Subject: [PATCH] Fix software locations in device container, make sure
 lofar-device-base is built first, as docker-compose does not support
 build-time dependencies.

---
 docker-compose/Makefile                       |  2 ++
 docker-compose/device-pcc.yml                 | 30 +++++++++++++++++++
 docker-compose/device-sdp.yml                 | 30 +++++++++++++++++++
 docker-compose/lofar-device-base.yml          | 21 +++++++++++++
 docker-compose/lofar-device-base/Dockerfile   |  4 +++
 .../lofar-device-base/lofar-requirements.txt  |  2 ++
 6 files changed, 89 insertions(+)
 create mode 100644 docker-compose/device-pcc.yml
 create mode 100644 docker-compose/device-sdp.yml
 create mode 100644 docker-compose/lofar-device-base.yml
 create mode 100644 docker-compose/lofar-device-base/Dockerfile
 create mode 100644 docker-compose/lofar-device-base/lofar-requirements.txt

diff --git a/docker-compose/Makefile b/docker-compose/Makefile
index 6c2e767c8..91c9c52c6 100644
--- a/docker-compose/Makefile
+++ b/docker-compose/Makefile
@@ -92,6 +92,8 @@ pull: ## pull the images from the Docker hub
 	$(DOCKER_COMPOSE_ARGS) docker-compose $(COMPOSE_FILE_ARGS) pull
 
 build: ## rebuild images
+	# docker-compose does not support build dependencies, so manage those here
+	$(DOCKER_COMPOSE_ARGS) docker-compose -f lofar-device-base.yml build
 	$(DOCKER_COMPOSE_ARGS) docker-compose $(COMPOSE_FILE_ARGS) build
 
 up: minimal  ## start the base TANGO system and prepare all services
diff --git a/docker-compose/device-pcc.yml b/docker-compose/device-pcc.yml
new file mode 100644
index 000000000..db4848121
--- /dev/null
+++ b/docker-compose/device-pcc.yml
@@ -0,0 +1,30 @@
+#
+# 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:
+#   - lofar-device-base.yml
+#
+version: '2'
+
+services:
+  device-pcc:
+    image: lofar-device-base
+    container_name: ${CONTAINER_NAME_PREFIX}device-pcc
+    network_mode: ${NETWORK_MODE}
+    volumes:
+        - ${TANGO_LOFAR_CONTAINER_MOUNT}
+    environment:
+      - TANGO_HOST=${TANGO_HOST}
+    entrypoint:
+      - /usr/local/bin/wait-for-it.sh
+      - ${TANGO_HOST}
+      - --timeout=30
+      - --strict
+      - --
+      - python3 -u ${TANGO_LOFAR_CONTAINER_DIR}/PCC/PCC LTS -v
diff --git a/docker-compose/device-sdp.yml b/docker-compose/device-sdp.yml
new file mode 100644
index 000000000..8671d8666
--- /dev/null
+++ b/docker-compose/device-sdp.yml
@@ -0,0 +1,30 @@
+#
+# 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:
+#   - lofar-device-base.yml
+#
+version: '2'
+
+services:
+  device-sdp:
+    image: lofar-device-base
+    container_name: ${CONTAINER_NAME_PREFIX}device-sdp
+    network_mode: ${NETWORK_MODE}
+    volumes:
+        - ${TANGO_LOFAR_CONTAINER_MOUNT}
+    environment:
+      - TANGO_HOST=${TANGO_HOST}
+    entrypoint:
+      - /usr/local/bin/wait-for-it.sh
+      - ${TANGO_HOST}
+      - --timeout=30
+      - --strict
+      - --
+      - python3 -u ${TANGO_LOFAR_CONTAINER_DIR}/SDP/SDP LTS -v
diff --git a/docker-compose/lofar-device-base.yml b/docker-compose/lofar-device-base.yml
new file mode 100644
index 000000000..3d40f0f63
--- /dev/null
+++ b/docker-compose/lofar-device-base.yml
@@ -0,0 +1,21 @@
+#
+# Docker compose file that forms the basis for LOFAR tango devices
+#
+# This is an abstract image that does not need to be spinned up, but
+# might be out of consistency with other images.
+#
+# Defines:
+#   - device-base: Base configuration for devices.
+#
+# Requires:
+#   - tango.yml
+#
+version: '2'
+
+services:
+  lofar-device-base:
+    image: lofar-device-base
+    build:
+        context: lofar-device-base
+    container_name: ${CONTAINER_NAME_PREFIX}lofar-device-base
+    network_mode: ${NETWORK_MODE}
diff --git a/docker-compose/lofar-device-base/Dockerfile b/docker-compose/lofar-device-base/Dockerfile
new file mode 100644
index 000000000..cd6b59511
--- /dev/null
+++ b/docker-compose/lofar-device-base/Dockerfile
@@ -0,0 +1,4 @@
+FROM nexus.engageska-portugal.pt/ska-docker/tango-itango:latest
+
+COPY lofar-requirements.txt /lofar-requirements.txt
+RUN pip3 install -r /lofar-requirements.txt
diff --git a/docker-compose/lofar-device-base/lofar-requirements.txt b/docker-compose/lofar-device-base/lofar-requirements.txt
new file mode 100644
index 000000000..90d21efe0
--- /dev/null
+++ b/docker-compose/lofar-device-base/lofar-requirements.txt
@@ -0,0 +1,2 @@
+opcua >= 0.98.9
+astropy 
-- 
GitLab