You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by ka...@apache.org on 2020/12/03 13:14:00 UTC
[airflow-site] branch master updated: User-friendly output for
site.sh + Bug fixes for the build process(#325)
This is an automated email from the ASF dual-hosted git repository.
kamilbregula pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airflow-site.git
The following commit(s) were added to refs/heads/master by this push:
new 74672f1 User-friendly output for site.sh + Bug fixes for the build process(#325)
74672f1 is described below
commit 74672f193c56e0dc8f81c2c9167d3962d36eb8f9
Author: Kamil BreguĊa <mi...@users.noreply.github.com>
AuthorDate: Thu Dec 3 14:09:54 2020 +0100
User-friendly output for site.sh + Bug fixes for the build process(#325)
* User-friendly output for site.sh (#319)
* Copy docs for staable version to /docs/stable/ (#321)
* Add sanity checks
---
site.sh | 94 +++++++++++++++++++++++++++++++++++++++++++++++------------------
1 file changed, 69 insertions(+), 25 deletions(-)
diff --git a/site.sh b/site.sh
index aa26e88..9e8e11d 100755
--- a/site.sh
+++ b/site.sh
@@ -16,7 +16,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
-set -euox pipefail
+set -euo pipefail
WORKING_DIR="$(pwd)"
MY_DIR="$(cd "$(dirname "$0")" && pwd)"
@@ -25,6 +25,10 @@ pushd "${MY_DIR}" &>/dev/null || exit 1
IMAGE_NAME=airflow-site
CONTAINER_NAME=airflow-site-c
+function log {
+ echo -e "$(date +'%Y-%m-%d %H:%M:%S'):INFO: ${*} " >&2;
+}
+
function usage {
cat << EOF
usage: ${0} <command> [<args>]
@@ -62,15 +66,17 @@ EOF
}
function ensure_image_exists {
+ log "Checking if image exists: ${IMAGE_NAME}"
if [[ ! $(docker images "${IMAGE_NAME}" -q) ]]; then
- echo "Image not exists."
+ log "Image not exists."
build_image
fi
}
function ensure_container_exists {
+ log "Checking if container exists: ${CONTAINER_NAME}"
if [[ ! $(docker container ls -a --filter="Name=${CONTAINER_NAME}" -q ) ]]; then
- echo "Container not exists"
+ log "Container not exists"
docker run \
--detach \
--name "${CONTAINER_NAME}" \
@@ -83,37 +89,41 @@ function ensure_container_exists {
}
function ensure_container_running {
+ log "Checking if container running: ${CONTAINER_NAME}"
container_status="$(docker inspect "${CONTAINER_NAME}" --format '{{.State.Status}}')"
- echo "Current container status: ${container_status}"
+ log "Current container status: ${container_status}"
if [[ ! "${container_status}" == "running" ]]; then
- echo "Container not running. Starting the container."
+ log "Container not running. Starting the container."
docker start "${CONTAINER_NAME}"
fi
}
function ensure_node_module_exists {
+ log "Checking if node module exists"
if [[ ! -d landing-pages/node_modules/ ]] ; then
- echo "Missing node dependencies. Start installation."
+ log "Missing node dependencies. Start installation."
run_command "/opt/site/landing-pages/" yarn install
- echo "Dependencies installed."
+ log "Dependencies installed."
fi
}
function ensure_that_website_is_build {
+ log "Check if landing-pages/dist/index.html file exists"
if [[ ! -f landing-pages/dist/index.html ]] ; then
- echo "The website is not built. Start building."
+ log "The website is not built. Start building."
run_command "/opt/site/landing-pages/" npm run build
- echo "The website builded."
+ log "The website builded."
fi
}
function build_image {
- echo "Start building image"
+ log "Start building image"
docker build -t airflow-site .
- echo "End building image"
+ log "End building image"
}
function run_command {
+ log "Running command: $*"
working_directory=$1
shift
if [[ -f /.dockerenv ]] ; then
@@ -136,6 +146,7 @@ function run_command {
}
function prepare_environment {
+ log "Preparing environment"
if [[ ! -f /.dockerenv ]] ; then
ensure_image_exists
ensure_container_exists
@@ -202,59 +213,92 @@ function run_lint {
}
function prepare_docs_index {
+ log "Preparing docs index"
run_command "/opt/site/docs-archive/" ./show_docs_index_json.sh > landing-pages/site/static/_gen/docs-index.json
}
function build_landing_pages {
+ log "Building landing pages"
run_command "/opt/site/landing-pages/" npm run index
prepare_docs_index
run_command "/opt/site/landing-pages/" npm run build
}
+function create_index {
+ output_path="$1/index.html"
+ log "Creating index: ${output_path}"
+
+ cat > "${output_path}" << EOF
+<!DOCTYPE html>
+<html>
+ <head><meta http-equiv="refresh" content="1; url=stable/" /></head>
+ <body></body>
+</html>
+EOF
+}
+
+function verbose_copy {
+ source="$1"
+ target="$2"
+ log "Copying '$source' to '$target'"
+ mkdir -p "${target}"
+ cp -R "$source" "$target"
+}
+
+function assert_file_exists {
+ file_path="$1"
+ if [[ ! -f "${file_path}" ]]; then
+ echo "Missing file: ${file_path}":
+ exit 1
+ fi
+}
+
function build_site {
+ log "Building full site"
+
if [[ ! -f "landing-pages/dist/index.html" ]]; then
build_landing_pages
fi
mkdir -p dist
rm -rf dist/*
- cp -R landing-pages/dist/. dist/
+ verbose_copy landing-pages/dist/. dist/
mkdir -p dist/docs/
rm -rf dist/docs/*
for doc_path in docs-archive/*/ ; do
version="$(basename -- "${doc_path}")"
- cp -R "${doc_path}" "dist/docs/${version}/"
+ verbose_copy "docs-archive/${version}/." "dist/docs/${version}"
done
- cp -R "docs-archive/$(cat docs-archive/stable.txt)" "dist/docs/stable/"
- cat > dist/docs/index.html << EOF
-<!DOCTYPE html>
-<html>
- <head><meta http-equiv="refresh" content="1; url=stable/" /></head>
- <body></body>
-</html>
-EOF
+ verbose_copy "docs-archive/$(cat docs-archive/stable.txt)/." "dist/docs/stable"
+ create_index dist/docs
+
+ # Sanity checks
+ assert_file_exists dist/docs/1.10.7/tutorial.html
+ assert_file_exists dist/docs/stable/tutorial.html
+ assert_file_exists dist/docs/index.html
}
function cleanup_environment {
container_status="$(docker inspect "${CONTAINER_NAME}" --format '{{.State.Status}}')"
- echo "Current container status: ${container_status}"
+ log "Current container status: ${container_status}"
if [[ "${container_status}" == "running" ]]; then
- echo "Container running. Killing the container."
+ log "Container running. Killing the container."
docker kill "${CONTAINER_NAME}"
fi
if [[ $(docker container ls -a --filter="Name=${CONTAINER_NAME}" -q ) ]]; then
- echo "Container exists. Removing the container."
+ log "Container exists. Removing the container."
docker rm "${CONTAINER_NAME}"
fi
if [[ $(docker images "${IMAGE_NAME}" -q) ]]; then
- echo "Images exists. Deleeting the image."
+ log "Images exists. Deleting the image."
docker rmi "${IMAGE_NAME}"
fi
}
function prepare_theme {
+ log "Preparing theme files"
SITE_DIST="landing-pages/dist"
THEME_GEN="sphinx_airflow_theme/sphinx_airflow_theme/static/_gen"
mkdir -p "${THEME_GEN}/css" "${THEME_GEN}/js"