Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce devfile docs build & deploy script #12646

Merged
merged 28 commits into from
Feb 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion wsmaster/che-core-api-devfile/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
<version>1.4</version>
<executions>
<execution>
<id>test</id>
<id>generate-pojo</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
Expand Down Expand Up @@ -189,6 +189,16 @@
<generateBuilders>true</generateBuilders>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/Dockerfile</exclude>
<exclude>**/*.sh</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
32 changes: 32 additions & 0 deletions wsmaster/che-core-api-devfile/src/main/resources/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#
# Copyright (c) 2012-2018 Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# Red Hat, Inc. - initial API and implementation
#

# This is a Dockerfile allowing to build devfile documentaion by using a docker container.
# Build step: $ docker build -t eclipse-che-devfile-docs
# It builds an archive file that can be used by doing later
# $ docker run --rm eclipse-che-devfile-docs | tar -C target/docs/ -xf -
FROM node:8.10.0

RUN apt-get update && \
apt-get install -y git \
&& apt-get -y clean \
&& rm -rf /var/lib/apt/lists/*
RUN git clone -b '1.1.0' --single-branch [email protected]:adobe/jsonschema2md.git
RUN cd jsonschema2md && npm install && npm link
mshaposhnik marked this conversation as resolved.
Show resolved Hide resolved

COPY ./schema /schema
RUN cd /schema && \
jsonschema2md -d . -e json -n && \
mv ./out/devfile.md ./out/index.md && \
tar zcf /tmp/out.tar.gz -C out .

CMD zcat /tmp/out.tar.gz
135 changes: 135 additions & 0 deletions wsmaster/che-core-api-devfile/src/main/resources/build_docs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#!/bin/bash
#
# Copyright (c) 2012-2018 Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# Red Hat, Inc. - initial API and implementation
#

set -e

TMP_DIR="/tmp/devfile"

if [[ -z "${DEVFILE_DOCS_GITHUB_TOKEN}" ]]; then
echo "GitHub token not found, exiting now..."
exit 1
else
GH_TOKEN="${DEVFILE_DOCS_GITHUB_TOKEN}"
fi


DEFAULT_COMMIT_MESSAGE="Update devfile docs"
DEFAULT_BUILD_DOCKER=false
DEFAULT_DEPLOY=true

build_with_docker() {
echo "Building docs using docker."
check_packages docker tar git
DOCKER_IMAGE_NAME="eclipse-che-devfile-docs"
docker build -t ${DOCKER_IMAGE_NAME} .
mkdir -p ${TMP_DIR}/docs && cd ${TMP_DIR}
docker run --rm ${DOCKER_IMAGE_NAME} | tar -C docs/ -xf -
echo "Building docs done."
}


build_native() {
echo "Building docs using native way."
check_packages git npm
mkdir -p ${TMP_DIR}/schema
cp -f schema/* ${TMP_DIR}/schema
cd ${TMP_DIR}
git clone -b '1.1.0' --single-branch [email protected]:adobe/jsonschema2md.git
cd jsonschema2md
npm install
npm link
cd ..
jsonschema2md -d schema -o docs -n -e json
mv ./docs/devfile.md ./docs/index.md
echo "Building docs done."
}

deploy() {
rm -rf devfile && git clone https://${GH_TOKEN}@github.com/redhat-developer/devfile.git
cp -f docs/* ./devfile/docs
cd devfile
if [[ `git status --porcelain` ]]; then
git commit -am "${COMMIT_MESSAGE}"
git push
else
echo "No changes in docs."
fi
}

check_packages() {
for var in "$@"
do
if rpm -q $var >> /dev/null
then
echo "Package $var is installed, continue..."
else
echo "Required package $var is NOT installed. Exiting now."
exit 1
fi
done
}

cleanup() {
rm -rf ${TMP_DIR}
}

print_help() {
echo "This script builds and deploys documentation in markdown format from devfile json schema."
echo "Command line options:"
echo "--docker Build docs in docker container"
echo "--no-deploy Skip deploy result to remote"
echo "--message Override default commit message"
}

parse_args() {
for i in "${@}"
do
case $i in
--docker)
IS_DOCKER=true
shift
;;
--no-deploy)
mshaposhnik marked this conversation as resolved.
Show resolved Hide resolved
IS_DEPLOY=false
shift
;;
--message)
MESSAGE="${i#*=}"
shift
;;
-help|--help)
print_help
exit 0
;;
esac
done
}

cleanup
parse_args "$@"

COMMIT_MESSAGE=${MESSAGE:-${DEFAULT_COMMIT_MESSAGE}}
IS_DOCKER=${IS_DOCKER:-${DEFAULT_BUILD_DOCKER}}
IS_DEPLOY=${IS_DEPLOY:-${DEFAULT_DEPLOY}}

if [[ "$IS_DOCKER" == "true" ]];
then
build_with_docker
else
build_native
fi
if [[ "$IS_DEPLOY" == "true" ]]; then
deploy
fi
cleanup
exit 0