From 926cfbb56ecbebe40da0cd9e169f57e84261c2d4 Mon Sep 17 00:00:00 2001
From: Stefano Alberto Russo <stefano.russo@gmail.com>
Date: Tue, 14 Apr 2020 16:40:24 +0200
Subject: [PATCH] Decoupled base and prefactor code into two separate
 containers and moved to new container names nomenclature.

---
 README.md                                     |  4 +-
 base/Dockerfile                               | 62 +++++++++++++++++
 base/build_docker_container.sh                |  3 +
 .../data/input_data/README.md                 |  0
 .../data/output_data/README.md                |  0
 {prefactor3 => base}/entrypoint.sh            | 10 +--
 base/run_docker_container.sh                  |  2 +
 {prefactor3 => base}/sudoers                  |  0
 prefactor3/Dockerfile                         | 68 ++-----------------
 prefactor3/build_docker_container.sh          |  2 +-
 prefactor3/run_docker_container.sh            |  2 +-
 prefactor3/run_singularity_container.sh       |  2 +-
 12 files changed, 85 insertions(+), 70 deletions(-)
 create mode 100644 base/Dockerfile
 create mode 100755 base/build_docker_container.sh
 rename {prefactor3 => base}/data/input_data/README.md (100%)
 rename {prefactor3 => base}/data/output_data/README.md (100%)
 rename {prefactor3 => base}/entrypoint.sh (80%)
 create mode 100755 base/run_docker_container.sh
 rename {prefactor3 => base}/sudoers (100%)

diff --git a/README.md b/README.md
index 59e2597..300a611 100644
--- a/README.md
+++ b/README.md
@@ -8,11 +8,11 @@ This container is based on the "lofaruser/imaging-pipeline:v3.10" base image, an
 
 How to run the container with Docker:
 
-    docker run --rm -v $INPUT_DATA_FOLDER:/input_data,$OUTPUT_DATA_FOLDER:/output_data -it lofarit/prefactor3:pipeline_v3.10
+    docker run --rm -v $INPUT_DATA_FOLDER:/input_data,$OUTPUT_DATA_FOLDER:/output_data -it lofarit/lofarit/prefactor3_base3.10
     
 How to run the container wth Singularity:
 
-    singularity run --pid --writable-tmpfs --containall --cleanenv -B$INPUT_DATA_FOLDER:/input_data,$OUTPUT_DATA_FOLDER:/output_data docker://lofarit/prefactor3:pipeline_v3.10
+    singularity run --pid --writable-tmpfs --containall --cleanenv -B$INPUT_DATA_FOLDER:/input_data,$OUTPUT_DATA_FOLDER:/output_data docker://lofarit lofarit/prefactor3_base3.10
 
 These commands will start the container and place you in the /home/lofar directlry inside the container. In both cases you have to set the $INPUT_DATA_FOLDER and $OUTPUT_DATA_FOLDER to the input and output data folders respectively, on the host system (i.e. the machine on which you are running the container). Note that the output data folder must exists and have write permissions (if using Singularty, by the user running the container).
 
