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 2019/11/04 14:31:38 UTC

[airflow-site] branch aip-11 updated: Use docker exec directly (#110)

This is an automated email from the ASF dual-hosted git repository.

kamilbregula pushed a commit to branch aip-11
in repository https://gitbox.apache.org/repos/asf/airflow-site.git


The following commit(s) were added to refs/heads/aip-11 by this push:
     new f7e8e95  Use docker exec directly (#110)
f7e8e95 is described below

commit f7e8e95808ddb36963afa5d1bdabf430b8983760
Author: Kamil BreguĊ‚a <mi...@users.noreply.github.com>
AuthorDate: Mon Nov 4 15:31:30 2019 +0100

    Use docker exec directly (#110)
---
 site.sh | 85 ++++++++++++++++++++++++++++++++++-------------------------------
 1 file changed, 44 insertions(+), 41 deletions(-)

diff --git a/site.sh b/site.sh
index c4f4a4d..ae5a4b3 100755
--- a/site.sh
+++ b/site.sh
@@ -84,8 +84,8 @@ function ensure_container_running {
 function ensure_node_module_exists {
     if [[ ! -d landing-pages/node_modules/ ]] ; then
         echo "Missing node dependencies. Start installation."
-        start_container_non_interactive bash -c "cd landing-pages/ && yarn install"
-        echo "Dependencies installed"
+        docker exec -w "/opt/site/landing-pages/" "${CONTAINER_NAME}" yarn install
+        echo "Dependencies installed."
     fi
 }
 
@@ -95,49 +95,52 @@ function build_image {
     echo "End building image"
 }
 
+if [[ "$#" -eq 0 ]]; then
+    echo "You must provide at least one command."
+    echo
+    usage
+    exit 1
+fi
 
-function start_container {
-    ensure_image_exists
-    ensure_container_exists
-    ensure_container_running
-    docker exec -ti "${CONTAINER_NAME}" "$@"
-}
+CMD=$1
 
-function start_container_non_interactive {
-    ensure_image_exists
-    ensure_container_exists
-    ensure_container_running
-    docker exec "${CONTAINER_NAME}" "$@"
-}
+shift
 
-if [[ "$#" -ge 1 ]] ; then
-    if [[ "$1" == "build-image" ]] ; then
-        build_image
-    elif [[ "$1" == "stop" ]] ; then
-        docker kill "${CONTAINER_NAME}"
-    elif [[ "$1" == "install-node-deps" ]] ; then
-        start_container bash -c "cd landing-pages/ && yarn install"
-    elif [[ "$1" == "preview" ]]; then
-        ensure_node_module_exists
-        start_container bash -c "cd landing-pages/site && npm run preview"
-    elif [[ "$1" == "build-site" ]]; then
-        ensure_node_module_exists
-        start_container bash -c "cd landing-pages/site && npm run build"
-    elif [[ "$1" == "lint-js" ]]; then
-        ensure_node_module_exists
-        start_container_non_interactive bash -c "cd landing-pages/site && npm run lint:js"
-    elif [[ "$1" == "lint-css" ]]; then
-        ensure_node_module_exists
-        start_container_non_interactive bash -c "cd landing-pages/site && npm run lint:css"
-    elif [[ "$1" == "shell" ]]; then
-        start_container "bash"
-    elif [[ "$1" == "help" ]]; then
-        usage
-    else
-        start_container "$@"
-    fi
-else
+# Check fundamentals commands
+if [[ "${CMD}" == "build-image" ]] ; then
+    build_image
+    exit 0
+elif [[ "${CMD}" == "stop" ]] ; then
+    docker kill "${CONTAINER_NAME}"
+    exit 0
+elif [[ "${CMD}" == "help" ]]; then
     usage
+    exit 0
+fi
+
+ensure_image_exists
+ensure_container_exists
+ensure_container_running
+
+# Check container commands
+if [[ "${CMD}" == "install-node-deps" ]] ; then
+    docker exec -w "/opt/site/landing-pages/" "${CONTAINER_NAME}" yarn install
+elif [[ "${CMD}" == "preview" ]]; then
+    ensure_node_module_exists
+    docker exec -w "/opt/site/landing-pages/" "${CONTAINER_NAME}" npm run preview
+elif [[ "${CMD}" == "build-site" ]]; then
+    ensure_node_module_exists
+    docker exec -w "/opt/site/landing-pages/" "${CONTAINER_NAME}" npm run build
+elif [[ "${CMD}" == "lint-js" ]]; then
+    ensure_node_module_exists
+    docker exec -w "/opt/site/landing-pages/" "${CONTAINER_NAME}" npm run lint:js
+elif [[ "${CMD}" == "lint-css" ]]; then
+    ensure_node_module_exists
+    docker exec -w "/opt/site/landing-pages/" "${CONTAINER_NAME}" npm run lint:css
+elif [[ "${CMD}" == "shell" ]]; then
+    docker exec -ti "${CONTAINER_NAME}" bash
+else
+    docker exec -ti "${CONTAINER_NAME}" "${CMD}" "$@"
 fi
 
 popd &>/dev/null || exit 1