Docker build and run environemnt for c2m 46/123946/5
authorGergely Csatari <gergely.csatari@nokia.com>
Wed, 8 Sep 2021 08:53:02 +0000 (11:53 +0300)
committerEric Debeau <eric.debeau@orange.com>
Fri, 24 Sep 2021 20:04:24 +0000 (20:04 +0000)
- Dockerfile to build a container for c2m
- A script to build the container
- A script to run the container
- A wrapper script to run c2m in the container

Issue-ID: DOC-762

Signed-off-by: Gergely Csatari <gergely.csatari@nokia.com>
Change-Id: Icea55512658bbb8a78934f2a5b4313345927e7b7

tools/Dockerfile [new file with mode: 0644]
tools/build-c2m.sh [new file with mode: 0755]
tools/c2m-wrapper.sh [new file with mode: 0755]
tools/c2m.sh
tools/example.pagelist
tools/run-c2m.sh [new file with mode: 0755]

diff --git a/tools/Dockerfile b/tools/Dockerfile
new file mode 100644 (file)
index 0000000..e364a74
--- /dev/null
@@ -0,0 +1,24 @@
+# Copyright 2021 Nokia
+# Licensed under the Apache License 2.0
+# SPDX-License-Identifier: Apache-2.0
+
+ARG build_env="no_proxy"
+
+#FROM openjdk:17-slim-bullseye as build_no_proxy
+FROM openjdk:8-jdk-slim as build_no_proxy
+ONBUILD RUN echo "I don't copy proxy settings"
+
+FROM openjdk:8-jdk-slim as build_proxy
+ONBUILD COPY proxy.conf /etc/apt/apt.conf.d/proxy.conf
+
+################ Add all non proxy dependent stuff here
+FROM build_${build_env}
+ARG DEBIAN_FRONTEND=noninteractive
+COPY c2m.sh ./c2m.sh
+COPY c2m-wrapper.sh ./c2m-wrapper.sh
+
+# Install wget
+RUN apt-get update && apt-get -y install apt-utils
+RUN apt-get -y install wget pandoc
+
+RUN wget -q https://repo1.maven.org/maven2/de/viaboxx/markdown/confluence2md/2.1/confluence2md-2.1-fat.jar
diff --git a/tools/build-c2m.sh b/tools/build-c2m.sh
new file mode 100755 (executable)
index 0000000..b5ad40f
--- /dev/null
@@ -0,0 +1,30 @@
+#!/bin/bash
+
+# Copyright 2021 Nokia
+# Licensed under the Apache License 2.0
+# SPDX-License-Identifier: Apache-2.0
+
+# Build script to create c2m container.
+
+set -x
+
+build_env="no_proxy"
+proxy=""
+if [[ -z "${http_proxy}" ]]; then
+    echo "http_proxy is empty"
+else
+    echo "http_proxy is set to $http_proxy"
+    build_env="proxy"
+    if [[ $http_proxy =~ ^http:\/\/[0-9] ]]; then
+        echo "starts with http"
+        proxy=$http_proxy
+    elif [[ $http_proxy =~ ^[0-9] ]]; then
+        echo "starts with number"
+        proxy=http://$http_proxy
+    fi
+    echo "Acquire::http::Proxy \"${proxy}\";" > proxy.conf
+fi
+
+echo "Proxy set to $proxy, build env is $build_env."
+
+docker build --no-cache --build-arg http_proxy=$proxy --build-arg https_proxy=$proxy --build-arg build_env=$build_env -t c2m:latest -t c2m:`git log -1 --format=%h` . || echo "Build failed."
diff --git a/tools/c2m-wrapper.sh b/tools/c2m-wrapper.sh
new file mode 100755 (executable)
index 0000000..8bfbbf9
--- /dev/null
@@ -0,0 +1,15 @@
+#!/bin/bash
+#
+# Copyright 2021 Nokia
+# Licensed under the Apache License 2.0
+# SPDX-License-Identifier: Apache-2.0
+set -x
+echo "c2m-wrapper -------------------------------------------------------------"
+
+rst_editor="ls " ./c2m.sh $1
+
+out_dir="/mount/output"
+[ ! -d $out_dir ] && mkdir $out_dir
+[ -d $out_dir ] && rm -rf $out_dir/*
+
+mv -f -v output/* $out_dir
\ No newline at end of file
index 371b348..cf0b2d1 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/bash
 
-#set -x # uncomment for bash script debugging
-
+set -x # uncomment for bash script debugging
+echo "c2m -------------------------------------------------------------"
 ### ============================================================================
 ### Licensed under the Apache License, Version 2.0 (the "License");
 ### you may not use this file except in compliance with the License.
@@ -122,7 +122,7 @@ user="${CONFLUENCE_USERNAME}";
 passwd="${CONFLUENCE_PASSWORD}";
 credentials="${user}":"${passwd}";
 server="https://wiki.onap.org";
-rst_editor="retext --preview";
+[ -z "$rst_editor" ] && rst_editor="retext --preview";
 
 # remove credentials for those using anonymous access
 test "${credentials}" = "*****:*****" && credentials=""
@@ -169,10 +169,13 @@ fi
 
 function create_working_dir {
 
+  base_dir="output"
+  [ ! -d $base_dir ] && mkdir $base_dir
+
   # compose name for working directory
   #working_dir="${page_id}-${page_title}";
   #working_dir="${page_title}-id${page_id}";
-  working_dir="${page_title}";
+  working_dir="${base_dir}/${page_title}";
   echo "INFO ***************************************************************************"
   echo "INFO working directory \"$working_dir\" will be created"
 
@@ -225,19 +228,21 @@ function pull_pages_from_wiki {
     proxy_to_parse="${https_proxy/https:\/\//""}";
     echo "https_proxy is set to \"${proxy_to_parse}\"";
   fi
-
+  
+  #java_options="--add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED --add-opens java.base/java.lang.annotation=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.net=ALL-UNNAMED"
+  
   if [[ $proxy_to_parse =~ ^([\.0-9]+) ]]; then
-    java_options=" -Dhttp.proxyHost=${BASH_REMATCH[1]}"
+    java_options="${java_options} -Dhttps.proxyHost=${BASH_REMATCH[1]} -Dhttp.proxyHost=${BASH_REMATCH[1]}"
     echo "${java_options}"
   fi
   if [[ $proxy_to_parse =~ .*:([0-9]+) ]]; then
-    java_options="${java_options} -Dhttps.proxyPort=${BASH_REMATCH[1]}"
+    java_options="${java_options} -Dhttps.proxyPort=${BASH_REMATCH[1]} -Dhttp.proxyPort=${BASH_REMATCH[1]}"
     echo "${java_options}"
   fi
 
   # TODO: -depth
   # pull pages from wiki and convert to markdown (as a source for conversion by pandoc)
-  java $java_options -jar "${basedir}"/confluence2md-2.1-fat.jar +H true +T false +RootPageTitle false +FootNotes true -maxHeaderDepth 7 -depth $depth -v true -o ${out_file}.md -u "${credentials}" -server $server $page_id
+  java $java_options -jar $basedir/confluence2md-2.1-fat.jar +H true +T false +RootPageTitle false +FootNotes true -maxHeaderDepth 7 -depth $depth -v true -o ${out_file}.md -u "${credentials}" -server $server $page_id
 }
 
 ###
index fad01e5..d845fdd 100644 (file)
 #
 # hierarchy | page_id  | page_title                      | depth
 #
-0           |  1018748 | ONAP Portal                     |  0
-1.1         |  1018759 | ONAP Portal for users           |  0
-1.2         |  1018762 | ONAP Portal for administrators  |  0
-1.2.1       |  1018764 | Admins                          |  0
-1.2.2       |  1018811 | Users                           |  0
-1.2.3       |  1018821 | Portal Admins                   |  0
-1.2.4       |  1018826 | Application Onboarding          |  0
-1.2.5       |  1018832 | Widget Onboarding               |  0
-1.2.6       |  1018835 | Edit Functional Menu            |  0
-1.2.7       | 16004953 | Portal Microservices Onboarding |  0
+0           |  107250975 | ZZZ Copy of ARC AAI Component Description - Istanbul-R9  |  0
 #
 # in case you want to export to only one single output page (that contains all child-pages of the above example) use:
 #
diff --git a/tools/run-c2m.sh b/tools/run-c2m.sh
new file mode 100755 (executable)
index 0000000..fe10037
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/bash
+#
+# Copyright 2021 Nokia
+# Licensed under the Apache License 2.0
+# SPDX-License-Identifier: Apache-2.0
+
+set -x
+echo "run-c2m -------------------------------------------------------------"
+if [[ -z "$CONFLUENCE_USERNAME" || -z "$CONFLUENCE_PASSWORD" ]]
+then
+    echo "Mandatory environment variables:"
+    echo "  CONFLUENCE_USERNAME: Confluence username"
+    echo "  CONFLUENCE_PASSWORD: Confluence password."
+    echo "Be aware! Setting bash debuging on will print credentials."
+    exit
+fi
+
+proxy=""
+if [[ -z "${http_proxy}" ]]; then
+    echo "http_proxy is empty"
+else
+    echo "http_proxy is set to $http_proxy"
+    if [[ $http_proxy =~ ^http:\/\/[0-9] ]]; then
+        echo "starts with http"
+        proxy=$http_proxy
+    elif [[ $http_proxy =~ ^[0-9] ]]; then
+        echo "starts with number"
+        proxy=http://$http_proxy
+    fi
+fi
+
+echo "Proxy set to $proxy, build env is $build_env."
+
+docker run -e http_proxy=$proxy -e https_proxy=$proxy -e HTTP_PROXY=$proxy -e HTTPS_PROXY=$proxy -e CONFLUENCE_PASSWORD=$CONFLUENCE_PASSWORD -e CONFLUENCE_USERNAME=$CONFLUENCE_USERNAME -v $PWD:/mount c2m:latest ./c2m-wrapper.sh /mount/$1
\ No newline at end of file