From 9205c55c1acbb4fb180594b14e50ef20dca9b0db Mon Sep 17 00:00:00 2001 From: Gergely Csatari Date: Wed, 8 Sep 2021 11:53:02 +0300 Subject: [PATCH] Docker build and run environemnt for c2m - 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 Change-Id: Icea55512658bbb8a78934f2a5b4313345927e7b7 --- tools/Dockerfile | 24 ++++++++++++++++++++++++ tools/build-c2m.sh | 30 ++++++++++++++++++++++++++++++ tools/c2m-wrapper.sh | 15 +++++++++++++++ tools/c2m.sh | 21 +++++++++++++-------- tools/example.pagelist | 11 +---------- tools/run-c2m.sh | 34 ++++++++++++++++++++++++++++++++++ 6 files changed, 117 insertions(+), 18 deletions(-) create mode 100644 tools/Dockerfile create mode 100755 tools/build-c2m.sh create mode 100755 tools/c2m-wrapper.sh create mode 100755 tools/run-c2m.sh diff --git a/tools/Dockerfile b/tools/Dockerfile new file mode 100644 index 000000000..e364a74d1 --- /dev/null +++ b/tools/Dockerfile @@ -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 index 000000000..b5ad40fb8 --- /dev/null +++ b/tools/build-c2m.sh @@ -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 index 000000000..8bfbbf97b --- /dev/null +++ b/tools/c2m-wrapper.sh @@ -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 diff --git a/tools/c2m.sh b/tools/c2m.sh index 371b348c5..cf0b2d1f2 100755 --- a/tools/c2m.sh +++ b/tools/c2m.sh @@ -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 } ### diff --git a/tools/example.pagelist b/tools/example.pagelist index fad01e525..d845fdd97 100644 --- a/tools/example.pagelist +++ b/tools/example.pagelist @@ -10,16 +10,7 @@ # # 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 index 000000000..fe1003722 --- /dev/null +++ b/tools/run-c2m.sh @@ -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 -- 2.16.6