From 6a3eb5e8d595cfc6de82c044044bcdc0602e4ca9 Mon Sep 17 00:00:00 2001
From: David Schmitz <schmitz@lrz.de>
Date: Tue, 23 May 2023 14:09:28 +0000
Subject: [PATCH] feature/exabgp_with_docker-compose2: try to exploit docker
 build cache by splitting install-debian:sh run in 3 phases; use decouple venv
 dir from main FOD dir (avoid mixing python bin/lib stuff within container
 with python bin/libs outside)

---
 docker-compose/Dockerfile_FOD                 | 16 ++++++++++++++--
 docker-compose/fod_setup_environment-step3.sh | 12 ++++++++++++
 docker-compose/fod_setup_environment.sh       |  3 ++-
 3 files changed, 28 insertions(+), 3 deletions(-)
 create mode 100755 docker-compose/fod_setup_environment-step3.sh

diff --git a/docker-compose/Dockerfile_FOD b/docker-compose/Dockerfile_FOD
index bb1b9208..3dd455bd 100644
--- a/docker-compose/Dockerfile_FOD
+++ b/docker-compose/Dockerfile_FOD
@@ -6,11 +6,23 @@ RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
     dpkg-reconfigure --frontend=noninteractive locales && \
     update-locale LANG=en_US.UTF-8
 ENV LANG en_US.UTF-8
-COPY docker-compose/fod_setup_environment.sh /opt/setup_environment.sh
-RUN mkdir -p /var/run/supervisor
 RUN apt-get update -y && apt-get -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' --assume-yes -fuy dist-upgrade
 RUN apt-get install -y git less man make gcc strace ltrace lsof file vim tshark tcpdump curl wget net-tools sudo psutils procps iptables iputils-ping iputils-tracepath hping3 iproute2 supervisor
 RUN useradd exabgp
+RUN mkdir -p /var/run/supervisor /opt/FOD
 WORKDIR /opt/FOD
 EXPOSE 8000
+
+# build step1 (exploit docker build cache, only redone if ./install-debian.sh changed)
+COPY install-debian.sh /opt/FOD
+RUN ./install-debian.sh --basesw_os --here__with_venv_relative --supervisord 
+
+# build step2 (exploit docker build cache, only redone if ./install-debian.sh or requirements.txt changed)
+COPY requirements.txt /opt/FOD
+RUN ./install-debian.sh --basesw_python --here__with_venv_relative --supervisord 
+
+# build step3 will be done in first CMD / run
+#COPY docker-compose/fod_setup_environment.sh /opt/setup_environment.sh # includes tryinfo to redo step 1 + step 2 again (at least ensure everything is really up-to-date)
+#COPY docker-compose/fod_setup_environment.sh /opt/setup_environment.sh # only to the least minimal adaptions necessary in the bind-mounted FOD dir are performed
+COPY docker-compose/fod_setup_environment-step3.sh /opt/setup_environment.sh
 CMD /opt/setup_environment.sh && supervisord -c docker-compose/fod_supervisord.conf
diff --git a/docker-compose/fod_setup_environment-step3.sh b/docker-compose/fod_setup_environment-step3.sh
new file mode 100755
index 00000000..39faa11a
--- /dev/null
+++ b/docker-compose/fod_setup_environment-step3.sh
@@ -0,0 +1,12 @@
+#!/bin/bash
+set -e
+if [ -e /opt/setup_ok ]; then
+	exit 0
+else
+	cd /opt/FOD
+	#./install-debian.sh --here --supervisord --setup_admin_user --setup_admin_user5 admin ${ADMIN_PASS} ${ADMIN_EMAIL} ${FOD_ORG} ${FOD_ORG_NET} --exabgp ${FOD_EXABGP_LOCAL_ID} ${FOD_EXABGP_LOCAL_IP} ${FOD_EXABGP_LOCAL_AS} ${FOD_EXABGP_REMOTE_ID} ${FOD_EXABGP_REMOTE_IP} ${FOD_EXABGP_REMOTE_AS}
+	#./install-debian.sh --here__with_venv_relative --supervisord --setup_admin_user --setup_admin_user5 admin ${ADMIN_PASS} ${ADMIN_EMAIL} ${FOD_ORG} ${FOD_ORG_NET} --exabgp ${FOD_EXABGP_LOCAL_ID} ${FOD_EXABGP_LOCAL_IP} ${FOD_EXABGP_LOCAL_AS} ${FOD_EXABGP_REMOTE_ID} ${FOD_EXABGP_REMOTE_IP} ${FOD_EXABGP_REMOTE_AS}
+	./install-debian.sh --fodproper1 --here__with_venv_relative --supervisord --setup_admin_user --setup_admin_user5 admin ${ADMIN_PASS} ${ADMIN_EMAIL} ${FOD_ORG} ${FOD_ORG_NET} --exabgp ${FOD_EXABGP_LOCAL_ID} ${FOD_EXABGP_LOCAL_IP} ${FOD_EXABGP_LOCAL_AS} ${FOD_EXABGP_REMOTE_ID} ${FOD_EXABGP_REMOTE_IP} ${FOD_EXABGP_REMOTE_AS}
+	/opt/FOD/venv/bin/python -m pip install exabgp
+	touch /opt/setup_ok
+fi
diff --git a/docker-compose/fod_setup_environment.sh b/docker-compose/fod_setup_environment.sh
index 72502758..6eecbf4f 100755
--- a/docker-compose/fod_setup_environment.sh
+++ b/docker-compose/fod_setup_environment.sh
@@ -4,7 +4,8 @@ if [ -e /opt/setup_ok ]; then
 	exit 0
 else
 	cd /opt/FOD
-	./install-debian.sh --here --supervisord --setup_admin_user --setup_admin_user5 admin ${ADMIN_PASS} ${ADMIN_EMAIL} ${FOD_ORG} ${FOD_ORG_NET} --exabgp ${FOD_EXABGP_LOCAL_ID} ${FOD_EXABGP_LOCAL_IP} ${FOD_EXABGP_LOCAL_AS} ${FOD_EXABGP_REMOTE_ID} ${FOD_EXABGP_REMOTE_IP} ${FOD_EXABGP_REMOTE_AS}
+	#./install-debian.sh --here --supervisord --setup_admin_user --setup_admin_user5 admin ${ADMIN_PASS} ${ADMIN_EMAIL} ${FOD_ORG} ${FOD_ORG_NET} --exabgp ${FOD_EXABGP_LOCAL_ID} ${FOD_EXABGP_LOCAL_IP} ${FOD_EXABGP_LOCAL_AS} ${FOD_EXABGP_REMOTE_ID} ${FOD_EXABGP_REMOTE_IP} ${FOD_EXABGP_REMOTE_AS}
+	./install-debian.sh --here__with_venv_relative --supervisord --setup_admin_user --setup_admin_user5 admin ${ADMIN_PASS} ${ADMIN_EMAIL} ${FOD_ORG} ${FOD_ORG_NET} --exabgp ${FOD_EXABGP_LOCAL_ID} ${FOD_EXABGP_LOCAL_IP} ${FOD_EXABGP_LOCAL_AS} ${FOD_EXABGP_REMOTE_ID} ${FOD_EXABGP_REMOTE_IP} ${FOD_EXABGP_REMOTE_AS}
 	/opt/FOD/venv/bin/python -m pip install exabgp
 	touch /opt/setup_ok
 fi
-- 
GitLab