Upgrade Docker image generation process to use new Java11 simulators.
Both OpenROADM versions 1.2.1 and 2.2.1 simulators are now using a
same docker image and the same scripts.
This brings the following improvements:
- create a multi-stage docker file to isolate build and run processes
- decrease image size
- use an applicative user in Dockerfile rather than root
- add healthcheck
- expose both netconf and restconf ports
- use the docker option --name to set the name of the container
- rootless container and sudo management for docker command
- centralize most scripts parameters in dockercmd_profile.sh
JIRA: TRNSPRTPCE-239
Signed-off-by: Christophe Betoule <christophe.betoule@orange.com>
Co-authored-by: Emmanuelle Delfour <emmanuelle.delfour@orange.com>
Co-authored-by: Guillaume Lambert <guillaume.lambert@orange.com>
Change-Id: I86b47cac0f795c2ac9d1615efa703d8ca87b34e5
--- /dev/null
+FROM maven:3.6.3-jdk-11-slim AS builder
+ARG GIT_REF=master
+RUN apt-get update \
+ && apt-get -f -m install -y git \
+ && rm -rf /var/lib/apt/lists/* \
+ && mkdir /tmp/git_repo \
+ && git clone -b "$GIT_REF" https://git.opendaylight.org/gerrit/transportpce /tmp/git_repo \
+ && cd /tmp/git_repo/tests \
+ && ./buildHoneynode.sh \
+ && ./buildHoneynode.sh 2.2.1 \
+ && mkdir -p /tmp/honeynode/honeynode_1.2.1/config \
+ && mkdir -p /tmp/honeynode/honeynode_2.2.1/config \
+ && mv /tmp/git_repo/tests/honeynode/1.2.1/honeynode-distribution/target/honeynode-distribution-1.19.04-hc/honeynode-distribution-1.19.04/* /tmp/honeynode/honeynode_1.2.1/. \
+ && mv /tmp/git_repo/tests/honeynode/2.2.1/honeynode-distribution/target/honeynode-distribution-1.19.04-hc/honeynode-distribution-1.19.04/* /tmp/honeynode/honeynode_2.2.1/. \
+ && cp /tmp/git_repo/tests/sample_configs/openroadm/1.2.1/* /tmp/honeynode/honeynode_1.2.1/config/. \
+ && cp /tmp/git_repo/tests/sample_configs/openroadm/2.2.1/* /tmp/honeynode/honeynode_2.2.1/config/.
+
+
+
+
+FROM adoptopenjdk/openjdk11:alpine-jre
+LABEL Name="OpenROADM compliant ROADM and XPDR NETCONF simulators"
+LABEL Description="Simulators for Openroadm devices based on honeycomb project"
+LABEL Maintainer="transportpce-dev@lists.opendaylight.org"
+LABEL Url="https://git.opendaylight.org/gerrit/transportpce"
+
+ENV DEVICE_VERSION=1.2.1
+ENV DEVICE_FILE=oper-ROADMA-full.xml
+RUN addgroup gsimulator && adduser -D usimulator -G gsimulator -u 100001\
+ && mkdir -p /opt/application/simulators
+COPY --chown=usimulator:gsimulator --from=builder /tmp/honeynode/ /opt/application/simulators/honeynode
+COPY --chown=usimulator:gsimulator --from=builder /tmp/git_repo/tests/sample_configs/openroadm/ /opt/application/simulators/honeynode/config
+RUN find /opt/application/simulators -name "honeycomb-tpce" -exec sed -i "/reflectwarn.sh/d" {} +
+USER usimulator
+WORKDIR /opt/application/simulators/honeynode
+HEALTHCHECK CMD wget --header "Authorization: Basic `echo -n "${USER}:${PASSWORD}" | base64`" http://localhost:8130/restconf/ -S -O -
+EXPOSE 1830/tcp 8130/tcp
+CMD /opt/application/simulators/honeynode/honeynode_$DEVICE_VERSION/honeycomb-tpce 1830 /opt/application/simulators/honeynode/config/$DEVICE_VERSION/$DEVICE_FILE
+++ /dev/null
-FROM openjdk:8-jdk-alpine
-
-RUN apk add --update --no-cache bash procps maven git \
- && mkdir /opt/sims \
- && cd /root \
- && git clone -b master https://git.opendaylight.org/gerrit/transportpce \
- && cd transportpce/tests \
- && ./buildHoneynode.sh \
- && mv honeynode/2.1 /opt/sims/honeynode \
- && echo -e '#/bin/sh\n\ncd /opt/sims\n./honeynode/honeynode-distribution/target/honeynode-distribution-1.18.01-hc/honeynode-distribution-1.18.01/honeycomb-tpce $@\n'>/usr/bin/honeynode \
- && chmod +x /usr/bin/honeynode \
- && mv sample_configs/ /opt/sims/ \
- && cd ../.. \
- && rm -rf transportpce/ .m2/ \
- && apk del git maven
-
-#CMD honeynode 830 sample_configs/openroadm/2.1/oper-ROADMA.xml
+++ /dev/null
-FROM openjdk:8-jdk-alpine
-
-RUN apk add --update --no-cache bash procps maven git \
- && mkdir /opt/sims \
- && cd /root \
- && git clone -b master https://git.opendaylight.org/gerrit/transportpce \
- && cd transportpce/tests \
- && ./buildHoneynode.sh 2.2.1\
- && mv honeynode/2.2.1 /opt/sims/honeynode \
- && echo -e '#/bin/sh\n\ncd /opt/sims\n./honeynode/honeynode-distribution/target/honeynode-distribution-1.18.01-hc/honeynode-distribution-1.18.01/honeycomb-tpce $@\n'>/usr/bin/honeynode \
- && chmod +x /usr/bin/honeynode \
- && mv sample_configs/ /opt/sims/ \
- && cd ../.. \
- && rm -rf transportpce/ .m2/ \
- && apk del git maven
-
-#CMD honeynode 830 sample_configs/openroadm/2.2.1/oper-ROADMA.xml
--- /dev/null
+#!/bin/sh
+
+. $(dirname $0)/dockercmd_profile.sh
+
+set -x
+${DOCKER_CMD} build --no-cache --tag=${DOCKER_IMAGE} .
--- /dev/null
+#!/bin/sh
+
+DEVICE_VERSION=${1:-1.2.1}
+
+# this file centralizes inb one place parameters needed by docker scripts,
+# more especially the image lists for 1.2.1 and 2.2.1 devices.
+# device versions supported as scripts argument are 1.2.1 and 2.2.1 and "all"
+
+#IMAGE_LIST format is suffix_port : container/image name : config file to fill netconf operational datastore
+
+IMAGE121_LIST="30:xpdra-1.2.1:oper-XPDRA.xml
+31:roadma-1.2.1:oper-ROADMA.xml
+32:roadmb-1.2.1:oper-ROADMB.xml
+33:roadmc-1.2.1:oper-ROADMC.xml
+34:xpdrc-1.2.1:oper-XPDRC.xml
+21:roadma-full-1.2.1:oper-ROADMA-full.xml
+23:roadmc-full-1.2.1:oper-ROADMC-full.xml
+"
+
+IMAGE221_LIST="40:xpdra-2.2.1:oper-XPDRA.xml
+41:roadma-2.2.1:oper-ROADMA.xml
+42:roadmb-2.2.1:oper-ROADMB.xml
+43:roadmc-2.2.1:oper-ROADMC.xml
+44:xpdrc-2.2.1:oper-XPDRC.xml
+45:spdrav2-2.2.1:oper-SPDRAv2.xml
+46:spdrav1-2.2.1:oper-SPDRAv1.xml
+"
+
+case "$DEVICE_VERSION" in
+ "1.2.1") IMAGE_LIST=$IMAGE121_LIST
+ ;;
+ "2.2.1") IMAGE_LIST=$IMAGE221_LIST
+ ;;
+ *) echo "unsupported device version"
+ exit 1
+ ;;
+esac
+
+DOCKER_CMD=docker
+DOCKER_IMAGE=honeynode:alpine-jre11
+RESTCONF_USER=admin
+RESTCONF_PASSWORD=admin
+if [ `which podman` ]
+then DOCKER_CMD=podman
+else
+ if [ ! `which $DOCKER_CMD` ]
+ then echo "no docker command available" >&2
+ exit 1
+ fi
+ #if "docker ps" cannot be run without error, prepend sudo
+ if ( ! $DOCKER_CMD ps >/dev/null 2>&1 );then
+ echo "docker command only usable as root, using sudo" >&2
+ DOCKER_CMD="sudo docker"
+ fi
+fi
+
+
+++ /dev/null
-#!/bin/bash
-
-cp Dockerfile.orig.21 Dockerfile
-sudo docker build --tag=alpine_honeynode:2.1 .
-for conf_file in `(cd ../.. && ls sample_configs/openroadm/2.1/)`
-do DOCKNAME=honeynode_`echo $conf_file |cut -d\. -f1 |tr '[:upper:]' '[:lower:]'`
- echo "generating docker image '$DOCKNAME'"
- echo -e "FROM alpine_honeynode:2.1\n\nCMD honeynode 830 sample_configs/openroadm/2.1/$conf_file\n" >Dockerfile
- sudo docker build --tag=$DOCKNAME:2.1 .
-done
+++ /dev/null
-#!/bin/bash
-
-cp Dockerfile.orig.221 Dockerfile
-sudo docker build --tag=alpine_honeynode:2.2.1 .
-for conf_file in `(cd ../.. && ls sample_configs/openroadm/2.2.1/)`
-do DOCKNAME=honeynode_`echo $conf_file |cut -d\. -f1 |tr '[:upper:]' '[:lower:]'`
- echo "generating docker image '$DOCKNAME'"
- echo -e "FROM alpine_honeynode:2.2.1\n\nCMD honeynode 830 sample_configs/openroadm/2.2.1/$conf_file\n" >Dockerfile
- sudo docker build --tag=$DOCKNAME:2.2.1 .
-done
--- /dev/null
+#!/bin/sh
+
+. $(dirname $0)/dockercmd_profile.sh
+
+DOCKER_OPTIONS="-e USER=${RESTCONF_USER} -e PASSWORD=${RESTCONF_PASSWORD} -e DEVICE_VERSION=${DEVICE_VERSION} -dit ${DOCKER_IMAGE}"
+
+for image in $IMAGE_LIST;do
+ suffix_port=`echo -n $image| cut -d: -f1`
+ image_name=`echo -n $image| cut -d: -f2`
+ device_file=`echo -n $image| cut -d: -f3`
+ #echo "$image_name $suffix_port $device_file"
+ if [ ! "$(${DOCKER_CMD} ps -q -f name=${image_name})" ];then
+ if [ "$(${DOCKER_CMD} ps -aq -f status=exited -f name=${image_name})" ];then
+ ${DOCKER_CMD} rm ${image_name}
+ fi
+ elif [ "$(${DOCKER_CMD} ps -q -f status=running -f name=${image_name})" ];then
+ ${DOCKER_CMD} stop ${image_name}
+ fi
+ echo ${image_name}
+ ${DOCKER_CMD} run --rm -p 178$suffix_port:1830 -p 81$suffix_port:8130 --name ${image_name} -e DEVICE_FILE=${device_file} ${DOCKER_OPTIONS}
+done
+
+exit
+
+++ /dev/null
-#!/bin/sh
-
-echo "killing previous sims containers"
-if [ -f kill_sims21.sh ]; then ./kill_sims21.sh; rm sims21.pid kill_sims21.sh; else echo "nothing to do"; fi
-
-echo `sudo docker run -d -p 17830:830 honeynode_oper-xpdra:2.1`>>sims21.pid
-echo `sudo docker run -d -p 17831:830 honeynode_oper-roadma:2.1`>>sims21.pid
-echo `sudo docker run -d -p 17832:830 honeynode_oper-roadmb:2.1`>>sims21.pid
-echo `sudo docker run -d -p 17833:830 honeynode_oper-roadmc:2.1`>>sims21.pid
-echo `sudo docker run -d -p 17834:830 honeynode_oper-xpdrc:2.1`>>sims21.pid
-echo `sudo docker run -d -p 17821:830 honeynode_oper-roadma-full:2.1`>>sims21.pid
-echo `sudo docker run -d -p 17823:830 honeynode_oper-roadmc-full:2.1`>>sims21.pid
-
-echo -n "#!/bin/sh\n\nsudo docker container kill "`cat sims21.pid`" \n" >kill_sims21.sh
-chmod +x kill_sims21.sh
+++ /dev/null
-#!/bin/sh
-
-echo "killing previous sims containers"
-if [ -f kill_sims221.sh ]; then ./kill_sims221.sh; rm sims221.pid kill_sims221.sh; else echo "nothing to do"; fi
-
-echo `sudo docker run -d -p 17840:830 honeynode_oper-xpdra:2.2.1`>>sims221.pid
-echo `sudo docker run -d -p 17841:830 honeynode_oper-roadma:2.2.1`>>sims221.pid
-#echo `sudo docker run -d -p 17842:830 honeynode_oper-roadmb:2.2.1`>>sims221.pid
-echo `sudo docker run -d -p 17843:830 honeynode_oper-roadmc:2.2.1`>>sims221.pid
-echo `sudo docker run -d -p 17844:830 honeynode_oper-xpdrc:2.2.1`>>sims221.pid
-
-echo -n "#!/bin/sh\n\nsudo docker container kill "`cat sims221.pid`" \n" >kill_sims221.sh
-chmod +x kill_sims221.sh
--- /dev/null
+#!/bin/sh
+
+. $(dirname $0)/dockercmd_profile.sh
+
+stop_list=""
+for image in $IMAGE_LIST;do
+ image_name=`echo -n $image| cut -d: -f2`
+ stop_list=$stop_list" "$image_name
+done
+${DOCKER_CMD} container stop ${stop_list}