[SDFAB-543] Add instruction and scripts of Docker environment

Change-Id: Ied8362240b2515985179d0d257652f8212a9bcfa
diff --git a/TestON/docker/.gitignore b/TestON/docker/.gitignore
new file mode 100644
index 0000000..ddbd53f
--- /dev/null
+++ b/TestON/docker/.gitignore
@@ -0,0 +1,3 @@
+fs/home/jenkins/*
+fs/usr/local
+fs/tmp
diff --git a/TestON/docker/Dockerfile b/TestON/docker/Dockerfile
new file mode 100644
index 0000000..686d4fa
--- /dev/null
+++ b/TestON/docker/Dockerfile
@@ -0,0 +1,33 @@
+# SPDX-FileCopyrightText: Copyright 2021-present Open Networking Foundation.
+# SPDX-License-Identifier: Apache-2.0
+FROM ubuntu:18.04
+
+ARG KUBECTL=v1.22.1
+ENV PACKAGES \
+    python \
+    python-pip \
+    ssh \
+    openssh-server \
+    curl \
+    supervisor
+ADD requirements.txt /
+
+RUN apt update && \
+    apt install --no-install-recommends -y $PACKAGES && \
+    curl -L "https://dl.k8s.io/release/$KUBECTL/bin/linux/amd64/kubectl" -o /usr/local/bin/kubectl && \
+    chmod 0755 /usr/local/bin/kubectl && \
+    python -m pip install setuptools && \
+    python -m pip install -r requirements.txt && \
+    mkdir -p /var/run/sshd && \
+    mkdir -p /var/log/supervisor && \
+    useradd -m jenkins && \
+    chsh -s /bin/bash jenkins && \
+    echo jenkins:jenkins | chpasswd
+
+ADD docker/fs /
+RUN chown -R jenkins.jenkins /home/jenkins && \
+    python -m pip install -r /tmp/additional-py-pkgs.txt
+
+CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"]
+
+EXPOSE 22
diff --git a/TestON/docker/build.sh b/TestON/docker/build.sh
new file mode 100755
index 0000000..e9a968d
--- /dev/null
+++ b/TestON/docker/build.sh
@@ -0,0 +1,36 @@
+#!/bin/bash
+# SPDX-FileCopyrightText: Copyright 2021-present Open Networking Foundation.
+# SPDX-License-Identifier: Apache-2.0
+# Usage:
+# ./build.sh [--wk] [--di]
+#
+# Options:
+# --wk: with user's SSH key.
+# --di: with DeepInsight utility library(from a private repo)
+
+set -euo pipefail
+
+THIS_DIR="$(cd $(dirname ${BASH_SOURCE[0]}) && pwd)"
+TEST_ON_DIR="$(cd ${THIS_DIR}/.. && pwd)"
+CONTAINER_FS="${THIS_DIR}/fs"
+DI_UTIL_REPO="git@github.com:opennetworkinglab/bf-di-scripts.git"
+
+mkdir -p "${CONTAINER_FS}/tmp"
+rm -rf "${CONTAINER_FS}/tmp/additional-py-pkgs.txt"
+touch "${CONTAINER_FS}/tmp/additional-py-pkgs.txt"
+
+for op in $@; do
+    case $op in
+        '--wk' )
+            rm -rf "${CONTAINER_FS}/home/jenkins/.ssh"
+            cp -r "${HOME}/.ssh" "${CONTAINER_FS}/home/jenkins/.ssh"
+        ;;
+        '--di' )
+            rm -rf "${CONTAINER_FS}/tmp/bf-di-scripts"
+            git clone "${DI_UTIL_REPO}" "${CONTAINER_FS}/tmp/bf-di-scripts"
+            echo "/tmp/bf-di-scripts/4/utility" > "${CONTAINER_FS}/tmp/additional-py-pkgs.txt"
+        ;;
+    esac
+done
+
+docker build -t teston -f "${THIS_DIR}/Dockerfile" "${TEST_ON_DIR}"
diff --git a/TestON/docker/fs/etc/supervisor/supervisord.conf b/TestON/docker/fs/etc/supervisor/supervisord.conf
new file mode 100644
index 0000000..eb23757
--- /dev/null
+++ b/TestON/docker/fs/etc/supervisor/supervisord.conf
@@ -0,0 +1,5 @@
+[supervisord]
+nodaemon=true
+
+[program:sshd]
+command=/usr/sbin/sshd -D
diff --git a/TestON/docker/fs/home/jenkins/.gitkeep b/TestON/docker/fs/home/jenkins/.gitkeep
new file mode 100644
index 0000000..574a722
--- /dev/null
+++ b/TestON/docker/fs/home/jenkins/.gitkeep
@@ -0,0 +1 @@
+Place user-specific files(e.g., Kubernetes config) here.
diff --git a/TestON/docker/start.sh b/TestON/docker/start.sh
new file mode 100755
index 0000000..fd7860f
--- /dev/null
+++ b/TestON/docker/start.sh
@@ -0,0 +1,24 @@
+#!/bin/bash
+# SPDX-FileCopyrightText: Copyright 2021-present Open Networking Foundation.
+# SPDX-License-Identifier: Apache-2.0
+set -euo pipefail
+SSH_PORT=${SSH_PORT:-2222}
+THIS_DIR="$(cd $(dirname ${BASH_SOURCE[0]}) && pwd)"
+TEST_ON_DIR="$(cd ${THIS_DIR}/.. && pwd)"
+
+function cleanup() {
+    echo "Stopping TestON container"
+    docker stop teston
+}
+trap cleanup EXIT
+
+echo "Starting TestON container..."
+
+docker run -d --rm --init --name teston \
+           -p $SSH_PORT:22 \
+           -v $TEST_ON_DIR:/home/jenkins/teston \
+           teston
+
+echo "SSH server listen on $SSH_PORT"
+echo "Attaching to the container..."
+docker exec -it -u jenkins teston bash -c "cd /home/jenkins && bash"