diff --git a/base/Dockerfile b/base/Dockerfile
new file mode 100644
index 0000000..d12eed7
--- /dev/null
+++ b/base/Dockerfile
@@ -0,0 +1,62 @@
+FROM lofaruser/imaging-pipeline:v3.10
+
+# Set non-interactive
+ENV DEBIAN_FRONTEND noninteractive
+
+# Always update when extending base images
+RUN apt update
+
+
+#------------------------
+# Install deps
+#------------------------
+
+# Git, Curl, sudo and  Nano
+RUN apt-get install git curl sudo nano -y
+
+
+#------------------------
+# Lofar user
+#------------------------
+
+# Add group. We chose GID 65527 to try avoiding conflicts.
+RUN groupadd -g 65527 lofar
+
+# Add user. We chose UID 65527 to try avoiding conflicts.
+RUN useradd lofar -d /home/lofar -u 65527 -g 65527 -m -s /bin/bash
+
+# Add metuaser user to sudoers
+RUN adduser lofar sudo
+
+# No pass sudo (for everyone, actually)
+COPY sudoers /etc/sudoers
+
+# Setup home and input/output data directories
+COPY data/input_data /input_data
+COPY data/output_data /output_data
+RUN chown lofar:lofar /home/lofar && chown -R lofar:lofar /input_data && chown -R lofar:lofar /output_data
+
+# This is required mainly for Singularity
+RUN mv /home/lofar /home/vanilla_lofar
+RUN ln -s /tmp/lofarhome /home/lofar
+RUN rm -rf /tmp/lofarhome
+
+
+#----------------------
+# Entrypoint
+#----------------------
+
+# Copy entrypoint
+COPY entrypoint.sh /
+
+# Give right permissions
+RUN chmod 755 /entrypoint.sh
+
+# Set entrypoint
+ENTRYPOINT ["/entrypoint.sh"]
+
+# Set user lofar
+USER lofar
+
+# Set container name
+ENV CONTAINER_NAME='base3.10'
diff --git a/base/build_docker_container.sh b/base/build_docker_container.sh
new file mode 100755
index 0000000..6e6d27d
--- /dev/null
+++ b/base/build_docker_container.sh
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+docker build  . -t lofarit/base3.10
diff --git a/prefactor3/data/input_data/README.md b/base/data/input_data/README.md
similarity index 100%
rename from prefactor3/data/input_data/README.md
rename to base/data/input_data/README.md
diff --git a/prefactor3/data/output_data/README.md b/base/data/output_data/README.md
similarity index 100%
rename from prefactor3/data/output_data/README.md
rename to base/data/output_data/README.md
diff --git a/prefactor3/entrypoint.sh b/base/entrypoint.sh
similarity index 80%
rename from prefactor3/entrypoint.sh
rename to base/entrypoint.sh
index 2f9574e..2533c56 100644
--- a/prefactor3/entrypoint.sh
+++ b/base/entrypoint.sh
@@ -14,14 +14,14 @@ echo "[INFO] Creating /tmp/lofarhome to be used as lofar home"
 mkdir /tmp/lofarhome
 
 echo "[INFO] Initialising /tmp/lofarhome with configuration files"
-cp -a /home/vanilla_lofar/* /tmp/lofarhome
+cp -aT /home/vanilla_lofar /tmp/lofarhome
 
 echo "[INFO] Moving to /home/lofar and setting as home"
 cd /home/lofar
 export HOME=/home/lofar
 
-echo "[INFO] Setting new prompt @prefactor3 container"
-echo 'export PS1="${debian_chroot:+($debian_chroot)}\u@prefactor3@\h:\w\$ "' > /tmp/lofarhome/.bashrc
+echo "[INFO] Setting new prompt @$CONTAINER_NAME container"
+echo 'export PS1="${debian_chroot:+($debian_chroot)}\u@$CONTAINER_NAME@\h:\w\$ "' >> /tmp/lofarhome/.bashrc
 
 # Set entrypoint command
 if [ "x$@" == "x" ]; then
@@ -37,7 +37,9 @@ echo -n "[INFO] Will execute entrypoint command: "
 echo $COMMAND
 echo ""
 echo "=============================================================="
-echo "|             Welcome to the Prefactor3 container!           |"
+echo ""
+echo "      Welcome to the LOFAR-IT $CONTAINER_NAME container!"
+echo ""
 echo "=============================================================="
 echo ""
 echo "You are now in /home/lofar with write access as user \"$(whoami)\"."
diff --git a/base/run_docker_container.sh b/base/run_docker_container.sh
new file mode 100755
index 0000000..1d23719
--- /dev/null
+++ b/base/run_docker_container.sh
@@ -0,0 +1,2 @@
+#!/bin/bash
+docker run --rm -v $PWD/data:/data -it lofarit/base3.10 /bin/bash
diff --git a/prefactor3/sudoers b/base/sudoers
similarity index 100%
rename from prefactor3/sudoers
rename to base/sudoers
diff --git a/prefactor3/Dockerfile b/prefactor3/Dockerfile
index 198051e..bfd3999 100644
--- a/prefactor3/Dockerfile
+++ b/prefactor3/Dockerfile
@@ -1,70 +1,16 @@
-FROM lofaruser/imaging-pipeline:v3.10
-
-# Set non-interactive
-ENV DEBIAN_FRONTEND noninteractive
-
-# Always update when extending base images
-RUN apt update
-
-
-#------------------------
-# Install deps
-#------------------------
-
-# Git, Curl, sudo and  Nano
-RUN apt-get install git curl sudo nano -y
-
-
-#------------------------
-# Lofar user
-#------------------------
-
-# Add group. We chose GID 65527 to try avoiding conflicts.
-RUN groupadd -g 65527 lofar
-
-# Add user. We chose UID 65527 to try avoiding conflicts.
-RUN useradd lofar -d /home/lofar -u 65527 -g 65527 -m -s /bin/bash
-
-# Add metuaser user to sudoers
-RUN adduser lofar sudo
-
-# No pass sudo (for everyone, actually)
-COPY sudoers /etc/sudoers
-
+FROM lofarit/base3.10
 
 #------------------------
 # Get prefactor
 #------------------------
-
+USER root
 RUN cd /opt && git clone https://github.com/lofar-astron/prefactor
 RUN cd /opt/prefactor && git pull && git checkout d4f18ff # V3.0 tag hash
+USER lofar
 
 # Add conf and run scripts
-COPY pipeline.cfg /home/lofar/pipeline.cfg
-COPY Pre-Facet-Calibrator.parset /home/lofar/Pre-Facet-Calibrator.parset
-COPY Pre-Facet-Target.parset /home/lofar/Pre-Facet-Target.parset
-COPY data/input_data /input_data
-COPY data/output_data /output_data
-RUN chown lofar:lofar /home/lofar && chown -R lofar:lofar /input_data && chown -R lofar:lofar /output_data
-
-# This is required mainly for Singularity
-RUN mv /home/lofar /home/vanilla_lofar
-RUN ln -s /tmp/lofarhome /home/lofar
-RUN rm -rf /tmp/lofarhome
+COPY pipeline.cfg /home/vanilla_lofar/pipeline.cfg
+COPY Pre-Facet-Calibrator.parset /home/vanilla_lofar/Pre-Facet-Calibrator.parset
+COPY Pre-Facet-Target.parset /home/vanilla_lofar/Pre-Facet-Target.parset
 
-
-#----------------------
-# Entrypoint
-#----------------------
-
-# Copy entrypoint
-COPY entrypoint.sh /
-
-# Give right permissions
-RUN chmod 755 /entrypoint.sh
-
-# Set entrypoint
-ENTRYPOINT ["/entrypoint.sh"]
-
-# Set user lofar
-USER lofar
+ENV CONTAINER_NAME='prefactor3_base3.10'
diff --git a/prefactor3/build_docker_container.sh b/prefactor3/build_docker_container.sh
index d0e790a..b32f5b1 100755
--- a/prefactor3/build_docker_container.sh
+++ b/prefactor3/build_docker_container.sh
@@ -1,3 +1,3 @@
 #!/bin/bash
 
-docker build  . -t lofarit/prefactor3:pipeline_v3.10
+docker build  . -t lofarit/prefactor3_base3.10
diff --git a/prefactor3/run_docker_container.sh b/prefactor3/run_docker_container.sh
index 0bbbc6c..3a01235 100755
--- a/prefactor3/run_docker_container.sh
+++ b/prefactor3/run_docker_container.sh
@@ -1,2 +1,2 @@
 #!/bin/bash
-docker run --rm -v $PWD/data:/data -it lofarit/prefactor3:pipeline_v3.10 /bin/bash
+docker run --rm -v $PWD/data:/data -it lofarit/prefactor3_base3.10 /bin/bash
diff --git a/prefactor3/run_singularity_container.sh b/prefactor3/run_singularity_container.sh
index 97d698e..2e405d5 100755
--- a/prefactor3/run_singularity_container.sh
+++ b/prefactor3/run_singularity_container.sh
@@ -1,2 +1,2 @@
 #!/bin/bash
-singularity run --pid --writable-tmpfs --containall --cleanenv -Bdata/lofar/input_data:/data/lofar/input_data,data/lofar/output_data:/data/lofar/output_data docker://lofarit/prefactor3
\ No newline at end of file
+singularity run --pid --writable-tmpfs --containall --cleanenv -Bdata/lofar/input_data:/data/lofar/input_data,data/lofar/output_data:/data/lofar/output_data docker://lofarit/prefactor3_base3.10
\ No newline at end of file
-- 
GitLab